生活随笔
收集整理的這篇文章主要介紹了
[mybatis]select_resultMap_自定义结果集映射规则
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
resultMap
- 自定義某個(gè)javaBean的封裝規(guī)則
- type:自定義規(guī)則的Java類型
- id:唯一id方便引用
- 指定主鍵列的封裝規(guī)則
- id:定義主鍵底層會(huì)有優(yōu)化
- column:指定哪一列
- property:指定對(duì)應(yīng)的javaBean屬性
public interface EmployeeMapperPlus {public Employee getEmpById(Integer id
);}
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.atguigu.mybatis.dao.EmployeeMapperPlus"><resultMap id="MyEmp" type="com.atguigu.mybatis.bean.Employee"><id column="id" property="id"></id><result column="last_name" property="lastName"></result><result column="email" property="email"></result><result column="gender" property="gender"></result></resultMap><select id = "getEmpById" resultMap="MyEmp">select * from tb1_employee where id = #{id}
</select></mapper>
@Testpublic void test03() throws IOException {SqlSessionFactory sqlSessionFactory
= getSqlSessionFactory();SqlSession sqlSession
= sqlSessionFactory
.openSession();try{EmployeeMapperPlus mapper
= sqlSession
.getMapper(EmployeeMapperPlus.class);Employee map
= mapper
.getEmpById(1);System.out
.println(map
);}finally {sqlSession
.close();}}
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)
總結(jié)
以上是生活随笔為你收集整理的[mybatis]select_resultMap_自定义结果集映射规则的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。