15Mybatis_输出类型

输出类型分为两种:1.resultType          和         2.resultMap

接下来先讲解resultType:

使用resultType进行输出映射,只有查询出来的列名和pojo中的属性名一致,该列才可以映射成功。

如果查询出来的列名和pojo中的属性名全部不一致,没有创建pojo对象。

只要查询出来的列名和pojo中的属性有一个一致,就会创建pojo对象。

案例:

userMapper.xml文件:

<?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">
<!-- nanmespace:命名空间。 作用就是对sql进行分类话管理,理解Sal分离 注意:使用mapper代理方式,namespace有特殊重要的作用
--> <mapper namespace="cn.itcast.mybatis.mapper.userMapper"> <!--
这里的id要和Mapp接口里面的函数名字一模一样。parameterType表示输入的类型,
resultType表示输出的类型 -->
<select id="findUserList" parameterType="cn.itcast.mybatis.po.UserQueryVo" resultType="cn.itcast.mybatis.po.UserCustom">
SELECT * FROM USER WHERE user.sex= #{userCustom.sex} AND user.username=#{userCustom.username}
</select> </mapper>

这里的resultType是"cn.itcast.mybatis.po.UserCustom"。

就是说 SELECT * FROM .......这里的* 如果改为username_而不是UserCustom中的username的话这个username就会映射失败,它的值就是null。

2.resultMap

Mybatis中使用resultMap完成高级输出结果的映射。其实就是对上面的弊端(只有sql语句中select id ...这些要和user中的属性名一致才能映射正确)的一个改正,用resultMap就可以如果查询出来的列名和pojo的属性名不一致,通过定义一个resultMap对列名和pojo属性名之间作一个映射关系。

思路:

1.定义resultMap

2.使用resultMap作为statment的输出映射类型。

我们要将SELECT id id_,username username_ FROM USER这句话成功映射。我们知道上面的那种resultType是不能成功的。

案例如下;

案例结构如下:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUQAAAGfCAIAAACocTx9AAAgAElEQVR4nO2d+V8TWd7v83fcH+/rXu9zH/u58/SoSKenHcfdfnq0dbqntbUVdTrTYGx9lFZEhEZZAm6x0VZBRVkCIuAecUHaBVHEXZBOQCRBgW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Gv4bCOQ4JXiTjdc+oQZcZrcsLB2BeR8ItNasEjM2vW648YMO51Q8Ifijd0IECEoszSyAADgAATijJ7SEhngAFAwAljmUM2AwwAgkIYywwAAA7IDAASAWQGAIkAMgOARACZAUAigMwAIBFAZgCQCBErszOOwB/ZOgAQDMJb5iGrsf7gijvZC+5kL6g/uGLIanTfxgHIDEiNUJTZw+9mI4RuZi8ctug/DJs/DJt7DQ/rDqzweCP8oCCQGQhvQlFmD++aGrK03U6f+rZ227tnGf3P0noaUt5e/+lp3tcPcr54kPPFk/yV9gGRHkBmQGqEqMyeZIDd3TOn60leT2tZX1t5X1t536vTPfqyd/pTvW1ne9vOWpoK6w8uFm6NT7PFg7IAIDwIUZmRBxlg15InUd1akXIteZLwRsgyk4KyACA8CF2ZkbsMsMvbPqY6TtNlsK1Yf/m/649+eXv/jNv7Z9xWz7itnnFD9cmdX+bf+WX+nV8+57UWOjIzFWDWDYQZoSuz2wyw81v+QL0+Qb0+YXu6r/bX+d2P9lOd56jO81TnearrAtV1keq6RHVrbc0F1VnTea1BZkBqhKjMnmSAVW76D6rloLUhvWbPDOuTfVR7AdVeQLUXUoYiylBMGTSUscT67MDV7NmWtke81gLTbEJQFgCEByEqsydXs09t+MhSt+2a6s+W+h2UPofS51D6A1TLQarlV6rlENV62NKQqU2fYX71kNRa4MhMCMoCgPAgFGX28HPmYuW/X0qZaq79iWrcSTWmUY3pVFMG1ZRJNamol1mm2sSLabNMrUSTAUCChKLMHvLwzJ5C5cSy+I9Pb55cnhBVsTW6cmt05dboiq3Rl9Lm3tdsG3zXGewxAkDgCGOZAQDAAZkBQCKAzAAgEUBmAJAIIDMASASQGQAkAsgMABIBZAYAiQAyA4BEAJkBQCKAzAAgEUBmAJAIIDMASASQGQAkAsgMABIBZAYAiQAyA4BEAJkBQCKAzAAgEUBmAJAI/x8z35HzF1OAdAAAAABJRU5ErkJggg==" alt="" />

