mybatis注解开发实体类属性和数据库字段不对应问题

/**
     * 查询所有用户
     * @return
     */
    @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();
为了解决重复使用,那就要让他变成一个有id的整体,其他地方要用就直接调用 
@ResultMap(“id”) 
@Result中通过id属性引用这个resultMap

/** * 根据id查询用户 * @param userId * @return */ @Select("select * from user where id=#{id} ") @ResultMap("userMap") User findById(Integer userId);

  

你可能感兴趣的:(mybatis注解开发实体类属性和数据库字段不对应问题)