java - Spring Data JPA:findAllByOrderBy 不排序
问题描述
在我的 SpringBoot 服务中,我想从我的 mysql 数据库中获取所有“人”实体,主要按值“月”排序,其次按值“日”排序。
返回一个包含所有实体的列表,但它们的顺序是它们被添加到数据库中的顺序,独立于属性“月”和“日”。
我究竟做错了什么?
存储库:
public interface PersonRepository extends JpaRepository<Person, UUID> {
public List<Person> findAllByOrderByMonthAscDayAsc();
}
实体:
@Entity
@Table
public class Person {
@Id
@GeneratedValue(generator = "uuid2")
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(columnDefinition = "BINARY(16)")
@JsonIgnore
private UUID id;
@Column
@NotNull
@JsonProperty(access = Access.WRITE_ONLY)
private Integer month;
@Column
@NotNull
@JsonProperty(access = Access.WRITE_ONLY)
private Integer day;
public Person(){
}
public Integer getMonth() {
return month;
}
public void setMonth(Integer month) {
this.month = month;
}
public Integer getDay() {
return day;
}
public void setDay(Integer day) {
this.day = day;
}
}
服务:
@Service
public class BdayService {
@Autowired
private PersonRepository personRepository;
public BdayService(){
}
@Transactional
public List<Person> findAllSorted(){
List<Person> persons = personRepository.findAllByOrderByMonthAscDayAsc();
return persons;
}
}
解决方案
推荐阅读
- php - Symfony 3.4 - 服务“Symfony\Component\Ldap\Ldap”依赖于不存在的服务“Symfony\Component\Ldap\Adapter\ExtLdap\Adapter”
- r - 使用 data.table 从起点和增量创建序列
- c# - ASP.Net Webmethod:如何用继承类反序列化参数?
- javascript - Postman - 仅从 URL 获取端点
- c++ - CMake:在项目范围内传播编译选项
- parallel-processing - CUDA 中的块间同步
- json - 如何使用 MS Unit 模拟 WebAPI 的 PATCH 方法?
- javascript - webpack动态导入方法reactjs中返回的是空数组而不是文件,如何解决?
- php - $this 对象在加载的模板中,带有角度
- java - 错误 osweb.context.ContextLoader - 上下文初始化失败