[英]"message": "Failed to convert from type [java.lang.String] to type [java.lang.Long] for value 'count'; For input string: \"count\""
I need count users in mysql using spring boot to display a statistic我需要使用 spring boot 统计 mysql 中的用户数以显示统计信息
my code content 3 class and interface :我的代码内容 3 类和接口:
////////////////interface////////////////////
public interface UserRepository extends JpaRepository<User, Long>
String count(String name);
////////////////service////////////////////
public String count(String username);
@Override
public String count(String username) {
return userRepository.count(username);
}
//////////////////iontroller////////////
@GetMapping("/count")
public String count(String username) {
return userService.count(username);
}
result in postman:结果邮递员:
"message": "Failed to convert from type [java.lang.String] to type [java.lang.Long] for value 'count'; nested exception is java.lang.NumberFormatException: For input string: \"count\""
In the repository you need to use countBy
clause with searching field name and return long as return type.在存储库中,您需要使用countBy
子句搜索字段名称并返回 long 作为返回类型。 Assuming in User
entity username
is a field.假设User
实体中的username
是一个字段。
long countByUsername(String username);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.