mybatis注解建立实体类属性和数据库字段列表的对应关系

/**
 * 查询所有用户
 * @return
 * id="userMap"  给results命名
 */
@Select("select * from user")
@Results(id="userMap"  value = {
        @Result(id = true, column = "id", property = "userId"),
        @Result(column = "username", property = "userName"),
        @Result(column = "address", property = "userAddress"),
        @Result(column = "sex", property = "userSex"),
        @Result(column = "birthday", property = "userBirthday"),
})
List findAll();

其他方法要使用userMap的方法

  /**
     * 保存用户
     * @param user
     */
    @Insert("insert into user(username,address,sex,birthday)values(#{username},#{address},#{sex},#{birthday})")
    @ResultMap("userMap")
    void saveUser(User user);

你可能感兴趣的:(mybatis框架)