Spring Data CRUD findByOrderBy 数字排序不正确。将 10 排序为 1
当我使用 CRUD 存储库并使用 findTop10ByOrderBy 方法时,它不会正确对整数进行排序。
谢谢
结果
Top Ten Songs
9 - 9 - 9
8 - 8 - 8
7 - 7 - 7
6 - 6 - 6
5 - 5 - 5
4 - 4 - 4
3 - 3 - 3
2 - 2 - 2
10 - 10 - 10
1 - 1 - 1
存储库
public interface LookRepository extends CrudRepository<Look, Long>{
List<Look> findAll();
List<Look> findByArtistContaining(String artist);
List<Look> findTop10ByOrderByRatingDesc();
}
服务
public List<Look> searchTopTen() {
return lookRepository.findTop10ByOrderByRatingDesc();
}
控制器
@RequestMapping("/TopTen")
public String TopTen(Model model) {
List<Look> looks = lookService.searchTopTen();
model.addAttribute("looks", looks);
return "topten.jsp";
}
When I am using the CRUD Repository and using the findTop10ByOrderBy method, it will not sort the integers correctly.
Thank you
Result
Top Ten Songs
9 - 9 - 9
8 - 8 - 8
7 - 7 - 7
6 - 6 - 6
5 - 5 - 5
4 - 4 - 4
3 - 3 - 3
2 - 2 - 2
10 - 10 - 10
1 - 1 - 1
Repository
public interface LookRepository extends CrudRepository<Look, Long>{
List<Look> findAll();
List<Look> findByArtistContaining(String artist);
List<Look> findTop10ByOrderByRatingDesc();
}
Service
public List<Look> searchTopTen() {
return lookRepository.findTop10ByOrderByRatingDesc();
}
Controller
@RequestMapping("/TopTen")
public String TopTen(Model model) {
List<Look> looks = lookService.searchTopTen();
model.addAttribute("looks", looks);
return "topten.jsp";
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论