mybatis
请叫我大虾
这个作者很懒,什么都没留下…
展开
-
org.apache.ibatis.binding.BindingException原因总结
排查方法如下:1、mapper接口和mapper.xml是否在同一个包(package)下?名字是否一样(仅后缀不同)?2、mapper.xml的命名空间(namespace)是否跟mapper接口的包名一致?(本人实在这里出错了)比如下图: mapperxml中AccountMapper的包名写错了. 少写了一个p3、接口的方法名,与xml中的一条sql标签的id一致...原创 2020-04-27 14:58:36 · 311 阅读 · 0 评论 -
mybaits二十一:1连接池以及事务控制
实际开发中经常会用到连接池,连接池可以减少我们获取连接所消耗的时间。原创 2020-03-18 22:37:54 · 191 阅读 · 0 评论 -
mybaits四-3:获取保存数据的id
<?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"><mapper namespace="com.atchi...原创 2020-03-14 09:29:58 · 355 阅读 · 0 评论 -
mybaits四-2:模糊查询
<?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"><mapper namespace="com.atchi...原创 2020-03-14 09:31:53 · 183 阅读 · 0 评论 -
mybaits二十七:spring, spring mvc,mybatis(ssm) 整合
配置web.xml<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocat...原创 2019-04-07 02:36:34 · 207 阅读 · 0 评论 -
mybaits二十六:mybatis,spring整合
整合需要的spring的jar包原创 2019-04-06 19:01:10 · 171 阅读 · 0 评论 -
mybaits二十五:mybatis整合ehcache
1. 整合需要的ehcache的jar包ehcache-core 包依赖 sfl4j-api,slf4j-log4j12包mybatis-ehcache是将mybatis和ehcache适配起来的包2.整合还需要一个ehcache.xml文件xml文件配置如下<ehcache> <!-- 磁盘存储:将缓存中暂时不...原创 2019-04-06 18:29:15 · 260 阅读 · 0 评论 -
mybaits二十四:缓存原理示意图
原创 2019-04-06 17:18:22 · 439 阅读 · 0 评论 -
mybaits二十八:逆向工程
mybatis generator 简称MBG,是一个专门为mybatis框架使用者定制的代码生成器.可以快速的根据表生成对应的映射文件,接口以及bean类。支持基本的增删改查,以及QBC风格的条件查询。但是表连接,存储过程等这些复杂的sql定义需要我们手工编写。逆向工程配置文件mbg.xml<?xml version="1.0" encoding="UTF-8"?&...原创 2019-04-07 12:20:36 · 257 阅读 · 0 评论 -
mybaits二十九:mybatis工作原理以及源码分析
根据配置文件创建SqlSessionFactorySqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);openSession获取sqlSession对象 SqlSession openSession = sqlSessio...原创 2019-04-07 18:31:16 · 206 阅读 · 0 评论 -
mybaits三:全局配置文件
environments标签<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd"><configuratio...原创 2019-03-28 22:32:59 · 229 阅读 · 0 评论 -
mybaits十八:内置标签
<!-- 两个内置参数: 不只是方法传递过来的参数可以用来判断,取值... mybatis默认还有两个内置参数, _parameter:代表整个参数 单个参数:_parameter就是这个参数 多个参数:参数会被封装为一个map,_parameter就是这个map ...原创 2019-04-02 23:29:57 · 288 阅读 · 0 评论 -
mybaits十九:bind绑定
<select id="getEmpsByInnerParam" resultType="com.atChina.bean.Employee"> <!-- bind标签可以将OGNL表达式的值绑定到一个变量中,方便后来引用这个变量的值 --> <bind name="_empName" value="'%'+ename+'%'"/> ...原创 2019-04-02 23:44:50 · 257 阅读 · 0 评论 -
mybaits二十:sql标签(抽取可重用的标签), include标签引用sql标签
<insert id="addEmps"> <foreach collection="list" item="emp" open="begin" close="end;"> insert into emptest( <include refid="insertColumn"></include> ...原创 2019-04-03 00:06:01 · 743 阅读 · 0 评论 -
mybaits二十一:2缓存介绍
mybatis系统中默认定义了两级缓存. 一级缓存和二级缓存 1.默认情况下,只有一级缓存(SqlSession级别的缓存,也称为本地缓存)开启。 2.二级缓存需要手动开启和配置,他是基于namespace级别的缓存。 3.为了提高扩展性。mybatis定义了缓存接口Cache。我们可以通过实现Cache接口来自定义二级缓...原创 2019-04-03 00:14:00 · 189 阅读 · 0 评论 -
mybaits二十三:二级缓存
二级缓存:(全局缓存),基于namespace级别的缓存,一个namespace对应一个二级缓存 工作机制: 1. 一个会话,查询一条数据,这个数据就会被放在当前会话的一级缓存中. 2. 如果会话关闭,一级缓存中的数据会被保存到二级缓存中,新的会话查询信息,就可以参照二级缓存的内容 3. 不同的namespace...原创 2019-04-05 23:34:36 · 222 阅读 · 0 评论 -
mybaits十七:使用foreach标签
foreach标签查询 主要用于构建in条件,他可以在sql中对集合进行迭代<select id="getEmpsByConditionForeach" resultType="com.atChina.bean.Employee"> select * from emptest <!-- collection:指定遍历的集合 ...原创 2019-03-31 23:48:22 · 542 阅读 · 0 评论 -
mybaits十六:使用set标签实现更新
<update id="updateEmpsByConditionSet" > update emptest <set> <if test="ename!=null"> ename = #{ename}, </if> <if test="job != null">...原创 2019-03-31 21:46:09 · 315 阅读 · 0 评论 -
mybaits二:通过接口类,查询数据
定义bean,对应数据库中的表package com.atChina.bean; public class Employee { private Integer deptno; private String dname; private String loc; public int getDeptno() { return deptno; } public voi...原创 2019-03-25 18:38:35 · 311 阅读 · 0 评论 -
mybaits三:全局配置文件(全面)
转载自: https://www.cnblogs.com/pjfmeng/p/7677773.html在全集配置文件中引入dtd约束“http://mybatis.org/dtd/mybatis-3-config.dtd”,主要有以下几个标签,现在详细解释下这几个标签的使用1、properties属性----引入外部properties配置文件<?xml version...转载 2019-03-30 11:00:37 · 208 阅读 · 0 评论 -
mybaits四-1:增删改查的实现
定义接口类:package com.atChina.dao;import com.atChina.bean.Employee;public interface EmployeeMapper { public Employee getEmployeeById(Integer depno); public void addEmploy(Employee employee); ...原创 2019-03-30 11:57:39 · 247 阅读 · 0 评论 -
mybaits五:主键的自增
mysql支持主键的自增 useGeneratedKeys=="true"使用自增主键获取主键值策略 keyProperty:指定对应的主键值,也就是mybatis获取到主键值后,将这个值封装给java bean的某个属性。<!-- parameterType可以省略不写 --> <insert id="addEmploy" p...原创 2019-03-30 13:21:42 · 254 阅读 · 0 评论 -
mybaits六:参数处理
单个参数和多个参数 单个参数 mybatis不多做特殊处理,通过 #{参数名},取出参数值<select id="getEmployeeById" resultType="emp" > select * from DEPTTEST where deptno = #{deptno} </select> 多个参数...原创 2019-03-30 15:20:39 · 276 阅读 · 0 评论 -
mybaits七:select查询返回list集合
package com.atChina.dao;import java.util.List;import java.util.Map;import org.apache.ibatis.annotations.Param;import com.atChina.bean.Employee;public interface EmployeeMapper { public List...原创 2019-03-30 19:10:16 · 2375 阅读 · 0 评论 -
mybaits八:select查询返回map集合
返回一条纪录的mappackage com.atChina.dao;import java.util.List;import java.util.Map;import org.apache.ibatis.annotations.MapKey;import org.apache.ibatis.annotations.Param;import com.atChina.bean.E...原创 2019-03-30 19:31:48 · 2787 阅读 · 0 评论 -
mybaits九:自定义结果映射规则
定义接口:package com.atChina.dao;import com.atChina.bean.Employee;public interface EmployeePlusMapper { public Employee getEmpByDepnos(Integer depno); }sql配置文件<?xml version="1.0" encodi...原创 2019-03-30 22:12:28 · 221 阅读 · 0 评论 -
mybaits十:关联查询
普通javaBeanpackage com.atChina.bean;import java.util.Date;public class Employee { private String empno; private String ename; private String job; private Integer mgr; private Date hiredate...原创 2019-03-30 22:52:47 · 206 阅读 · 0 评论 -
mybaits十一:使用association分步查询
DepartmentMapper.xml sql配置文件<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><!-- ...原创 2019-03-30 23:49:18 · 336 阅读 · 0 评论 -
mybaits十二:使用collection嵌套结果集查询
定义bean, 该bean中有一个集合属性empspackage com.atChina.bean;import java.util.List;public class Department { private Integer id; private List<Employee> emps; public List<Employee> getEmp...原创 2019-03-31 11:49:34 · 652 阅读 · 0 评论 -
mybaits十三:使用collection分布查询
DepartmentMapper.xml的sql配置文件<resultMap type="com.atChina.bean.Department" id="defineDeptStep"> <id column="deptno" property="deptno"/> <result column="dname" property="dname"/...原创 2019-03-31 12:29:11 · 271 阅读 · 0 评论 -
mybaits十四:使用if和where标签构建动态sql
<where>标签会在sql语句中加上 'where',并且会去掉'and'(使用where标签的话,and就要放在语句的前面,比如'and ename = #{ename}', 如果放在语句的后面,比如'ename = #{ename} and' , where标签可能去不掉and,就会造成拼接的sql语句最后多一个and,造成错误)<select id="getEm...原创 2019-03-31 20:38:23 · 228 阅读 · 0 评论 -
mybaits十五:使用trim自定义字符串的截取规则
<select id="getEmpsByConditionTrim" resultType="com.atChina.bean.Employee"> select * from( select a.empno as no, a.ename, a.job, a.mgr, a.hiredate, a.sal, a.deptno from emptest ...原创 2019-03-31 20:59:59 · 348 阅读 · 0 评论 -
mybaits十六:使用choose标签实现分支选择
<!-- 分支选择 <choose> <when></when> <otherwise></otherwise> </choose> 类似于switch-case-default的使用 --> <select i...原创 2019-03-31 21:16:07 · 327 阅读 · 0 评论 -
mybaits一:初步认识mybatis
定义bean,对应数据库中的表package com.atChina.bean;public class Employee { private Integer deptno; private String dname; private String loc; public int getDeptno() { return deptno; } public voi...原创 2019-03-25 17:15:28 · 235 阅读 · 0 评论