我想在存储库层中编写一些查询方法.此方法必须忽略null参数.例如:
List<Foo> findByBarAndGoo(Bar barParam, @optional Goo gooParam);
Run Code Online (Sandbox Code Playgroud)
此方法必须通过以下条件返回Foo:
bar == barParam && goo == gooParam;
Run Code Online (Sandbox Code Playgroud)
如果gooParam不为null.如果gooParam为null,则条件更改为:
bar == barParam;
Run Code Online (Sandbox Code Playgroud)
有什么解决方案吗?有人能帮我吗?
我希望通过gradle将querydsl带入我的spring-boot项目.尽管在网上找到了几个例子,但由于依赖性问题(我认为),它们实际上都不适合我.根据QueryDSL支持论坛,尚不支持gradle.但是我想知道如果有人设法让它工作了所有的gradle和spring-boot?
这是我的build.gradle:
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'jacoco'
apply plugin: 'war'
buildscript {
repositories {
maven { url "http://repo.spring.io/libs-snapshot" }
mavenLocal()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.0.0.RC4")
}
}
repositories {
mavenCentral()
maven { url: "http://repo.spring.io/libs-snapshot" }
// maven { url: "http://repo.spring.io/milestone" }
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web:1.0.0.RC5")
compile("org.springframework.boot:spring-boot-starter-data-jpa:1.0.0.RC5")
compile("org.springframework:spring-orm:4.0.0.RC1")
compile("org.hibernate:hibernate-entitymanager:4.2.1.Final")
compile("com.h2database:h2:1.3.172")
compile("joda-time:joda-time:2.3")
compile("org.thymeleaf:thymeleaf-spring4")
compile("org.codehaus.groovy.modules.http-builder:http-builder:0.7.1")
compile('org.codehaus.groovy:groovy-all:2.2.1')
compile('org.jadira.usertype:usertype.jodatime:2.0.1')
// this line fails
querydslapt "com.mysema.querydsl:querydsl-apt:3.3.2"
testCompile('org.spockframework:spock-core:0.7-groovy-2.0') {
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
}
testCompile('org.codehaus.groovy.modules.http-builder:http-builder:0.7+')
testCompile("junit:junit")
} …Run Code Online (Sandbox Code Playgroud) 我在当前项目中使用Spring Data和Neo4j并处于以下情况:
@RestController
@RequestMapping(value = SearchResource.URI)
public class PersonResource {
public static final String URI = "/person";
@Autowired
PersonRepository personRepository;
@GetMapping
public Collection<Person> findPersons(
@RequestParam(value = "name", required = false) String name,
@RequestParam(value = "birthDate", required = false) Long birthDate,
@RequestParam(value = "town", required = false) Spring town) {
Collection<Person> persons;
if (name != null && birthDate == null && town == null) {
persons = personRepository.findPersonByName(name);
} else if (name != null && birthDate != null && town == …Run Code Online (Sandbox Code Playgroud) 如何使用Spring Data轻松实现一种“REST API 查询语言”来过滤实体?
例如,对于以下Person实体:
@Data
@Entity
public class Person {
@Id
@GeneratedValue
private Long id;
private LocalDate dob; // date of birth
private String name;
@Formula("timestampdiff('year', dob, now())")
private Integer age;
public Person(String name, LocalDate dob) {
this.name = name;
this.dob = dob;
}
}
Run Code Online (Sandbox Code Playgroud)
我想通过这样的请求获取其数据:
GET /people?name=jo&age=18&page=1&sort=name,desc
Run Code Online (Sandbox Code Playgroud)
即:'获取所有name包含“jo”(不区分大小写)且age等于 18 的人的第一页,按name降序排序'。
我需要使用Spring Boot REST和Spring Data JPA使用 Criteria API 来实现复杂的搜索功能。我需要提供如下所示的 RPI
,/college?select=*&where=name:DemoCollege并输入[1,2,3]location:LAstaff{firstName:foo, lastName:boo, workExp>10}
Collage 对象有name、location、type字段和staff列表。它有onetomany关系,Staff所以College可以有一名或多名工作人员。
基于 uri,我需要使用 criteria api 构建查询。
我发现实现该toPredicate()方法非常复杂org.springframework.data.jpa.domain.Specification。有没有这样的例子来处理如此复杂的搜索过滤器?
提前致谢。
spring ×3
spring-boot ×3
spring-data ×3
querydsl ×2
criteria-api ×1
cypher ×1
gradle ×1
hibernate ×1
jpql ×1
rest ×1
spring-rest ×1