简体   繁体   English

"message": "无法从类型 [java.lang.String] 转换为类型 [java.lang.Long] 以获取值 'count';对于输入字符串:\\"count\\""

[英]"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.

相关问题 无法在 SPRING 中将类型“java.lang.String”的值转换为所需的类型“java.lang.Long” - Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long' in SPRING Spring NumberFormatException:无法将类型&#39;java.lang.String&#39;的值转换为所需的类型&#39;java.lang.Long - Spring NumberFormatException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long 无法将 Spring JPA 从类型 [java.lang.String] 转换为类型 [java.lang.Long]? - Failed to convert from type [java.lang.String] to type [java.lang.Long] for Spring JPA? Spring JPAF无法将值“为什么?”从类型[java.lang.String]转换为类型[java.lang.Long]。 - Spring JPAFailed to convert from type [java.lang.String] to type [java.lang.Long] for value 'Why?' 无法将类型“java.lang.String”的值转换为所需类型“java.lang.Long”嵌套异常 java.lang.NumberFormatException 对于输入字符串“null” - Failed convert value of type 'java.lang.String' to required type 'java.lang.Long' nested excep java.lang.NumberFormatException For input string “null” 如何解决错误:无法将类型&#39;java.lang.String&#39;的值转换为所需的类型&#39;java.lang.Long&#39;; - How do I fix error: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; 提交表单时,无法将“java.lang.String”类型的值转换为所需类型“java.lang.Long”错误 - Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long' error when submitting form 无法将类型“java.lang.String”的值转换为所需的类型“long”; 对于输入字符串:“{id}” - Failed to convert value of type 'java.lang.String' to required type 'long'; For input string: "{id}" 无法将类型“ java.lang.String”的值转换为所需的类型“ long”; 嵌套的异常是java.lang.NumberFormatException:对于输入字符串:“” - Failed to convert value of type 'java.lang.String' to required type 'long'; nested exception is java.lang.NumberFormatException: For input string: “” 当Get请求不是ID时,获取此异常:无法将类型java.lang.String的值转换为所需的类型java.lang.Long - when the Get request is other than Id getting this exception :Failed to convert value of type java.lang.String to required type java.lang.Long
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM