GithubHelp home page GithubHelp logo

ekisstherain / jpa-querydsl-spring-boot-starter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mioxs/jpa-querydsl-spring-boot-starter

0.0 1.0 0.0 93 KB

License: Apache License 2.0

Java 100.00%

jpa-querydsl-spring-boot-starter's Introduction

jpa-querydsl-spring-boot-starter

English | δΈ­ζ–‡

  • Jpa Quick Design
  • Support spring boot 2.1.x and above (including 2.1.x)

Introduction

  • Jpa Service CRUD package, support querydsl out of the box.

use

  1. Add dependency
       <dependency>
           <groupId>com.github.uinio</groupId>
           <artifactId>jpa-querydsl-spring-boot-starter</artifactId>
           <version>2.5.1</version>
       </dependency>

  1. examples
  • Entity class
@Table
@Entity
public class Contact implements Serializable {

    @Id
    private Integer id;

    private Name name;

    private String notes;

    //getter setter ...   
}

Repository

public interface ContactRepository extends JpaRepository<Contact, Integer> {

}

service

  • Provide single table CURD operation.
  • Note: The provided JpaService only supports single table operations, and complex operations use EntityManager or QueryDsl
public interface ContactService extends JpaService<Contact, Integer> {
}

@Service
public class ContactServiceImpl extends JpaServiceImpl<Contact, Integer> implements UserService {

}

Test

@SpringBootTest
class MainApplicationTests {

    @Autowired
    private ContactService contactService;

    @Test
    void contextLoads() {
        //Insert
        Contact contact = new Contact();
        contact.setName("test");
        contact.setNotes("test");
        contactService.save(contact);

        //Update
        Contact contact = new Contact();
        contact.setId(1);
        contact.setName("example");
        contact.setNotes("example");
        contactService.update(contact);

        //Delete
        contactService.deleteById(1);

        //BatchDeletion
        contactService.deleteByIds(new Integer[]{1, 2});

        //Pagination
        contactService.page(1, 2);

        //...
    }
}

querydsl out of the box

  • configuration
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>com.mysema.maven</groupId>
            <artifactId>apt-maven-plugin</artifactId>
            <version>1.1.3</version>
            <executions>
                <execution>
                    <goals>
                        <goal>process</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>target/generated-sources/java</outputDirectory>
                        <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>com.querydsl</groupId>
                    <artifactId>querydsl-apt</artifactId>
                    <version>${querydsl.version}</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>
  • mvn compile generate query class
@SpringBootTest
class MainApplicationTests {

    @Autowired
    private JPAQueryFactory jpaQueryFactory;

    @Test
    void contextLoads() {
        QContact contact = QContact.contact;
        jpaQueryFactory.update(contact).set(contact.name, "test")
                .where(contact.id.eq(1)).execute();
    }

}

jpa-querydsl-spring-boot-starter's People

Contributors

mioxs avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.