resultMap引用另外一個Mapper文件的resultMap

如今同個包mapper下有兩個文件:userMapper.xml和scanMapper.xmljava

scanMapper.xml文件內容以下:mybatis

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="soc.dao.ScanDao">
	<cache readOnly="true" eviction="FIFO" flushInterval="60000" />
	<resultMap id="BaseResultMap" type="soc.entity.Scan">
		<result column="id" property="id" />
		<result column="name" property="name" />
		<result column="status" property="status" />
	</resultMap>

</mapper>

userMapper.xml文件裏想引用scanMapper.xml的resultMap--BaseResultMap,引用方法以下:app

userMapper.xml:spa

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="soc.dao.UserDao">
	<cache readOnly="true" eviction="FIFO" flushInterval="60000" />
	<resultMap id="BaseResultMap" type="soc.entity.User">
		<result column="id" property="id" />
		<result column="name" property="name" />
		<result column="salary" property="salary" />
		<result column="birthday" property="birthday" />
	</resultMap>
	
	<select id="testOutMapper" resultMap="soc.dao.ScanDao.BaseResultMap">
		select * from scan
	</select>
</mapper>

如上,resultMap="soc.dao.ScanDao.BaseResultMap"即resultMap="另外一個Mapper文件的namespace路徑.id"。code

相關文章
相關標籤/搜索