abel533 / Mapper

Mybatis Common Mapper - Easy to use
https://mybatis.io
MIT License
7.34k stars 1.63k forks source link

最新版selectByPrimaryKey()方法查询失败 #345

Closed fchen521 closed 6 years ago

fchen521 commented 6 years ago

我的是springboot项目,之前用的的版本是1.1.4没有问题,但是换成2.0.3-beta1后发现selectByPrimaryKey()方法不能根据主键查询了。 这是实体

@Data
public class UserInfo {
    @Id
    private int id;
    private String username;
    private String password;
}

接口

@org.apache.ibatis.annotations.Mapper
@Repository
public interface UserMapper extends Mapper<UserInfo> {
}

测试方法

@RunWith(SpringRunner.class)
@SpringBootTest
public class DemoApplicationTests {
    @Autowired
    UserMapper mapper;
    @Test
    public void contextLoads() throws SQLException, IOException {
        mapper.selectByPrimaryKey(2);
    }

}

2.0.3-beta1版本打印信息

2018-06-26 18:24:49.774 DEBUG 14096 --- [           main] c.e.d.m.UserMapper.selectByPrimaryKey    : ==>  Preparing: SELECT username,password FROM userinfo WHERE username = ? AND password = ? 
[2018-06-26 18:24:49 下午]:DEBUG com.alibaba.druid.filter.logging.Log4jFilter.statementLog(Log4jFilter.java:137){conn-10005, pstmt-20000} created. SELECT username,password  FROM userinfo  WHERE  username = ? AND password = ?
2018-06-26 18:24:49.944 DEBUG 14096 --- [           main] c.e.d.m.UserMapper.selectByPrimaryKey    : ==> Parameters: 2(Integer), 2(Integer)
[2018-06-26 18:24:49 下午]:DEBUG com.alibaba.druid.filter.logging.Log4jFilter.statementLog(Log4jFilter.java:137){conn-10005, pstmt-20000} Parameters : [2, 2]
[2018-06-26 18:24:49 下午]:DEBUG com.alibaba.druid.filter.logging.Log4jFilter.statementLog(Log4jFilter.java:137){conn-10005, pstmt-20000} Types : [INTEGER, INTEGER]

下面是1.1.4版本打印信息

2018-06-26 18:29:07.230 DEBUG 6504 --- [           main] c.e.d.m.UserMapper.selectByPrimaryKey    : ==>  Preparing: SELECT id,username,password FROM userinfo WHERE id = ? 
[2018-06-26 18:29:07 下午]:DEBUG com.alibaba.druid.filter.logging.Log4jFilter.statementLog(Log4jFilter.java:137){conn-10005, pstmt-20000} created. SELECT id,username,password  FROM userinfo  WHERE  id = ?

我想问主键是id ,sql 语句不应该是 SELECT username,password FROM userinfo WHERE id=?,现在换个版本,selectByPrimaryKey()方法变成了SELECT username,password FROM userinfo WHERE username = ? AND password = ? 导致查询失败,请问这是什么原因?还是2.0版本后修改了这个方法吗?

abel533 commented 6 years ago

2.x 没改这个方法。你这日志显示确实有问题。

cuivip commented 6 years ago

@cfmygit 为什么不说下关闭原因

abel533 commented 5 years ago

我也想知道原因。