在MyBatis中,Result注解用于映射查詢結果集中的列到Java對象的屬性。Result注解有如下屬性:
配置示例:
@Results({
@Result(property = "id", column = "user_id", jdbcType = JdbcType.INTEGER),
@Result(property = "username", column = "user_name", jdbcType = JdbcType.VARCHAR),
@Result(property = "email", column = "user_email", jdbcType = JdbcType.VARCHAR),
@Result(property = "roles", column = "user_id",
many = @Many(select = "com.example.mapper.RoleMapper.findByUserId"))
})
public User findUserById(Integer userId);