spring - Spring boot - 当我设置“用户名”变量时,JPA 匹配器不起作用
问题描述
我开始学习弹簧靴。我试了很多次都没有解决一个问题。用户类有用户名变量。我想检查用户名是否存在我们的数据库并将异常作为错误消息抛出。
ExampleMatcher matcher = ExampleMatcher.matchingAll()
.withMatcher("username", exact())
.withIgnorePaths("id");
Example<Users> example = Example.of(users, matcher);
List<Users> find = usersRepository.findAll(example);
System.out.println("Find users: "+find.size());
我在匹配器上设置了用户名变量。当我运行 api 并显示日志时。你可以在下面看到:
User payload: Users{id=0, firstName='Homer', lastName='Simpsons', username='bart.skate', email='homer.sleeper@gmail.com', password='@bcd1234'}
Find users: 0
User payload: Users{id=0, firstName='Homer', lastName='Simpsons', username='bart.skate', email='homer.simpsons@gmail.com', password='@bcd1234'}
Find users: 0
第一个用户已创建。所以我尝试再次创建新用户相同的用户名。没有找到用户名。
我希望有人帮助为我解释。谢谢!
解决方案
推荐阅读
- android - 如何修复 No Agent definition found for id Watson Assistant 错误?
- database - 限制相对于另一列条目的重复条目
- java - 限制对共享资源的访问的设计模式
- c++ - 如何使用opencv在不丢失像素的情况下对图像进行去失真
- c# - 通过 .Net 和 SqlBulkCopy 从 Oracle 到 SQL Server 以极高的精度传输浮点数
- javascript - 功能组件和组件类的区别?
- ubuntu - Hadoop 在启动时使用了错误的用户名?
- python - 在多个按钮上显示图像 - kivy
- java - 仅在调用另一个方法时如何锁定方法
- woocommerce - 如何删除供应商:从 Dokan 客户订单电子邮件