你好实际的错误是:
Exception in thread "main" org.springframework.core.convert.ConversionFailedException:
Failed to convert from type [java.lang.Object[]] to type [boolean] for value '{2, ramesh, pass, 12345, ramu}';
nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.Integer] to type [boolean]
这里我尝试创建一个方法来通过id查找用户,但是当我尝试将值放入boolean类型时,它给出了上述错误
@Query("select case when count(s)>0 then true else false end from user_dao s where s.id =:id ")
@Query(value = "select * from user_dao where id =:id ", nativeQuery = true)
boolean isStudentExistsById(@Param("id") Integer id);
在main
方法-〉中,这应该输出true或false。
System.out.println(userRepo.isStudentExistsById(2));
在Bean的构造器中
UserDao(int id, String name, String phone, String user_name, String
password) {
this.id = id;
this.name = name;
this.phone = phone;
this.user_name = user_name;
this.password = password;
}
1条答案
按热度按时间rn0zuynd1#
最简单的方法--使用
CrudRepository
的方法(你的仓库通常继承了它):boolean existsById(Integer id)
个有关其他选项,请参见Spring Data JPA and Exists query