JPA将我的排序属性拆分为" _"默认,所以它抛出没有找到属性的异常。 如果我从变量中删除下划线,它可以正常工作。
但我只想保持" _"在我的实体属性中,我该怎么办?
变量:
@Column(name = "CREATE_TIME")
private LocalDateTime create_Time;
可分页:
Pageable pageable = new PageRequest(page, 10, Sort.Direction.DESC,"create_Time");
例外:
org.springframework.data.mapping.PropertyReferenceException: No property create found for type Rtm_App!
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:77)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:329)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:309)
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:272)
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:243)
at org.springframework.data.jpa.repository.query.QueryUtils.toJpaOrder(QueryUtils.java:546)
at org.springframework.data.jpa.repository.query.QueryUtils.toOrders(QueryUtils.java:500)
at org.springframework.data.jpa.repository.support.SimpleJpaRepository.getQuery(SimpleJpaRepository.java:653)
at org.springframework.data.jpa.repository.support.SimpleJpaRepository.getQuery(SimpleJpaRepository.java:608)
at org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:407)
at org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:377)
拆分财产的地方
public class PropertyPath implements Iterable<PropertyPath> {
private static final String DELIMITERS = "_\\.";
private static final String ALL_UPPERCASE = "[A-Z0-9._$]+";
private static final Pattern SPLITTER = Pattern.compile("(?:[%s]?([%s]*?[^%s]+))".replaceAll("%s", DELIMITERS));
public static PropertyPath from(String source, TypeInformation<?> type) {
List<String> iteratorSource = new ArrayList<String>();
Matcher matcher = SPLITTER.matcher("_" + source);
while (matcher.find()) {
iteratorSource.add(matcher.group(1));
}
Iterator<String> parts = iteratorSource.iterator();
PropertyPath result = null;
Stack<PropertyPath> current = new Stack<PropertyPath>();
while (parts.hasNext()) {
if (result == null) {
result = create(parts.next(), type, current);
current.push(result);
} else {
current.push(create(parts.next(), current));
}
}
return result;
}