随笔分类 - Mybatis
摘要:整合Mybatis步骤: 1.导入相关jar包: junit mybatis mysql数据库 spring相关 aop织入 mybatis-spring <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</
阅读全文
摘要:14.1一级缓存 默认情况下,只有一级缓存开启。(SqlSession级别的缓存,也称为本地缓存)只在一次SqlSession中有效,也就是拿到连接到关闭连接这个区间。 测试步骤 1.开启日志 2.测试在一个Session中查询两次相同的记录 @Testpublic void test(){ Sql
阅读全文
摘要:根据不同的条件生成不同的sql语句 搭建环境 CREATE TABLE `blog`(`id` VARCHAR(50) NOT NULL COMMENT '博客id',`title` VARCHAR(100) NOT NULL COMMENT '博客标题',`author` VARCHAR(30)
阅读全文
摘要:1.环境搭建,和多对一一样 实体类 package com.yl.pojo;import lombok.Data;@Datapublic class Student { private int id; private String name; private int tid;} package
阅读全文
摘要:测试环境搭建 1.新建实体类 2.建立Mapper接口 3.建立Mapper.xml文件 4.在核心配置文件中绑定注册Mapper接口或者文件 5.测试 按照查询嵌套处理 实体类 @Datapublic class Student { private int id; private String n
阅读全文
摘要:Never write another getter or equals method again, with one annotation your class has a fully featured builder, Automate your logging variables, and m
阅读全文
摘要:1.注解在接口上实现 @Select("select * from user")List<User> getUsers(); 2.在核心配置文件中绑定接口 <mappers> <mapper class="com.yl.dao.UserMapper"/></mappers> 3.测试 本质:反射机制
阅读全文
摘要:8.1 使用Limit分页 1.接口 //分页List<User> getUserByLimit(Map<String,Integer> map); 2.Mapper.xml <select id="getUserByLimit" parameterType="map" resultMap="Use
阅读全文
摘要:7.1日志工厂 如果一个数据库操作出现了异常,我们需要排错,日志就是最好的助手 在Mybatis中具体使用哪一个日志实现,在设置中设定 STDOUT_LOGGING 标准日志输出 7.2LOG4J 导入依赖 <dependency> <groupId>log4j</groupId> <artifac
阅读全文
摘要:private int id;private String name;private String password;//pwd改为password 测试后pwd变为null 解决方法: 起别名 <select id="getUserById" parameterType="int" resultT
阅读全文
摘要:1.核心配置文件 mybatis-config.xml 2.环境配置 Mybaits可以配置成适应多种环境 尽可能配置多个环境,当每个SqlSessionFactory实例只能选择一种环境 Mybatis的事务管理器JDBC和MANGED,默认是JDBC,连接池:POOLED 3.属性 可以通过pr
阅读全文
摘要:假设我们的实体类或者数据库中的表,字段或者参数过多,我们考虑使用map,如果要用实体类传递,则必须写全所有字段 int addUser2(Map<String,Object> map); <insert id="addUser2" parameterType="map"> insert into m
阅读全文
摘要:1.namespace namespace中的包名要和dao/mapper接口的包名一直 2.select id:就是对应的namespace中的方法名 resultType:Sql语句执行的返回值 parameterType:传递参数的类型 1.编写接口 //查询全部用户List<User> ge
阅读全文
摘要:思路:搭建环境->导入Mybatis->编写代码->测试 2.搭建环境 2.1搭建数据库 2.2新建项目 1.新建一个普通maven项目 2.删除src目录 3.导入maven依赖 <dependencies> <!--mysql驱动--> <dependency> <groupId>mysql</
阅读全文
浙公网安备 33010602011771号