解决问题:数据库表里面很多字段不太需要,有时只想取到里面的部分字段的值,如果重新定义 DTO 会比较麻烦。 BookMapper.xml 文件中定义如下: ` <!-- Book全部字段 -->
<resultMap >
<id column="bookid" 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 column="book_id" property="bookId" jdbcType="BIGINT" />
<result column="book_name" property="bookName" jdbcType="VARCHAR" />
<result column="author" property="author" jdbcType="VARCHAR" />
</resultMap>
<!-- 查询语句 -->
<select >
select book_id, book_name, author from book
</select>
BookMapper.java 文件中定义如下:
List<Map<String, Object>> selectPartBook();
1 BookService.java 用 List< Map< String, Object > > 来接收
List<Map<String, Object>> map = bookMapper.selectPartBook();
下面博客使用的方法需要传入id值,所以不适用。 MyBatis使用@MapKey注解接收多个查询记录到Map中,以便方便地用get()方法获取字段的值

相关文章:

  • 2022-12-23
  • 2021-05-13
  • 2021-06-27
  • 2022-12-23
  • 2021-10-16
  • 2021-05-16
  • 2022-12-23
猜你喜欢
  • 2021-11-28
  • 2023-03-10
  • 2021-10-17
  • 2022-12-23
  • 2021-07-18
  • 2021-06-06
相关资源
相似解决方案