java深入探究16-mybatis
链接:http://pan.baidu.com/s/1skJ4TNB 密码:koo9
1.引入mybatis
jsbc简单易学,上手快,非常灵活构建SQL,效率高但代码繁琐,难以写出高质量的代码
hibernate不用写SQL,完全以面向对象的方式设计和访问但处理复杂业务时,灵活度差
所以中间产物:mybatis就应运而生
2.mybatis说法和特定
1)MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google code,并且改名为MyBatis 。2013年11月迁移到Github。
2)iBATIS一词来源于“internet”和“abatis”的组合,是一个基于Java的持久层框架。iBATIS提供的持久层框架包括SQL Maps和Data Access Objects(DAO)
3)jdbc/dbutils/springdao,hibernate/springorm,mybaits同属于ORM解决方案之一
3.mybatis快速入门
1)导入jar包(5个核心包+2个数据库访问包):asm-3.3.1.jar;cglib-2.2.2.jar;commons-logging-1.1.1.jar;log4j-1.2.16.jar;mybatis-3.1.1.jar;mysql-connector-java-5.1.7-bin.jar;ojdbc5.jar
2)创建sql:
--mysql语法
create table students(
id int() primary key,
name varchar(),
sal double(,)
);
--oracle语法
create table students(
id number() primary key,
name varchar2(),
sal number(,)
);
创建Student.java
/**
* 学生
* @author AdminTC
*/
public class Student {
private Integer id;
private String name;
private Double sal;
public Student(){}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Double getSal() {
return sal;
}
public void setSal(Double sal) {
this.sal = sal;
}
}
3)配置映射文件StudentMapper.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"> <mapper namespace="mynamespace">
<insert id="add1">
insert into students(id,name,sal) values(,'哈哈',)
</insert>
<insert id="add2" parameterType="cn.itcast.javaee.mybatis.app05.Student">
insert into students(id,name,sal) values(#{id},#{name},#{sal})
</insert>
</mapper>
4)配置mybatis.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>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://127.0.0.1:3306/mybatis"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="cn/itcast/javaee/mybatis/app05/StudentMapper.xml"/>
</mappers>
</configuration>
5)创建MyBatisUtil工具类
/**
* MyBatis工具类
* @author AdminTC
*/
public class MyBatisUtil {
private static ThreadLocal<SqlSession> threadLocal = new ThreadLocal<SqlSession>();
private static SqlSessionFactory sqlSessionFactory;
static{
try {
Reader reader = Resources.getResourceAsReader("mybatis.xml");
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
private MyBatisUtil(){}
public static SqlSession getSqlSession(){
SqlSession sqlSession = threadLocal.get();
if(sqlSession == null){
sqlSession = sqlSessionFactory.openSession();
threadLocal.set(sqlSession);
}
return sqlSession;
}
public static void closeSqlSession(){
SqlSession sqlSession = threadLocal.get();
if(sqlSession != null){
sqlSession.close();
threadLocal.remove();
}
}
public static void main(String[] args) {
Connection conn = MyBatisUtil.getSqlSession().getConnection();
System.out.println(conn!=null?"连接成功":"连接失败");
}
}
6)创建StudentDao
/**
* 持久层
* @author AdminTC
*/
public class StudentDao {
/**
* 增加学生(无参)
*/
public void add1() throws Exception{
SqlSession sqlSession = MyBatisUtil.getSqlSession();
try{
sqlSession.insert("mynamespace.add1");
}catch(Exception e){
e.printStackTrace();
sqlSession.rollback();
throw e;
}finally{
sqlSession.commit();
}
MyBatisUtil.closeSqlSession();
}
/**
* 增加学生(有参)
*/
public void add2(Student student) throws Exception{
SqlSession sqlSession = MyBatisUtil.getSqlSession();
try{
sqlSession.insert("mynamespace.add2",student);
}catch(Exception e){
e.printStackTrace();
sqlSession.rollback();
throw e;
}finally{
sqlSession.commit();
}
MyBatisUtil.closeSqlSession();
}
public static void main(String[] args) throws Exception{
StudentDao dao = new StudentDao();
dao.add1();
dao.add2(new Student(,"呵呵",8000D));
}
}
4. mybatis工作流程
1)通过Reader对象读取src目录下的mybatis.xml配置文件(改文件的名字和位置可变)
2)通过SqlSessionFactoryBuilder对象创建sqlSessionFactory对象
3)从当前线程中获取SqlSession对象
4)事务开始,mybatis中默认
5)通过sqlSession对象读取StudentMapper.xml映射文件中操作编号,从而读取sql语句
6)事务提交必写
7)关闭SqlSession对象并且分离当前线程与sqlSession对象,让GC尽早回收
5.mybatis配置文件解析
1)StudentMapper.xml文件,提倡放在与实体同目录下,文件名任意
2)environments连接环境信息优化:
1.建一个db.properties用来存放连接信息
2.在mybatis中properties属性可以加载这个配置信息
3.连接环境配置属性值就可以用${mysql.url}形式从配置文件中获取了
3)StudentMapper.xml中insert标签parameterType="app04.Student"每次要类全路径
简化方式:
1.mybatis中添加
<!-- 设置类型别名 -->
<typeAliases>
<typeAlias type="app04.Student" alias="student"/>
</typeAliases>
2.之后在StudentMapper.xml中写类型时都可以用简称student了
<?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="mynamespace">
<insert id="add1">
insert into students(id,name,sal) values(,'哈哈',)
</insert>
<insert id="add2" parameterType="cn.itcast.javaee.mybatis.app05.Student">
insert into students(id,name,sal) values(#{id},#{name},#{sal})
</insert>
</mapper>
6.mybatis映射文件祥解(StudentMapper.xml)
StudentMapper:存放表映射;sql语句
mybatis:连接环境信息,加载映射文件
7.基于MybatisUtil工具类,完成CURD操作
StudentMapper.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"> <mapper namespace="app09.Student"> <resultMap type="app09.Student" id="studentMap">
<id property="id" column="id"/>
<result property="name" column="name"/>
<result property="sal" column="sal"/>
</resultMap> <!-- 增加学生 -->
<insert id="add" parameterType="app09.Student">
insert into students(id,name,sal) values(#{id},#{name},#{sal})
</insert>
<!-- 根据ID查询学生
如果参数不是一个实体的话,只是一个普通变量,例如:int,double,String
这里的#{中间的变量名可以随便写},不过提倡就用方法的形参
-->
<select id="findById" parameterType="int" resultType="app09.Student">
select * from students where id=#{id}
</select>
<!-- 查询所有学生
理论上resultType要写List<Student>
但这里只需书写List中的类型即可,即只需书写Student的全路径名
-->
<select id="findAll" resultType="app09.Student">
select id,name,sal from students
</select>
<!-- 更新学生 -->
<update id="update" parameterType="app09.Student">
update students set name=#{name},sal=#{sal} where id=#{id}
</update>
<!-- 删除学生 -->
<delete id="delete" parameterType="app09.Student">
delete form students where id=#{id}
</delete> <!--
注意:这个insert/update/delete标签只是一个模板,在做操作时,其实是以SQL语句为核心的
即在做增/删/时,insert/update/delete标签可通用,
但做查询时只能用select标签
我们提倡什么操作就用什么标签
-->
</mapper>
StudentDao.java
package app09; import java.util.List; import org.apache.ibatis.session.SqlSession;
import util.MybatisUtil; public class StudentDao {
/**
* 增加学生
*/
public void add(Student student)throws Exception{
SqlSession sqlSession=null;
try{
sqlSession=MybatisUtil.getSqlSession();
//开始事务
sqlSession.insert(Student.class.getName()+".add",student);
sqlSession.commit();
//提交
}catch (Exception e) {
e.printStackTrace();
sqlSession.rollback();
}finally{
//解除关系让GC处理sqlSession对象
MybatisUtil.closeSqlSession();
}
}
/**
*根据ID 查询学生
*/
public Student findById(int id)throws Exception{
SqlSession sqlSession=null;
try{
sqlSession=MybatisUtil.getSqlSession();
//开始事务
Student student=sqlSession.selectOne(Student.class.getName()+".findById", id);
sqlSession.commit();
return student;
//提交
}catch (Exception e) {
e.printStackTrace();
sqlSession.rollback();
throw new RuntimeException();
}finally{
//解除关系让GC处理sqlSession对象
MybatisUtil.closeSqlSession();
}
}
/**
* 查询所有学生
*/
public List<Student> findAll()throws Exception{
SqlSession sqlSession=null;
try{
sqlSession=MybatisUtil.getSqlSession();
//开始事务
return sqlSession.selectOne(Student.class.getName()+".findAll"); //提交
}catch (Exception e) {
e.printStackTrace();
sqlSession.rollback();
throw new RuntimeException();
}finally{
//解除关系让GC处理sqlSession对象
MybatisUtil.closeSqlSession();
}
}
/**
* 更新学生
*/
public void update(Student student) throws Exception{
SqlSession sqlSession = null;
try{
sqlSession = MybatisUtil.getSqlSession();
sqlSession.update(Student.class.getName()+".update",student);
sqlSession.commit();
}catch(Exception e){
e.printStackTrace();
sqlSession.rollback();
throw e;
}finally{
MybatisUtil.closeSqlSession();
}
}
/**
* 删除学生
*/
public void delete(Student student) throws Exception{
SqlSession sqlSession = null;
try{
sqlSession = MybatisUtil.getSqlSession();
sqlSession.delete(Student.class.getName()+".delete",student);
sqlSession.commit();
}catch(Exception e){
e.printStackTrace();
sqlSession.rollback();
throw e;
}finally{
MybatisUtil.closeSqlSession();
}
} public static void main(String[] args) throws Exception{
StudentDao dao = new StudentDao();
//dao.add(new Student(1,"哈哈",7000D));
//dao.add(new Student(2,"呵呵",8000D));
//dao.add(new Student(3,"班长",9000D));
//dao.add(new Student(4,"键状高",10000D));
//Student student = dao.findById(4);
//List<Student> studentList = dao.findAll();
//for(Student student : studentList){
// System.out.print(student.getId()+":"+student.getName()+":"+student.getSal());
// System.out.println();
//}
Student student = dao.findById();
System.out.println(student.getName());
//student.setName("靓班长");
//dao.update(student); //Student student = dao.findById(3);
//System.out.print(student.getId()+":"+student.getName()+":"+student.getSal()); //dao.delete(student);
}
}
8.分页查询
package app10; import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.session.SqlSession;
import util.MybatisUtil; public class StudentDao {
public void add(Student student)throws Exception{
SqlSession sqlSession=null;
try{
sqlSession.insert(Student.class.getName()+".add",student);
sqlSession.commit();
}catch (Exception e) {
e.printStackTrace();
sqlSession.rollback();
}finally{
MybatisUtil.closeSqlSession();
}
}
/**
* 分页
* 在映射文件中参数不能是多个,对个多个参数需要封装用map
* @param start
* @param size
* @return
*/
public List<Student> findAllWithFy(int start,int size){
SqlSession sqlSession=null;
try{
sqlSession = MybatisUtil.getSqlSession(); Map<String,Object> map = new LinkedHashMap<String,Object>();
map.put("pstart",start);
map.put("psize",size);
return sqlSession.selectList(Student.class.getName()+".findAllWithFy", map);
}catch(Exception e){
e.printStackTrace();
sqlSession.rollback();
throw new RuntimeException();
}finally{
MybatisUtil.closeSqlSession();
}
}
/**
* 分页有条件
* 在映射文件中参数不能是多个,对个多个参数需要封装用map
* @param start
* @param size
* @return
*/
public List<Student> findAllWithFy(String name,int start,int size){
SqlSession sqlSession=null;
try{
sqlSession = MybatisUtil.getSqlSession(); Map<String,Object> map = new LinkedHashMap<String,Object>();
map.put("pstart",start);
map.put("psize",size);
map.put("pname", "%"+name+"%");
return sqlSession.selectList(Student.class.getName()+".findAllByNameWithFy", map);
}catch(Exception e){
e.printStackTrace();
sqlSession.rollback();
throw new RuntimeException();
}finally{
MybatisUtil.closeSqlSession();
}
} public static void main(String[] args) throws Exception{
StudentDao dao = new StudentDao(); //for(int i=1;i<=10;i++){
// dao.add(new Student(i,"哈哈",7000D));
//} System.out.println("--------------------第一页");
List<Student> studentList1=dao.findAllWithFy("xiao",, ); //List<Student> studentList1 = dao.findAllByNameWithFy("哈",0,3);
for(Student s : studentList1){
System.out.println(s.getId()+":"+s.getName()+":"+s.getSal());
}
//System.out.println("--------------------第二页");
//List<Student> studentList2 = dao.findAllByNameWithFy("哈",3,3);
//for(Student s : studentList2){
// System.out.println(s.getId()+":"+s.getName()+":"+s.getSal());
//}
//System.out.println("--------------------第三页");
//List<Student> studentList3 = dao.findAllByNameWithFy("哈",6,3);
//for(Student s : studentList3){
// System.out.println(s.getId()+":"+s.getName()+":"+s.getSal());
//} }
}
<?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="app10.Student"> <resultMap type="app10.Student" id="studentMap">
<id property="id" column="id"/>
<result property="name" column="name"/>
<result property="sal" column="sal"/>
</resultMap> <insert id="add" parameterType="app10.Student">
insert into students(id,name,sal) values(#{id},#{name},#{sal})
</insert>
<select id="findAllWithFy" parameterType="map" resultMap="studentMap">
select id,name,sal from students limit #{pstart},#{psize}
</select>
<select id="findAllByNameWithFy" parameterType="map" resultMap="studentMap">
select id,name,sal from students where name like #{pname} limit #{pstart},#{psize}
</select>
</mapper>
9。动态SQL操作
1)动态查询:select id,name,sal from students where 1=1 and name=? and sal=?
<where>
<if test="pid!=null">
and id=#{pid}
</if>
<if test="pname!=null">
and name=#{pname}
</if>
<if test="psal=null">
and sal=#{psal}
</if>
</where>
StudentMapper.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"> <mapper namespace="app11.Student"> <resultMap type="app11.Student" id="studentMap">
<id property="id" column="id"/>
<result property="name" column="name"/>
<result property="sal" column="sal"/>
</resultMap> <select id="findAll" parameterType="map" resultMap="studentMap">
select * from students
<where>
<if test="pid!=null">
and id=#{pid}
</if>
<if test="pname!=null">
and name=#{pname}
</if>
<if test="psal=null">
and sal=#{psal}
</if>
</where>
</select> </mapper>
StudentDao.java
package app11; import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map; import org.apache.ibatis.session.SqlSession; import util.MybatisUtil; /**
* 持久层
* @author AdminTC
*/
public class StudentDao {
/**
* 有条件的查询所有学生
*/
public List<Student> findAll(Integer id,String name,Double sal) throws Exception{
SqlSession sqlSession = null;
try{
sqlSession = MybatisUtil.getSqlSession(); Map<String,Object> map = new LinkedHashMap<String,Object>();
map.put("pid",id);
map.put("pname",name);
map.put("psal",sal); return sqlSession.selectList(Student.class.getName()+".findAll",map);
}catch(Exception e){
e.printStackTrace();
throw e;
}finally{
MybatisUtil.closeSqlSession();
}
} public static void main(String[] args) throws Exception{
StudentDao dao = new StudentDao();
List<Student> studentList = dao.findAll(,null,null);
for(Student s : studentList){
System.out.println(s.getId()+":"+s.getName()+":"+s.getSal());
}
}
}
2)动态更新:update students set name=?,sal=? where id=?
StudentDao.java
package app12; import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map; import org.apache.ibatis.session.SqlSession; import util.MybatisUtil; /**
* 持久层
* @author AdminTC
*/
public class StudentDao {
/**
* 有条件更新学生
*/
public void dynaUpdate(Integer id,String name,Double sal) throws Exception{
SqlSession sqlSession = null;
try{
sqlSession = MybatisUtil.getSqlSession(); Map<String,Object> map = new HashMap<String, Object>();
map.put("pid",id);
map.put("pname",name);
map.put("psal",sal);
sqlSession.update("studentNamespace.dynaUpdate",map);
sqlSession.commit();
}catch(Exception e){
e.printStackTrace();
sqlSession.rollback();
throw e;
}finally{
MybatisUtil.closeSqlSession();
}
} public static void main(String[] args) throws Exception{
StudentDao dao = new StudentDao();
//关注SQL的变化
//dao.dynaUpdate(1,null,9000D);//update students set sal=? where id=?
//dao.dynaUpdate(1,"笨笨",null);//update students set name=? where id=?
dao.dynaUpdate(,"笨笨",10000D);//update students set name=? and sal=? where id=?
}
}
StudentMapper.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"> <mapper namespace="studentNamespace"> <resultMap type="app12.Student" id="studentMap">
<id property="id" column="id"/>
<result property="name" column="name"/>
<result property="sal" column="sal"/>
</resultMap> <!-- set标签自动判断哪个是最后一个字段,会自动去掉最后一个,号 -->
<update id="dynaUpdate" parameterType="map">
update students
<set>
<if test="pname!=null">
students_name = #{pname},
</if>
<if test="psal!=null">
students_sal = #{psal},
</if>
</set>
where students_id = #{pid}
</update> </mapper>
3)动态删除
delete from students where id in (1,3,5,7)
select id,name,sal from students where id in (2,4,6,8)
StudentDao.java
package app13; import java.util.ArrayList;
import java.util.List; import org.apache.ibatis.session.SqlSession; import app13.StudentDao; import util.MybatisUtil; /**
* 持久层
* @author AdminTC
*/
public class StudentDao {
/**
* 根据ID批量删除学生(数组版本)
* @param ids
* @throws Exception
*/
public void dynaDeleteArray(int ...ids)throws Exception{
SqlSession sqlSession=null;
try{
sqlSession=MybatisUtil.getSqlSession();
sqlSession.delete(Student.class.getName()+".dynaDeleteArray",ids);
sqlSession.commit();
}catch (Exception e) {
e.printStackTrace();
sqlSession.rollback();
throw new RuntimeException();
}finally{
MybatisUtil.closeSqlSession();
}
} public void dynaDeleteList(List<Integer> ids)throws Exception{
SqlSession sqlSession = null;
try{
sqlSession = MybatisUtil.getSqlSession();
sqlSession.delete("studentNamespace.dynaDeleteList",ids);
sqlSession.commit();
}catch(Exception e){
e.printStackTrace();
sqlSession.rollback();
throw e;
}finally{
MybatisUtil.closeSqlSession();
}
} public static void main(String[] args) throws Exception{
StudentDao dao = new StudentDao();
dao.dynaDeleteArray(,); //List<Integer> ids = new ArrayList<Integer>();
//ids.add(6);
//ids.add(8);
//ids.add(9);
//dao.dynaDeleteList(ids);
}
}
StudentMapper.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"> <mapper namespace="app13.Student"> <resultMap type="app13.Student" id="studentMap">
<id property="id" column="id"/>
<result property="name" column="name"/>
<result property="sal" column="sal"/>
</resultMap> <delete id="dynaDeleteArray">
delete from students where id in
<!-- foreach用于迭代数组元素
open表示开始符号
close表示结束符合
separator表示元素间的分隔符
item表示迭代的数组,属性值可以任意,但提倡与方法的数组名相同
#{ids}表示数组中的每个元素值
-->
<foreach collection="array" open="(" close=")" separator="," item="ids">
#{ids}
</foreach>
</delete> <delete id="dynaDeleteList">
delete from students where id in
<foreach collection="list" open="(" close=")" separator="," item="ids">
#{ids}
</foreach>
</delete>
</mapper>
4)动态插入:insert into student(id,name,sal) values(?,?,?)
StudentMapper.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"> <mapper namespace="studentNamespace"> <resultMap type="app14.Student" id="studentMap">
<id property="id" column="id"/>
<result property="name" column="name"/>
<result property="sal" column="sal"/>
</resultMap> <!-- 定义sql片段 字段名,id属性值任意写-->
<sql id="key">
<trim suffixOverrides=",">
<if test="id!=null">
id,
</if>
<if test="name!=null">
name,
</if>
<if test="sal!=null">
sal,
</if>
</trim> </sql>
<!-- 定义sql片段 ? -->
<sql id="value">
<!-- 去掉最后一个, -->
<trim suffixOverrides=",">
<if test="id!=null">
#{},
</if>
<if test="name!=null">
#{},
</if>
<if test="sal!=null">
#{},
</if>
</trim> </sql> <insert id="dynaInsert" parameterType="day14.Student">
insert into students(<include refid="key"></include>) values(<include refid="value"></include>)
</insert> </mapper>
StudentDao.java
package app14; import java.util.ArrayList;
import java.util.List; import org.apache.ibatis.session.SqlSession; import app13.Student; import util.MybatisUtil; /**
* 持久层
* @author AdminTC
*/
public class StudentDao {
/**
* 动态插入学生
*/
public void dynaInsert(Student student) throws Exception{
SqlSession sqlSession = null;
try{
sqlSession = MybatisUtil.getSqlSession();
sqlSession.insert("studentNamespace.dynaInsert",student);
sqlSession.commit();
}catch(Exception e){
e.printStackTrace();
sqlSession.rollback();
throw e;
}finally{
//MybatisUtil.closeSqlSession();
}
} public static void main(String[] args) throws Exception{
StudentDao dao = new StudentDao();
//dao.dynaInsert(new Student(1,"哈哈",7000D));//insert into 表名(*,*,*) values(?,?,?)
dao.dynaInsert(new Student(,"哈哈",null));//insert into 表名(*,*) values(?,?)
//dao.dynaInsert(new Student(3,null,7000D));//insert into 表名(*,*) values(?,?)
//dao.dynaInsert(new Student(4,null,null));//insert into 表名(*) values(?)
}
}
java深入探究16-mybatis的更多相关文章
- 疑惑的 java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransaction.getTimeout()L
在MAVEN项目里面,在整合spring和mybatis在执行数据库操作的时候报出了: java.lang.AbstractMethodError: org.mybatis.spring.transa ...
- Java 集合系列 16 HashSet
java 集合系列目录: Java 集合系列 01 总体框架 Java 集合系列 02 Collection架构 Java 集合系列 03 ArrayList详细介绍(源码解析)和使用示例 Java ...
- Mybatis异常:java.lang.ClassNotFoundException: org.mybatis.spring.SqlSessionFactoryBean
问题描述: 一月 15, 2014 3:43:13 下午 org.springframework.context.support.AbstractApplicationContext prepareR ...
- Cause: java. lang.InstantiationException: tk.mybatis.mapper.provider.base.BaseInsertProvider
相信现在Java Web开发都是用的mybatis吧,而用到mybatis很多人都不会错过通用mapper吧! (纯属瞎扯淡...qwq). 如我上一篇博客所写,目前公司新项目,使用了通用mapper ...
- java.lang.NoSuchMethodException: tk.mybatis.mapper.provider.SpecialProvider.<init>()
Caused by: org.apache.ibatis.builder.BuilderException: Error invoking SqlProvider method (tk.mybatis ...
- java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransaction.getTimeout()Ljava/lang/Integer; at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.jav
在整合spring和mybatis在执行数据库操作的时候报出了: java.lang.AbstractMethodError: org.mybatis.spring.transaction.Sprin ...
- 2018面向对象程序设计(Java)第16周学习指导及要求
2018面向对象程序设计(Java)第16周学习指导及要求(2018.12.13-2018.12.16) 学习目标 (1) 掌握线程概念: (2) 掌握线程创建的两种技术: (3) 理解和掌握线程 ...
- Java字符串转16 进制工具类Hex.java
Java字符串转16 进制工具类Hex.java 学习了:https://blog.csdn.net/jia635/article/details/56678086 package com.strin ...
- 【Java】-NO.16.EBook.4.Java.1.011-【疯狂Java讲义第3版 李刚】- AWT
1.0.0 Summary Tittle:[Java]-NO.16.EBook.4.Java.1.011-[疯狂Java讲义第3版 李刚]- AWT Style:EBook Series:Java ...
- 【Java】-NO.16.EBook.4.Java.1.012-【疯狂Java讲义第3版 李刚】- Swing
1.0.0 Summary Tittle:[Java]-NO.16.EBook.4.Java.1.011-[疯狂Java讲义第3版 李刚]- Swing Style:EBook Series:Jav ...
随机推荐
- CodeIgniter框架——源码分析之Config.php
CI框架的配置信息被存储在$config数组中,我们可以添加自己的配置信息或配置文件到$config中: $this->config->load('filename'); //加载配置文件 ...
- 【BZOJ2064】分裂 状压DP
[BZOJ2064]分裂 Description 背景:和久必分,分久必和...题目描述:中国历史上上分分和和次数非常多..通读中国历史的WJMZBMR表示毫无压力.同时经常搞OI的他把这个变成了一个 ...
- Json工具类库之Gson实战笔记
日常接口的数据传输通常使用xml或者json来传递数据,xml较庞大但是描述数据能力十分出众,json数据结构较小而且支持ajax传输,xml在数据传输和解析资源占用都比较逊色于json.因此日常的接 ...
- 巨蟒django之权限8:排序&&菜单展开权限归属
1.权限控制的流程+表结构 内容回顾: wsgi:socket进行收发消息 中间件:(超级重点的面试题)在全局范围内控制django的输入和输出的一个钩子,处理输入和输出说白了就是处理请求和响应req ...
- Jquery Ajax Json ashx 实现前后台数据传输
经过一个多星期的研究,各种查找资料终于自己实现了Jquery Ajax Json ashx 的前后台数据交流功能 首先一点,Ajax只能对应一个ashx文件,多余两个,如果打开异步传输的async: ...
- UI中各种手势的使用点击,捏合,清扫,旋转,平移,边缘移动,长按
#import "RootViewController.h" @interface RootViewController (){ UIImageView *imageView ...
- 数据性能调校——查看最耗资源的各种SQL
从计划高速缓存中清除查询计划 DBCC FREEPROCCACHE 清除缓存中的过程 DBCC DROPCLEANBUFFERS清除内存中的数据 SELECT DB_ID('你的数据库名') tota ...
- 基于twemproxy的redis集群部署
一.系统及软件版本 操作系统:CentOS Linux release 7.3.1611 (Core) 内核版本:3.10.0-514.el7.x86_64 redis版本:3.2.8 twempro ...
- 算法题14 小Q歌单,牛客网,腾讯笔试题
算法题14 小Q歌单,牛客网,腾讯笔试题 题目: 小Q有X首长度为A的不同的歌和Y首长度为B的不同的歌,现在小Q想用这些歌组成一个总长度正好为K的歌单,每首歌最多只能在歌单中出现一次,在不考虑歌单内歌 ...
- LeetCode:螺旋矩阵【54】
LeetCode:螺旋矩阵[54] 题目描述 给定一个包含 m x n 个元素的矩阵(m 行, n 列),请按照顺时针螺旋顺序,返回矩阵中的所有元素. 示例 1: 输入: [ [ 1, 2, 3 ], ...