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属性名之间作一个映射关系。
15Mybatis_输出类型的更多相关文章
- 【SAP业务模式】之ICS(六):发票输出类型
这篇开始主要讲述发票输出类型: 首先我们新建一个发票类型,用于公司间的发票MIV,而标准的发票类型还是F2保持不变: 一.新建发票类型: 目录:SPRO-销售与分销-出具发票-开票凭证-定义出具发票类 ...
- Visual Stdio 无法直接启动带有“类库输出类型”的项目若要调试此项目,请在此解决方案中添加一个引用库项目的可执行项目。将这个可执行项目设置为启动项目!
j解决方法:项目-属性-应用程序-输出类型-Windows应用程序
- paip.多维理念 输入法的外码输入理论跟文字输出类型精髓
paip.多维理念 输入法的外码输入理论跟文字输出类型精髓 通常,我们的输入法使用的外码是拼音,但是,这个的用户体验很差.. 应该使用多个外码类型... ##按照词汇来源,有如下几个 固有词ati 来 ...
- mybatis由浅入深day01_8输出映射_8.1resultType输出类型(8.1.1输出简单类型_8.1.2输出pojo对象和pojo列表_8.1.3输出hashmap)
8 输出映射 8.1 resultType(输出类型) 使用resultType进行输出映射,只有查询出来的列名和pojo中的属性名一致,该列才可以映射成功. 如果查询出来的列名和pojo中的属性名全 ...
- Log4j(3)--rootLogger根配置和appender输出类型配置
参考博客:http://blog.java1234.com/blog/articles/270.html 一.rootLogger根配置: Log4j 根配置语法 log4j.rootLogger = ...
- 20190615 NACE关于采购订单的输出类型
项目已经做好的配置,我们复盘一下 一.使用NACE 进入输出控制条件: EF 采购订单,首先看->输出类型 标准是使用 nast 作为记录表 1输出类型, 2过程, 3 存取顺序,4 条件记录: ...
- ExecuteNonQuary接收存储过程的输出类型的变量的值
1.设置所调用的存储过程需要的参数 public decimal CreateOrder(string orderId, int userId, string address) { SqlParame ...
- PHP 注释 数据类型 变量的定义/输出 类型的获取/转换 可变变量
注释方法: 1,单行注释: // 2, 多行注释: /* */ 二,数据类型 1,integer(整数型):在三十二位操作系统中它的有效范围是:-2147483648~+2147 ...
- console.log()中的%d,%s等代表的输出类型
在console.log()或console.debug()中输出时会有%d,%s等符号. %s for a String value 字符类型 %d or %i for a Integer valu ...
随机推荐
- android布局--Android fill_parent、wrap_content和match_parent的区别
来自:http://www.cnblogs.com/nikyxxx/archive/2012/06/15/2551390.html 三个属性都用来适应视图的水平或垂直大小,一个以视图的内容或尺寸为基础 ...
- Sharepoint 2013 列表使用JS Link
使用JS Link可以向Sharepoint List注册脚本,重写Field模板,使得对于符合条件的字段改变格式和样式.但是有一个问题是,页面postback的话,JS不会被触发,不知道怎么解,有知 ...
- IOS程序开发中-跳转到 发送短信界面 实现发短信
前言:我发现我标题取的不好,谁帮我取个承接上下文的标题?评论一下,我改 项目需求:在程序开发中,我们需要在某个程序里面发送一些短信验证(不是接收短信验证,关于短信验证,传送门:http://www.c ...
- 如何在Eclipse卸载之前添加的android 的 ADT
Android开发环境配置中,怎么卸载ADT? 在Android开发环境配置中,可能会遇到很多问题,其中ADT安装失败需要卸载,怎么卸载呢?下面讲一种方法,希望能够对你有所帮助. 我采用的是Eclip ...
- IOS 应用跳转 (IOS9白名单)
跳转到指定app的实现 IOS中应用的跳转是通过URL实现的,因此在实现应用跳转之前我们要设置一下对应的URL. 图一(寻找配置软件的URL) 图二(具体配置选项) 注意: 如果IOS版本为IOS9 ...
- UVa 103 - Stacking Boxes(dp求解)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- 敏捷软件开发:原则、模式与实践——第8章 SRP:单一职责原则
第8章 SRP:单一职责原则 一个类应该只有一个发生变化的原因. 8.1 定义职责 在SRP中我们把职责定义为变化的原因.如果你想到多于一个的动机去改变一个类,那么这个类就具有多于一个的职责.同时,我 ...
- 回文数 第N个回文数
判断回文数还是不难,如果能转为字符串就更简单了. 如果是求第N个回文数呢. 12321是一个回文数,这里先考虑一半的情况. 回文数的个数其实是有规律的.如: 1位回文数: 9个 2位回文数: 9个 3 ...
- springMVC请求流程详解
SpringMVC框架是一个基于请求驱动的Web框架,并且使用了'前端控制器'模型来进行设计,再根据'请求映射规则'分发给相应的页面控制器进行处理. (一)整体流程 具体步骤: 1. 首先用户发送请 ...
- 在IE8等不支持placeholder属性的浏览器中模拟placeholder效果
placeholder是一个很有用的属性,可以提示用户在input框中输入正确的内容,但是IE8以及IE8一下的浏览器不支持该属性,我们可以使用js来模拟相似的效果.下面直接上代码: <!doc ...