Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mivui/jpa-querydsl-spring-boot-starter


https://github.com/mivui/jpa-querydsl-spring-boot-starter

jpa querydsl spring-boot spring-data-jpa

Last synced: 3 months ago
JSON representation

Awesome Lists containing this project

README

        

# jpa-querydsl-spring-boot-starter

English | [中文](./ZH_CN.md)

* 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
```xml

com.github.uinio
jpa-querydsl-spring-boot-starter
2.5.1

```

----------

2. examples

* Entity class

```java

@Table
@Entity
public class Contact implements Serializable {

@Id
private Integer id;

private Name name;

private String notes;

//getter setter ...
}
```

---------
> Repository

```java
public interface ContactRepository extends JpaRepository {

}
```

--------
> service

* Provide single table CURD operation.
* Note: The provided JpaService only supports single table operations, and complex operations use EntityManager or
QueryDsl

```java
public interface ContactService extends JpaService {
}
```

--------

```java

@Service
public class ContactServiceImpl extends JpaServiceImpl implements UserService {

}
```

-------
> Test

```java

@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

```xml



org.springframework.boot
spring-boot-maven-plugin


com.mysema.maven
apt-maven-plugin
1.1.3



process


target/generated-sources/java
com.querydsl.apt.jpa.JPAAnnotationProcessor





com.querydsl
querydsl-apt
${querydsl.version}



```

* mvn compile generate query class

```java

@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();
}

}
```