我们主要修改的还是userMapper.xml和userMapper.java

第一步:我们先修改userMapper.xml代码:

<?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">
<!-- nanmespace:命名空间。 作用就是对sql进行分类话管理,理解Sal分离 注意:使用mapper代理方式,namespace有特殊重要的作用
--> <mapper namespace="cn.itcast.mybatis.mapper.userMapper"> <!--
定义resultMap
将SELECT id id_,username username_ FROM USER 和User类中的属性做一个映射关系 type:resultMap最终映射的java对象类型,可以使用别名
id:对resultMap的唯一标识。
-->
<resultMap type="User" id="userResultMap">
<!--
id:表示查询结果集中唯一的标识。
column:查询出来的列名
property:type指定的pojo类型中的属性名
最终resultMap对column和property作一个映射关系(对应关系) -->
<id column="id_" property="id"/>
<result column="username_" property="username"/>
</resultMap>
     <!--
id:表示查询结果集中唯一的标识。
这里的resultMap要和<resultMap type="User" id="userResultMap">一致 -->
        <select id="findUserByResultMap" parameterType="cn.itcast.mybatis.po.UserQueryVo" resultMap="userResultMap">
SELECT id id_,username username_ FROM USER WHERE user.sex= #{userCustom.sex} AND user.username=#{userCustom.username}
</select> </mapper>

第二步:编写Mapper.java类

package cn.itcast.mybatis.mapper;

import java.util.List;

import cn.itcast.mybatis.po.User;
import cn.itcast.mybatis.po.UserCustom;
import cn.itcast.mybatis.po.UserQueryVo; public interface userMapper {
//这个名字(findUserById)和UserMapper.xml里面的id要一模一样
//注意这里写的是返回的List.这样代码内部就会调用selectList,但是在userMapper.xml中要写的是
//resultType="cn.itcast.mybatis.po.User"
/*
*
<select id="findUserList" parameterType="cn.itcast.mybatis.po.UserQueryVo" resultType="cn.itcast.mybatis.po.UserCustom">
SELECT * FROM USER WHERE user.sex= #{userCustom.sex} AND user.username=#{userCustom.username}
</select>
*
*
*/
public List<UserCustom> findUserList(UserQueryVo userQueryVo);
public User findUserByResultMap(UserQueryVo userQueryVo);
}

第三步:编写测试代码:

package cn.itcast.mybatis.first;

import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.List; import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test; import cn.itcast.mybatis.Dao.UserMapper;
import cn.itcast.mybatis.mapper.userMapper;
import cn.itcast.mybatis.po.User;
import cn.itcast.mybatis.po.UserCustom;
import cn.itcast.mybatis.po.UserQueryVo; public class Mybatis_mappertest { private SqlSessionFactory sqlSessionFactory;
@Before
public void setup() throws IOException
{ String resource="SqlMapConfig.xml";
InputStream inputStream= Resources.getResourceAsStream(resource);
//主要是生成SqlsessionFactory。
this.sqlSessionFactory=new SqlSessionFactoryBuilder().build(inputStream);
}
@Test
public void testMaper()
{
SqlSession sqlSession=null; sqlSession=sqlSessionFactory.openSession();
//生成代理类
userMapper userMapper=sqlSession.getMapper(userMapper.class);
//创建包装对象,设置查询条件
UserQueryVo userQueryVo=new UserQueryVo();
UserCustom userCustom=new UserCustom(); userCustom.setSex("1");
userCustom.setUsername("王");
userQueryVo.setUserCustom(userCustom); userMapper.findUserByResultMap(userQueryVo); } }

运行结果:正确。

总结:

使用resultType进行输出映射,只有查询出来的列名和pojo中的属性名一致,该列才可以映射成功。

如果查询出来的列名和pojo的属性名不一致,通过定义一个resultMap对列名和pojo属性名之间作一个映射关系。

上一篇:web app开发技巧总结 (share)


下一篇:storm深入研究