mybatis使用注解开发
@Select 就是mapper里面的<select></select>
@Results 相当于<resultMap></resultMap>
@Result 相当于resultMap的字标签result 同时它的属性id是一个Boolean类型的值,如果为true,那么这个字段就是表的id,如果为false,那就是普通字段
@Select("select * from userinfo")
@Results(id = "userMap",value = {
@Result(id = true,property = "userId",column = "userId"),
@Result(property = "username",column = "username"),
@Result(property = "realName",column = "realName"),
@Result(property = "sex",column = "sex"),
@Result(property = "age",column = "age"),
@Result(property = "accounts",column = "userId",many = @Many(
select = "com.zh.dao.AccountMapper.findAccountById",
fetchType = FetchType.LAZY
))
})
List<User> findAll();
@Select("select * from userinfo where userId=#{userId}")
User findById(Integer userId);

浙公网安备 33010602011771号