14Mybatis_输入映射(传递pojo的包装对象)——很重要
假设我们有这么一个需求:用户信息的综合查询,需要传入的查询条件很复杂(可能包括用户信息,其他的信息,比如商品,订单)
我们的思想是:传入到select中的parameterType是一个包装类,里面可以有很多的东西。
我们已经有一个user.java po类了,但我们查询的条件可能是比user这个类更复杂的。我们为了方便扩展就要延伸出一个userCustom extend user 这么一个类。
案例如下:
先给出案例结构:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAU8AAAGgCAIAAAClvXLyAAAgAElEQVR4nO2d+V8TWd7v83fcH+/rXu9zH/u58/SoSKenHcfdfnq0dbqntbUVdTrTYGx9lFZEhEYFAm6x0VZBRdlFcDfigrQLooi7IJ2wSIIC2WSnAJ26P1RSOVV1TiVglkrV9/06L1+pyjmnTiHv1Kmi6hMVHTDszq7DeWcyj5VkHis5kn+mt68ffbfd2bsk7Uzgtg4AAA9V4LrWZxV1vG5ydLbaO1811D3JPJyHvttm65m+MY/UFgAAvxMQ2zutjm1pmS8rt/c37h1q3D1Ql2a9vfVw+uafEjJ+SsjYlpbZaXWMxnaDRqXWm8Y8HJNerdIYxtbuQ7YLANIiILZvS8vseVNBd9/ClPeD70cG3r7tBtsBIMgExPZNSftp5zV8oWnmdF2qto/1owEAJM8Yba+srNTpdKR3NyQcpa3n8OVf76dvzLtS25RadGfFrvO+bQ1sBwA/MBbbKyoqxo8fP27cOFKF1bEn6NeFTHlvKbh2Jv/nHcVrN+St3ZBX//L1+Wrj1A25s+IK7je8Pn3usbC5Sa9WuWC8M2hUar1ew1nnWu/C/WHAqeleyQjsqezpgL8lTx2VWm9CxBcMCQDCj1Hbzqi+aNEiEdu/0xynW4/QrUcGjUe3bivOPFt3rvU9Uy6a3zuofzHV6jsH/7m+jN8Yc3A1aFjLPOfS6AGfbYOtyajq7tOg8dTQuDtAV3IU1xjwQwKA8GN0trOqL168WMT2ew9ae01XnQ+PDzkaa4xvS14OCUv2bfv3sQbL625Ba+YAi07deWKr9SbOYRg5kuNq8mX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09zPNlLteZSrblUax5lzqfMBZS5kLIUOZ7tv5ox097ySNCaMJPHhLcBgBKR1jX5k+s+sldvuab7s71mG2XKpEyZlGk/1XiAavyVajxINR2y16YZUqbZmh/iWhOO7ZjwNgBQItL6e3uB9t8vJU22Vf1E1W2n6nZQdSlUfSpVn0bV66iX6daq+Is7ZlibsKoDAOAFad1L9/DM7jzt+JLYj09tnFgaF1G2OfL05sjTmyPLNkde2jH7fuGW/rftoR4jAIQr0rIdAIDAAbYDgFIA2wFAKYDtAKAUwHYAUApgOwAoBbAdAJQC2A4ASgFsBwClALYDgFIA2wFAKYDtAKAUwHYAUApgOwAoBbAdAJQC2A4ASgFsBwClALYDgFIA2wFAKYDtAKAUwHYAUApgOwAohf8PjOqldP51OnAAAAAASUVORK5CYII=" alt="" />
上面的案例说明如下:SqlMapConfig.xml是总的配置文件。mapper/userMapper.xml是这个案例的配置文件。User.java是针对数据库的实体类。UserCustom.java是User.java的实现类。UserQueryVo.java是包装类。userMapper.java是Mapper接口类。Mybatis_mappertest.java是测试代码。
第一步:
SqlMapConfig.xml代码如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration> <!-- properties的配置必须写在typeAliases的上面 -->
<properties resource="db.properties"></properties> <!-- 配置别名 -->
<typeAliases>
<!-- 针对别名定义
type:类型的路径
alias:别名
-->
<typeAlias type="cn.itcast.mybatis.po.User" alias="user"/>
</typeAliases> <!-- 和spring整合后 environments配置将废除-->
<environments default="development">
<environment id="development">
<!-- 使用jdbc事务管理-->
<transactionManager type="JDBC" />
<!-- 数据库连接池-->
<dataSource type="POOLED">
<property name="driver" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</dataSource>
</environment>
</environments> <!-- 把映射文件(sqlmap/user.xml)加载进sqlMapConfig.xml-->
<mappers> <!-- 把mapper.xml加载进sqlMapConfig.xml-->
<!--
遵循一些规范:需要将mapper接口类名和mapper.xml映射文件名称保持一致
且在一个目录中。
当着这个规范的前提是:使用mapper代理方法。 -->
<mapper resource="mapper/userMapper.xml"/> </mappers> </configuration>
第二步:
<?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表示输出的类型。
UserQueryVo里面有一个UserCustom, #{userCustom.sex} 里面写的是UserQueryVo里面的属性(userCustom)的属性(sex)
-->
<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>
第三步:
User.java代码和UserCustom.java:
package cn.itcast.mybatis.po; import java.util.Date; public class User {
private int id;//主键
private String username;//用户的名称
private Date birthday;//生日
private String sex;//性别
private String address;//地址
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
} }
package cn.itcast.mybatis.po; public class UserCustom extends User { }
第四步:写UserQueryVo.java包装类
package cn.itcast.mybatis.po; public class UserQueryVo {
//用户的查询条件
private UserCustom userCustom; public UserCustom getUserCustom() {
return userCustom;
} public void setUserCustom(UserCustom userCustom) {
this.userCustom = userCustom;
} }
第五步:userMapper.java是Mapper接口类
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);
}
第六步:
编写Mybatis_mappertest.java测试代码。
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.findUserList(userQueryVo); } }
结果:运行正常。
14Mybatis_输入映射(传递pojo的包装对象)——很重要的更多相关文章
- mybatis由浅入深day01_ 7输入映射(7.1传递pojo的包装对象_7.2#{}与${}_7.3传递简单类型_7.4传递pojo对象_7.5传递hashmap)
7 输入映射 通过parameterType指定输入参数的类型,类型可以是简单类型.hashmap.pojo的包装类型. 7.1 传递pojo的包装对象 7.1.1 需求 完成用户信息的综合查询,需要 ...
- mybatis入门基础(四)----输入映射和输出映射
一:输入映射 通过parameterType指定输入参数的类型,类型可以是简单类型.hashmap.pojo的包装类型. 1.1.传递pojo的包装对象 1.1.1.需求描述 完成用户信息的综合查询, ...
- 【mybatis深度历险系列】mybatis中的输入映射和输出映射
在前面的博文中,小编介绍了mybatis的框架原理以及入门程序,还有mybatis中开发到的两种方法,原始开发dao的方法和mapper代理方法,今天博文,我们来继续学习mybatis中的相关知识,随 ...
- Mybatis学习(4)输入映射、输出映射、动态sql
一.输入映射: 通过parameterType指定输入参数的类型,类型可以是简单类型.hashmap.pojo的包装类型 1) 传递pojo的包装对象 需求是:完成用户信息的综合查询,传入的查询条件复 ...
- (七)mybatis 的输入映射与输出映射
目录 前言 输入映射 - - 传递 pojo 包装类型 (复杂查询 ) 输出映射 - - resultType 输出映射 - - resultMap 前言 通过 paramterType 指定输入参数 ...
- mybatis基础系列(二)——基础语法、别名、输入映射、输出映射
增删改查 mapper根节点及其子节点 mybatis框架需要读取映射文件创建会话工厂,映射文件是以<mapper>作为根节点,在根节点中支持9个元素,分别为insert.update.d ...
- 【MyBatis学习06】输入映射和输出映射
在前面几篇博文的例子中也可以看到mybatis中输入映射和输出映射的身影,但是没有系统的总结一下,这篇博客主要对这两个东东做一个总结.我们知道mybatis中输入映射和输出映射可以是基本数据类型.ha ...
- Spring+SpringMVC+MyBatis深入学习及搭建(四)——MyBatis输入映射与输出映射
转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/6878529.html 前面有讲到Spring+SpringMVC+MyBatis深入学习及搭建(三)——My ...
- Mybatis输入映射和输出映射
本节内容: 输入参数映射 输出映射 resultMap Mapper.xml映射文件中定义了操作数据库的sql,每个sql是一个statement,映射文件是mybatis的核心. 一.环境准备 复制 ...
随机推荐
- 我的Fitbit Force手环使用体验
2013年底,从淘宝上代购了Fitbit Force二代,下手前也对比了当时的几个类似产品,好像记得Nike新款暂时在国内还买不到,就买下了这个,1020元,时至今日好像只需六.七百了.当时看中它的主 ...
- Centos 7: 打开Samba防火墙端口
firewall-cmd --permanent --add-port=137/tcp firewall-cmd --permanent --add-port=138/tcp firewall-cmd ...
- Volley网络连接
一.Volley a burst or emission of many things or a large amount at once Volley是Android平台上的网络通信库,能使网络通信 ...
- IP 协议首部格式与其配套使用的四个协议(ARP,RARP,ICMP,IGMP)
目录 IP协议首部格式地址解析协议 ARP逆向地址解析协议 RARP网际控制报文协议 ICMP网际组管理协议IGMP IP 数据报首部 IP数据报首部格式: 最高位在左边,记为0 bit:最低位在右边 ...
- Linux0.11内核剖析--内核体系结构
一个完整可用的操作系统主要由 4 部分组成:硬件.操作系统内核.操作系统服务和用户应用程序,如下图所示: 用户应用程序是指那些字处理程序. Internet 浏览器程序或用户自行编制的各种应用程序: ...
- oc 字符串
#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { ...
- WPF Caliburn.Micro ListView 批量删除 新方法.高效的
上一片我做的批量删除,是更具ListView的选项改变事件,然后放到一个全局变量里面,缺点已经说了.这次又找到一个好的方法.和大家分享一下.这次我将删除按钮的click事件里面的参数绑定为ListVi ...
- linux+jre+apache+mysql+tomcat调优
一.不再为Apache进程淤积.耗尽内存而困扰 0. /etc/my.cnf,在mysqld那一段加上如下一行: log-slow-queries=queries-slow.log 重启MySQL 酌 ...
- QA:Failed to deploy artifacts from/to snapshots XX Failed to transfer file Return code is: 405, ReasonPhrase:Method Not Allowed.
QA: Failed to deploy artifacts from/to snapshots XX Failed to transfer file Return code is: 405, Rea ...
- Effective Java 21 Use function objects to represent strategies
Theory In the Java the function pointers is implemented by the declaring an interface to represent s ...