前提
Java代码中定义的ID名为 userId
MySql中的定义的ID名为 id
这样在查询时,就会出现查不到id的值
方法一 加别名
select id as userid , username, password as userPassword from user
方法二 使用resultMap
@Select("select * from user")
@Results(id = "resultMap" , value = {
@Result(property = "userId",column = "id")
})
其中定义的 id = "resultMap" 使得其他方法可以通过
@ResultMap("resultMap") 这种方式来调用这个属性
比如:
@ResultMap("resultMap")
@Select("select * from user where username like #{name}")