您当前的位置: 首页 >  mybatis

wespten

暂无认证

  • 0浏览

    0关注

    899博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

MyBatis核心技术二

wespten 发布时间:2020-04-04 15:13:10 ,浏览量:0

1.MyBatis_简介

2.MyBatis_下载

3.MyBatis_HelloWorld

(environments配置环(配置数据源)&SqlSessionFactory(通过sqlSessionFactoryBuilder()获取sqlSessionFactory.openSession()获取sqlSession.selectOne(“selectEmp”,1)可以直接执行已经映射的sql语句)&SqlSession&使用resultType实现(返回的数据类型)&mappers配置分析(#{id}从传递过来得到参数中取出id值,将写好的sql映射文件注册到全局mappers中,resource=”EmployeeMapper.xml”)&使用typeAliases配置别名)

4.MyBatis_接口式编程

(MyBatis注解配置(getSqlSessionFactory(),openSession.getMapper(EmployeeMappers.class),mapper.getEmpById(1)象)&命名空间:Namespace (namespace指定接口的全类名,select的id要与方法进行绑定,通过生成代理对象,通过代理对象进行增删改查)&)

5.MyBatis_小结(1)

(Connection(非线程安全,不能写在成员变量里,每次使用获取新的对象)&)

6.MyBatis_全局配置文件_引入dtd约束

(为Web 资源设置安全约束(window perferences xm xml Catalog 添加进Mybatis的约束,以后在xml文件中就会有提示)&)

7.MyBatis_全局配置文件_properties_引入外部配置文件

(修改db.properties文件(通过url获取网络或者类路径下的配置文件,类路径通过resource引入,com/)&)

8.MyBatis_全局配置文件_settings_运行时行为设置

(用驼峰法命名属性(在settings中设置,mapUnderscoreToCamelCase不用起别名)&使用resultType实现&alias标签的解析&)

9.MyBatis_全局配置文件_typeAliases_别名

(typeAliases类型命名( ,默认别名为类名小写,package name=”” 为包下的类批量起别名。通过@Alias(“”)为类指定类的别名)&)

10.MyBatis_全局配置文件_typeHandlers_类型处理器简介

(typeHandlers类型处理器(Java类型与数据库类型一一对应,)&)

11.MyBatis_全局配置文件_plugins_插件简介

(plugins配置分析(Executor执行器的方法,query,commit,update,rollback可以通过插件机制在executor执行增删改前执行默认的行为,ParameterHandler参数处理器,预编译需要设置参数,ResultSetHandler结果集处理器,StatementHandler对sql语句进行处理,插件可以拦截四大对象的方法)&)

12.MyBatis_全局配置文件_enviroments_运行环境

( default访问修饰符(通过environments的default指定某个环境进行切换)&DataSource(id是environment唯一标识,)&配置多个连接数据库环境(可以配置多个environment标签,environment中有和两种标签,JDBC事务与Managed使用J2EE容器的事物处理方式,dataSource type=”POOLED”使用连接池技术)&)

13.MyBatis_全局配置文件_databaseIdProvider_多数据库支持

(databaseIdProvider数据库厂商标识(为不同数据库厂商起别名 )&在SQL映射的id值相同的情况下有无databaseId的优先级判断(,只需要告诉mysql,对应的sql语句是在什么环境下的))

14.MyBatis_全局配置文件_mappers_sql映射注册

(使用Mapper接口对查询的数据进行分页(resource引用类路径下的sql映射文件,url应用网络或者磁盘路径下的资源,class直接引用接口,接口全类名,xml必须和接口放在同一目录下并且文件名一致,也可以直接将sql语句写在接口上,@Select,重要的需要映射文件 批量注册)&)

15.MyBatis_小结(2)

(@Configuration创世纪(映射文件的中标签要有一定的前后顺序,里面的一些标签可以没有)&)

16.MyBatis_映射文件_增删改查

(<parameter>标签和其处理类(parameterType参数类型可以指定全类名或者别名,#{email}取出对象中的属性值)&<sql:update>标签(更新可以不写parameter,mybatis允许增删改直接定义以下类型的返回值 Integer,Long,Boolean)&)

17.MyBatis_映射文件_insert_获取自增主键的值

(sqlSessionFactory创建(ssqlSessionFactory.openSession(true)自动提交,)&获取后一个自动生成的ID值的函数(useGeneratedKeys=”true” keyProperty=”id” 指定属性对应的主键值,Oracle不支持自增)&)

18.MyBatis_映射文件_insert_Oracle使用序列生成主键演示

19.MyBatis_映射文件_insert_获取非自增主键的值_selectKey

(序列对象(oracle序列就是自增, 查询主键的sql语句,写sql不能带分号)&)

20.MyBatis_映射文件_参数处理_单个参数&多个参数&命名参数

( 参数(Parameters)(mybatis单个参数不会做特殊处理#{absa},多个参数时mybatis会封装成一个Map,#{param1}获取指定的key,命名参数在接口方法上test(@Param(“id”) Integer id,@Param(“lastName”)String lastName) #{id})¶meters 指令支持的参数类型&请求参数与返回对象()&)

21.MyBatis_映射文件_参数处理_POJO&Map&TO

(POJO映射(直接传入POJO,通过#{属性名}获取POJO的值,也可以直接传入Map test(Map map),#{key}取出key的值)&)

22.MyBatis_映射文件_参数处理_参数封装扩展思考

(ids日志源(test(@Param(“e”)Employee emp)e.lastName  test(List ids) 如果是数组或者集合类型会特殊处理,collection或者list或者array作为key #{list[0})&模糊查询((%ss%))&)

23.MyBatis_源码分析_参数处理_参数封装map的过程

()

24.MyBatis_映射文件_参数处理_#与$取值区别

(预编译(#{}会进行预编译处理,${}直接将值拼到sql中会有sql注入风险,大多分库分表的情况下,表名不能使用占位符需要使用${year}_salary,order by ${f_name} asc ${order})&防止SQL注入&分库分表解决方案&)

25.MyBatis_映射文件_参数处理_#取值时指定参数相关规则

(插入null值的第 1种方法——JdbcType(mybatis对于所有null映射为jdbcType为OTHER类型,#{jdbcType=null}处理null值,也可以全局配置 为null的时候oracle识别)&)

26.MyBatis_映射文件_select_返回List

(使用resultType实现(如果返回值为List,resultType要写集合中封装的类型,mybatis会自动封装集合返回)&)

27.MyBatis_映射文件_select_记录封装map

(主键(返回类型为map,resultType为map类型单个记录,多条记录封装一个map,Map ,resultType始终是封装集合中元素的类型,接口上使用@MapKey(“id”)告诉Mybatis封装map时使用哪个属性做为主键)&)

28.MyBatis_映射文件_select_resultMap_自定义结果映射规则

(<resultMap>标签(如果列名与属性名不一致的情况下,resultMap=”MyEmp”可以自定义映射规则与resultType只能使用一个,@Alias(“emp”) )& COLUMN命令(指定哪一列对应哪一个property,非主键使用result定义)&)

29.MyBatis_映射文件_select_resultMap_关联查询_环境搭建

(使用外键需要注意的问题(外键级联属性, )&)

30.MyBatis_映射文件_select_resultMap_关联查询_级联属性封装结果

(联合查询(指定javaBean中的属性值,JavaType指定联合主键的类型 sql查询来的did,对应JavaBean的属性值)&)

31.MyBatis_映射文件_select_resultMap_关联查询_association定义关联对象封装规则

32.MyBatis_映射文件_select_resultMap_关联查询_association分步查询

(排序查询(分布查询 当前属性是调用select指定的方法查出的结果,column指定将哪一列的值传给该方法,最后封装给dept)&)

33.MyBatis_映射文件_select_resultMap_关联查询_分步查询&延迟加载

(提前加载和延迟加载(分段查询希望使用的时候再去查询,节省资源,,)&)

34.MyBatis_映射文件_select_resultMap_关联查询_collection定义关联集合封装规则

(一对多查询(left Join 定义关联集合类型的属性的封装规则,ofType指定集合里面元素额类型,在里面定义集合元素的封装对象规则)&)

35.MyBatis_映射文件_select_resultMap_关联查询_collection分步查询&延迟加载

(实体类定义与Mapper编写(一对多的分段查询 将查询出的id列值传递给方法进行查询)&)

36.MyBatis_映射文件_select_resultMap_分步查询传递多列值&fetchType

(Columns分区(分布查询传入多列的值 column=”{deptId=id,key2=column2}” #{deptId})&使用fetchType属性设置局部加载策略( 延迟加载)&)

37.MyBatis_映射文件_select_resultMap_discriminator鉴别器

(鉴别非法电话号码(判断某列的值,根据值进行封装, 指定封装什么类型时开始进行判断)&)

38.MyBatis_动态sql_简介&环境搭建

(Namespace类型(namespace写接口的全类名)&)

39.MyBatis_动态sql_if_判断&OGNL

( if语句( 根据参数中取值进行判断,转义字符处理特殊字符 and email.trim()!=" 会对字符串与数字进行自动转换)&)

40.MyBatis_动态sql_where_查询条件

(trim、where、set元素(where 1=1 and id=#{id},或者通过标签包含所有动态条件,不需要用1=1,自动去除第一个多出来的and或者or )&)

41.MyBatis_动态sql_trim_自定义字符串截取

(<trim>、<where>、<set>元素(将后面多出来的and或if去掉,prefix=”where”指定前缀,suffixOverrides=”and”去掉整个字符串后面多余的字符 )&)

42.MyBatis_动态sql_choose_分支选择

( choose、when和otherwise标签(choose相当于case 1=1 )&)

43.MyBatis_动态sql_set_与if结合的动态更新

(Set( last_name = #{lastName}, 取出更新后的逗号,)&)

44.MyBatis_动态sql_foreach_遍历集合

(<foreach>标签的使用(collection指定遍历的集合, list类型的参数会封装在map中,map的key对应list,separator元素之间的分隔符,open以什么开头,index就是索引,对应map的index就是key)&)

45.MyBatis_动态sql_foreach_mysql下foreach批量插入的两种方式

(实例26:“批量插入”与“逐条插入”数据,比较性能差异(values(),() #{emp.dept.id}属性的属性,new Department(1))&JDBC连接属性(jdbc.url=3306/mybatis?allowMultiQueries=true,多个sql之间;分隔)&)

46.MyBatis_动态sql_foreach_oracle下批量插入的两种方式

(针对Oracle的CURD(oracle不支持values(),()在begin end;中定义多条insert 语句,也可以通过中间表把数据一块拿出来,from dual union 连接上之后一块插入)&)

47.MyBatis_动态sql_foreach_oracle下foreach批量保存两种方式

(批量更新(oracle添加更新 open=”begin” close=”end;” begin end;)&)

48.MyBatis_动态sql_内置参数_parameter&_databaseId

(循环的内置参数(_paramete代码传入的参数,判断传入的参数是否为null,_databaseId当前数据库的别名 )&)

49.MyBatis_动态sql_bind_绑定

(使用bind()方法绑定事件(模糊查询 ’%${lastName}%’,将OGNL表达式的值绑定在一个变量中, #{_lastName})&)

50.MyBatis_动态sql_sql_抽取可重用的sql片段

(SQL语言基础( employee_id,last_name,email ,直接使用 直接使用include引用外部定义的sql)&)

51.MyBatis_缓存_缓存介绍

52.MyBatis_缓存_一级缓存体验

(获取本地缓存数据(一级缓存为本地缓存与数据库同一次会话查询到的数据sqlSession级别的 mapper=openSession.getMapper(Employee.class) emp = mapper.getEmpById(1),一级缓存一直会开启。二级缓存为全局缓存)&)

53.MyBatis_缓存_一级缓存失效的四种情况

(如何解决失效问题(sqlSession不同一级缓存失效,查询条件不同,两次查询之间进行了增删改等操作,)&)

54.MyBatis_缓存_二级缓存介绍

(namespace资源隔离(二级缓存namespacec级别的缓存,会话关闭一级缓存的数据会被保存到二级缓存中,)&)

55.MyBatis_缓存_二级缓存使用&细节

(二级缓存(mapper级别)( 开启全局二级缓冲, )&)

56.MyBatis_缓存_缓存有关的设置以及属性

(测试select、insert、update和delete操作(useCache=”false” 二级缓冲不适用,增删改flushCache=”true” 查询不会再使用缓存,清除1,2级缓存的数据,每次查询之后就会清除缓存)&clear( )清空缓冲区(只是清除一级缓存)&)

57.MyBatis_缓存_缓存原理图示

(二级缓存原理阐述(会话关闭,一级缓存的数据就会保存在二级缓存中,先查找二级缓存范围较大,之后再查询一级缓存与数据库)&)

58.MyBatis_缓存_第三方缓存整合原理&ehcache适配包下载

59.MyBatis_缓存_MyBatis整合ehcache&总结

(整合Ehcache()&)

60.MyBatis_整合Spring_整合适配包下载

61.MyBatis_整合Spring_所有需要的jar包导入

62.MyBatis_整合Spring_引入MyBatis之前的配置

63.MyBatis_整合Spring_SpringMVC配置文件编写

64.MyBatis_整合Spring_Spring配置文件编写

65.MyBatis_整合Spring_Spring整合MyBatis关键配置

(datasourcetransactionmanager的实现(spring与mybatis用同样的事务管理器,通过控制连接池的连接达到控制事务的目的,)&FactoryBean的使用(sqlSessionFactoryBean实现了FactoryBean接口,调用getObject()方法来创建sqlSessionFactory对象,)& 创建Configuration对象(指定全局配置文件的位置)&)

66.MyBatis_整合Spring_整合测试

67.MyBatis_逆向工程_mbg简介

68.MyBatis_逆向工程_mgb配置文件编写

69.MyBatis_逆向工程_使用mbg逆向生成所有代码及配置

70.MyBatis_逆向工程_测试简单查询&测试带条件复杂查询

71.MyBatis_运行原理_框架分层架构

(网络接口层(数据链路层)&Executor框架&)

72.MyBatis_运行原理_调试前注意

73.MyBatis_运行原理_SQLSessionFactory的初始化

(DeploymentBuilder对象&)

74.MyBatis_运行原理_openSession获取SqlSession对象

( Configuration介绍&使用--no-defaults选项&Statement接口&Statement接口)

75.MyBatis_运行原理_getMapper获取到接口的代理对象

76.MyBatis_运行原理_查询实现

77.MyBatis_运行原理_查询流程总结

78.MyBatis_运行原理_MyBatis原理总结

79.MyBatis_插件_插件原理

80.MyBatis_插件_插件编写&单个插件原理

81.MyBatis_插件_多个插件运行流程

82.MyBatis_插件_开发插件

83.MyBatis_扩展_分页_PageHelpler分页插件使用

84.MyBatis_扩展_批量_BatchExecutor&Spring中配置批量sqlSession

85.MyBatis_扩展_存储过程_oracle中创建一个带游标的存储过程

86.MyBatis_扩展_存储过程_MyBatis调用存储过程

87.MyBatis_扩展_自定义类型处理器_MyBatis中枚举类型的默认处理

88.MyBatis_扩展_自定义类型处理器_使用自定义的类型处理器处理枚举类型

66.MyBatis_整合Spring_整合测试

67.MyBatis_逆向工程_mbg简介

68.MyBatis_逆向工程_mgb配置文件编写

69.MyBatis_逆向工程_使用mbg逆向生成所有代码及配置

70.MyBatis_逆向工程_测试简单查询&测试带条件复杂查询

单个参数:mybatis不会做特殊处理,     #{参数名/任意名}:取出参数值。      多个参数:mybatis会做特殊处理。     多个参数会被封装成 一个map,         key:param1...paramN,或者参数的索引也可以         value:传入的参数值     #{}就是从map中获取指定的key的值;          异常:     org.apache.ibatis.binding.BindingException:      Parameter 'id' not found.      Available parameters are [1, 0, param1, param2]     操作:         方法:public Employee getEmpByIdAndLastName(Integer id,String lastName);         取值:#{id},#{lastName}

【命名参数】:明确指定封装参数时map的key;@Param("id")     多个参数会被封装成 一个map,         key:使用@Param注解指定的值         value:参数值     #{指定的key}取出对应的参数值

POJO: 如果多个参数正好是我们业务逻辑的数据模型,我们就可以直接传入pojo;     #{属性名}:取出传入的pojo的属性值    

Map: 如果多个参数不是业务模型中的数据,没有对应的pojo,不经常使用,为了方便,我们也可以传入map     #{key}:取出map中对应的值

TO: 如果多个参数不是业务模型中的数据,但是经常要使用,推荐来编写一个TO(Transfer Object)数据传输对象 Page{     int index;     int size; }

========================思考================================     public Employee getEmp(@Param("id")Integer id,String lastName);     取值:id==>#{id/param1}   lastName==>#{param2}

public Employee getEmp(Integer id,@Param("e")Employee emp);     取值:id==>#{param1}    lastName===>#{param2.lastName/e.lastName}

##特别注意:如果是Collection(List、Set)类型或者是数组,          也会特殊处理。也是把传入的list或者数组封装在map中。             key:Collection(collection),如果是List还可以使用这个key(list)                 数组(array) public Employee getEmpById(List ids);     取值:取出第一个id的值:   #{list[0]}      ========================结合源码,mybatis怎么处理参数========================== 总结:参数多时会封装map,为了不混乱,我们可以使用@Param来指定封装时使用的key; #{key}就可以取出map中的值;

(@Param("id")Integer id,@Param("lastName")String lastName); ParamNameResolver解析参数封装map的; //1、names:{0=id, 1=lastName};构造器的时候就确定好了

    确定流程:     1.获取每个标了param注解的参数的@Param的值:id,lastName;  赋值给name;     2.每次解析一个参数给map中保存信息:(key:参数索引,value:name的值)         name的值:             标注了param注解:注解的值             没有标注:                 1.全局配置:useActualParamName(jdk1.8):name=参数名                 2.name=map.size();相当于当前元素的索引     {0=id, 1=lastName,2=2}                 

args【1,"Tom",'hello'】:

public Object getNamedParams(Object[] args) {     final int paramCount = names.size();     //1、参数为null直接返回     if (args == null || paramCount == 0) {       return null;           //2、如果只有一个元素,并且没有Param注解;args[0]:单个参数直接返回     } else if (!hasParamAnnotation && paramCount == 1) {       return args[names.firstKey()];            //3、多个元素或者有Param标注     } else {       final Map param = new ParamMap();       int i = 0;              //4、遍历names集合;{0=id, 1=lastName,2=2}       for (Map.Entry entry : names.entrySet()) {                  //names集合的value作为key;  names集合的key又作为取值的参考args[0]:args【1,"Tom"】:           //eg:{id=args[0]:1,lastName=args[1]:Tom,2=args[2]}         param.put(entry.getValue(), args[entry.getKey()]);                           // add generic param names (param1, param2, ...)param         //额外的将每一个参数也保存到map中,使用新的key:param1...paramN         //效果:有Param注解可以#{指定的key},或者#{param1}         final String genericParamName = GENERIC_NAME_PREFIX + String.valueOf(i + 1);         // ensure not to overwrite parameter named with @Param         if (!names.containsValue(genericParamName)) {           param.put(genericParamName, args[entry.getKey()]);         }         i++;       }       return param;     }   } } ===========================参数值的获取====================================== #{}:可以获取map中的值或者pojo对象属性的值; ${}:可以获取map中的值或者pojo对象属性的值;

select * from tbl_employee where id=${id} and last_name=#{lastName} Preparing: select * from tbl_employee where id=2 and last_name=?     区别:         #{}:是以预编译的形式,将参数设置到sql语句中;PreparedStatement;防止sql注入         ${}:取出的值直接拼装在sql语句中;会有安全问题;         大多情况下,我们去参数的值都应该去使用#{};                  原生jdbc不支持占位符的地方我们就可以使用${}进行取值         比如分表、排序。。。;按照年份分表拆分             select * from ${year}_salary where xxx;             select * from tbl_employee order by ${f_name} ${order}

#{}:更丰富的用法:     规定参数的一些规则:     javaType、 jdbcType、 mode(存储过程)、 numericScale、     resultMap、 typeHandler、 jdbcTypeName、 expression(未来准备支持的功能);

    jdbcType通常需要在某种特定的条件下被设置:         在我们数据为null的时候,有些数据库可能不能识别mybatis对null的默认处理。比如Oracle(报错);                  JdbcType OTHER:无效的类型;因为mybatis对所有的null都映射的是原生Jdbc的OTHER类型,oracle不能正确处理;                  由于全局配置中:jdbcTypeForNull=OTHER;oracle不支持;两种办法         1、#{email,jdbcType=OTHER};         2、jdbcTypeForNull=NULL             

mbg.xml            





	
  
  	
    
    

	
    
      
    

	
    
      
      
    

	
    
      
    

	
    
      
    

	
    
    
  

package com.atguigu.mybatis.test;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
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.Test;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

import com.atguigu.mybatis.bean.Employee;
import com.atguigu.mybatis.bean.EmployeeExample;
import com.atguigu.mybatis.bean.EmployeeExample.Criteria;
import com.atguigu.mybatis.dao.EmployeeMapper;

/*import com.atguigu.mybatis.bean.Employee;
import com.atguigu.mybatis.dao.EmployeeMapper;*/

public class MyBatisTest {

	public SqlSessionFactory getSqlSessionFactory() throws IOException {
		String resource = "mybatis-config.xml";
		InputStream inputStream = Resources.getResourceAsStream(resource);
		return new SqlSessionFactoryBuilder().build(inputStream);
	}

	@Test
	public void testMbg() throws Exception {
		List warnings = new ArrayList();
		boolean overwrite = true;
		File configFile = new File("mbg.xml");
		ConfigurationParser cp = new ConfigurationParser(warnings);
		Configuration config = cp.parseConfiguration(configFile);
		DefaultShellCallback callback = new DefaultShellCallback(overwrite);
		MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,
				callback, warnings);
		myBatisGenerator.generate(null);
	}
	
	@Test
	public void testMyBatis3Simple() throws IOException{
		SqlSessionFactory sqlSessionFactory = getSqlSessionFactory();
		SqlSession openSession = sqlSessionFactory.openSession();
		try{
			EmployeeMapper mapper = openSession.getMapper(EmployeeMapper.class);
			List list = mapper.selectByExample(null);
			for (Employee employee : list) {
				System.out.println(employee.getId());
			}
		}finally{
			openSession.close();
		}
	}
	
	@Test
	public void testMyBatis3() throws IOException{
		SqlSessionFactory sqlSessionFactory = getSqlSessionFactory();
		SqlSession openSession = sqlSessionFactory.openSession();
		try{
			EmployeeMapper mapper = openSession.getMapper(EmployeeMapper.class);
			//xxxExample就是封装查询条件的
			//1、查询所有
			//List emps = mapper.selectByExample(null);
			//2、查询员工名字中有e字母的,和员工性别是1的
			//封装员工查询条件的example
			EmployeeExample example = new EmployeeExample();
			//创建一个Criteria,这个Criteria就是拼装查询条件
			//select id, last_name, email, gender, d_id from tbl_employee 
			//WHERE ( last_name like ? and gender = ? ) or email like "%e%"
			Criteria criteria = example.createCriteria();
			criteria.andLastNameLike("%e%");
			criteria.andGenderEqualTo("1");
			
			Criteria criteria2 = example.createCriteria();
			criteria2.andEmailLike("%e%");
			example.or(criteria2);
			
			List list = mapper.selectByExample(example);
			for (Employee employee : list) {
				System.out.println(employee.getId());
			}
			
		}finally{
			openSession.close();
		}
	}
	

}
package com.atguigu.mybatis.dao;

import com.atguigu.mybatis.bean.Employee;
import com.atguigu.mybatis.bean.EmployeeExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;

public interface EmployeeMapper {
    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_employee
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    int countByExample(EmployeeExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_employee
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    int deleteByExample(EmployeeExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_employee
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    int deleteByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_employee
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    int insert(Employee record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_employee
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    int insertSelective(Employee record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_employee
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    List selectByExample(EmployeeExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_employee
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    Employee selectByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_employee
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    int updateByExampleSelective(@Param("record") Employee record, @Param("example") EmployeeExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_employee
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    int updateByExample(@Param("record") Employee record, @Param("example") EmployeeExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_employee
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    int updateByPrimaryKeySelective(Employee record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_employee
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    int updateByPrimaryKey(Employee record);
}
package com.atguigu.mybatis.dao;

import com.atguigu.mybatis.bean.Department;
import com.atguigu.mybatis.bean.DepartmentExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;

public interface DepartmentMapper {
    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_dept
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    int countByExample(DepartmentExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_dept
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    int deleteByExample(DepartmentExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_dept
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    int deleteByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_dept
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    int insert(Department record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_dept
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    int insertSelective(Department record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_dept
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    List selectByExample(DepartmentExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_dept
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    Department selectByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_dept
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    int updateByExampleSelective(@Param("record") Department record, @Param("example") DepartmentExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_dept
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    int updateByExample(@Param("record") Department record, @Param("example") DepartmentExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_dept
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    int updateByPrimaryKeySelective(Department record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_dept
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    int updateByPrimaryKey(Department record);
}
package com.atguigu.mybatis.bean;

import java.util.ArrayList;
import java.util.List;

public class EmployeeExample {
    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database table tbl_employee
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    protected String orderByClause;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database table tbl_employee
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    protected boolean distinct;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database table tbl_employee
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    protected List oredCriteria;

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_employee
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    public EmployeeExample() {
        oredCriteria = new ArrayList();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_employee
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    public void setOrderByClause(String orderByClause) {
        this.orderByClause = orderByClause;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_employee
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    public String getOrderByClause() {
        return orderByClause;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_employee
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    public void setDistinct(boolean distinct) {
        this.distinct = distinct;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_employee
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    public boolean isDistinct() {
        return distinct;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_employee
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    public List getOredCriteria() {
        return oredCriteria;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_employee
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    public void or(Criteria criteria) {
        oredCriteria.add(criteria);
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_employee
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    public Criteria or() {
        Criteria criteria = createCriteriaInternal();
        oredCriteria.add(criteria);
        return criteria;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_employee
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    public Criteria createCriteria() {
        Criteria criteria = createCriteriaInternal();
        if (oredCriteria.size() == 0) {
            oredCriteria.add(criteria);
        }
        return criteria;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_employee
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    protected Criteria createCriteriaInternal() {
        Criteria criteria = new Criteria();
        return criteria;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_employee
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    public void clear() {
        oredCriteria.clear();
        orderByClause = null;
        distinct = false;
    }

    /**
     * This class was generated by MyBatis Generator.
     * This class corresponds to the database table tbl_employee
     *
     * @mbggenerated Sat Mar 25 13:59:48 GMT+08:00 2017
     */
    protected abstract static class GeneratedCriteria {
        protected List criteria;

        protected GeneratedCriteria() {
            super();
            criteria = new ArrayList();
        }

        public boolean isValid() {
            return criteria.size() > 0;
        }

        public List getAllCriteria() {
            return criteria;
        }

        public List getCriteria() {
            return criteria;
        }

        protected void addCriterion(String condition) {
            if (condition == null) {
                throw new RuntimeException("Value for condition cannot be null");
            }
            criteria.add(new Criterion(condition));
        }

        protected void addCriterion(String condition, Object value, String property) {
            if (value == null) {
                throw new RuntimeException("Value for " + property + " cannot be null");
            }
            criteria.add(new Criterion(condition, value));
        }

        protected void addCriterion(String condition, Object value1, Object value2, String property) {
            if (value1 == null || value2 == null) {
                throw new RuntimeException("Between values for " + property + " cannot be null");
            }
            criteria.add(new Criterion(condition, value1, value2));
        }

        public Criteria andIdIsNull() {
            addCriterion("id is null");
            return (Criteria) this;
        }

        public Criteria andIdIsNotNull() {
            addCriterion("id is not null");
            return (Criteria) this;
        }

        public Criteria andIdEqualTo(Integer value) {
            addCriterion("id =", value, "id");
            return (Criteria) this;
        }

        public Criteria andIdNotEqualTo(Integer value) {
            addCriterion("id ", value, "id");
            return (Criteria) this;
        }

        public Criteria andIdGreaterThan(Integer value) {
            addCriterion("id >", value, "id");
            return (Criteria) this;
        }

        public Criteria andIdGreaterThanOrEqualTo(Integer value) {
            addCriterion("id >=", value, "id");
            return (Criteria) this;
        }

        public Criteria andIdLessThan(Integer value) {
            addCriterion("id ", value, "lastName");
            return (Criteria) this;
        }

        public Criteria andLastNameGreaterThanOrEqualTo(String value) {
            addCriterion("last_name >=", value, "lastName");
            return (Criteria) this;
        }

        public Criteria andLastNameLessThan(String value) {
            addCriterion("last_name ", value, "email");
            return (Criteria) this;
        }

        public Criteria andEmailGreaterThanOrEqualTo(String value) {
            addCriterion("email >=", value, "email");
            return (Criteria) this;
        }

        public Criteria andEmailLessThan(String value) {
            addCriterion("email ", value, "gender");
            return (Criteria) this;
        }

        public Criteria andGenderGreaterThanOrEqualTo(String value) {
            addCriterion("gender >=", value, "gender");
            return (Criteria) this;
        }

        public Criteria andGenderLessThan(String value) {
            addCriterion("gender ", value, "dId");
            return (Criteria) this;
        }

        public Criteria andDIdGreaterThanOrEqualTo(Integer value) {
            addCriterion("d_id >=", value, "dId");
            return (Criteria) this;
        }

        public Criteria andDIdLessThan(Integer value) {
            addCriterion("d_id             
关注
打赏
1665965058
查看更多评论
0.0473s