java - "message": "从类型 [java.lang.String] 转换为类型 [java.lang.Long] 的值 'count' 失败;对于输入字符串:\"count\""
问题描述
我需要使用spring boot在mysql中计算用户来显示统计信息
我的代码内容 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);
}
结果是邮递员:
"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\""
解决方案
在存储库中,您需要使用countBy
带有搜索字段名称的子句并返回 long 作为返回类型。假设User
实体username
是一个字段。
long countByUsername(String username);
推荐阅读
- deep-linking - 在 Power Apps 中不使用库的深层链接
- php - Safari 和 Laravel - 邮件验证
- reactjs - 反应中输入字段中只有正整数
- javascript - javascript中create2函数的等价物是什么?
- jquery - 有谁知道如何将 RTL 应用于插件 mmenu.js?
- r - 使用 dplyr 显示某个变量变量的最大和对应的级别
- node.js - 如何在 mvc 核心 Web 应用程序中使用 https 请求访问 nodejs 服务器?
- macos - Apple Script 不再与 Big Sur 一起运行
- artifactory - 神器停止响应
- sftp - Azure 逻辑应用程序 - 我可以在我的动态内容中使用初始化变量作为我的 SFTP 服务器连接的凭据吗?