mybatis查询结果和mysql的查询结果不一样

mybatis查询结果和mysql的查询结果不一样

问题描述:

我只想查询userName和userAge,结果user类的所有属性都跑出来了....![图片说明](https://img-ask.csdn.net/upload/201710/11/1507707452_948210.png)图片说明

 <!-- Book全部字段 -->
<resultMap id="BaseResultMap" type="com.lgsc.cjbd.book.model.Book">
    <id column="book_id" property="bookId" jdbcType="BIGINT" />
    <result column="book_name" property="bookName" jdbcType="VARCHAR" />
    <result column="press" property="press" jdbcType="VARCHAR" />
    <result column="author" property="author" jdbcType="VARCHAR" />
    <result column="translator" property="translator" jdbcType="VARCHAR" />
    <result column="isbn" property="isbn" jdbcType="CHAR" />
</resultMap>

<!-- 定义resultMap,type为HashMap -->
<resultMap id="PartBookMap" type="java.util.HashMap">
    <id column="book_id" property="bookId" jdbcType="BIGINT" />
    <result column="book_name" property="bookName" jdbcType="VARCHAR" />
    <result column="author" property="author" jdbcType="VARCHAR" />
</resultMap>

<!-- 查询语句 -->
<select id="selectPartBook" resultMap="PartBookMap">
    select book_id, book_name, author from book
</select>

如上,将你的字段写到一个map里,然后返回那个map。参考链接:http://blog.csdn.net/u014710520/article/details/73569257

返回值由resultMap确定,BaseMap应该是指定的user的相关属性,将resultMap="map"