4

springboot 中 mapper 查询操作返回指定的字段时,总是报错

 1 year ago
source link: https://www.v2ex.com/t/923256
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  Java

springboot 中 mapper 查询操作返回指定的字段时,总是报错

  shayang888 · 2 小时 17 分钟前 · 207 次点击

这是我的实体类

public record User(Integer id, String email, String password, String nickname, Integer is_active) {
}

这是 mapper 的查询语句

@Select("select email,nickname from user where email = #{email} limit 1")
User findUserByEmail(@Param("email") String email);

现在情况是我如果查询的字段不用*或者写完所有的字段,都会报错

org.springframework.dao.DataIntegrityViolationException: Error attempting to get column 'email' from result set.  Cause: java.sql.SQLDataException: Cannot determine value type from string 'XXX'
; Cannot determine value type from string 'XXX'

我的数据库表结构的字段和里面的值都是正确的,所以不存在数据库的错误

第 1 条附言  ·  1 小时 43 分钟前

@Terminator0826
public record User(Integer id, String email, String password, String nickname, Integer is_active) {
public User(String email, String nickname, Integer is_active) {
this(null, email, null, nickname, is_active);
}
}

我现在添加了个这个构造器,但是返回的结果就是

"data": {
"id": null,
"email": "XXX",
"password": null,
"nickname": "XXX",
"is_active": 0
}

id 和 password 还是查出来了


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK