MyBatis
CodeBoyWLC
技术+原理爱好者
展开
-
【MyBatis】typeHandler处理枚举
CREATE TABLE tbl_employee ( id INT (11) PRIMARY KEY AUTO_INCREMENT, last_name VARCHAR (255), gender CHAR (1), email VARCHAR (255), empStatus VARCHAR(11));public class Employee { private Integer id; private String lastName; private String emai原创 2021-05-03 09:25:48 · 140 阅读 · 1 评论 -
【MyBatis】利用执行器实现,批量操作
目的:避免写非常长的SQL语句public class Employee { private Integer id; private String lastName; private String email; private String gender; public Employee(String lastName, String email, String gender) { super(); this.lastName = lastName; this.email原创 2021-04-30 21:00:39 · 194 阅读 · 1 评论 -
【MyBatis】分页插件PageHelper
public class Employee { private Integer id; private String lastName; private String email; private String gender; public Employee(String lastName, String email, String gender) { super(); this.lastName = lastName; this.email = email; this原创 2021-04-30 20:54:49 · 94 阅读 · 1 评论 -
【MyBatis】利用插件:执行SQL前改造
public class Employee { private Integer id; private String last_name; private String email; private String gender; @Override public String toString() { return "Employee [id=" + id + ", last_name=" + last_name + ", email=" + email + ", gender=" +原创 2021-04-30 20:52:14 · 326 阅读 · 1 评论 -
【MyBatis】插件
public class Employee { private Integer id; private String last_name; private String email; private String gender; @Override public String toString() { return "Employee [id=" + id + ", last_name=" + last_name + ", email=" + email + ", gender=" +原创 2021-04-30 20:41:05 · 43 阅读 · 1 评论 -
【MyBatis】逆向工程
public class MyBatisTest { public SqlSessionFactory getSqlSessionFactory() throws IOException { String resource = "mybatis-config.xml"; InputStream inputStream = Resources.getResourceAsStream(resource); return new SqlSessionFactoryBuilder().build(in原创 2021-04-30 20:37:35 · 49 阅读 · 1 评论 -
【MyBatis】缓存:让一级缓存失效
public interface EmployeeMapper { public Employee getEmpById(Integer id); public Long addEmp(Employee employee);}public class MyBatisTest { public SqlSessionFactory getSqlSessionFactory() throws IOException { String resource = "mybatis-config.xm原创 2021-04-30 20:37:57 · 198 阅读 · 0 评论 -
【MyBatis】动态SQL==><bind>
public interface EmployeeMapperDynamicSQL { public List<Employee> getEmpsTestInnerParameter(Employee employee);}public class MyBatisTest { public SqlSessionFactory getSqlSessionFactory() throws IOException { String resource = "mybatis-con原创 2021-04-29 14:22:56 · 51 阅读 · 0 评论 -
【MyBatis】动态SQL==><foreach>Oracle实现批量插入
public interface EmployeeMapperDynamicSQL { public void addEmps(@Param("emps")List<Employee> emps);}public class MyBatisTest { public SqlSessionFactory getSqlSessionFactory() throws IOException { String resource = "mybatis-config.xml";原创 2021-04-29 14:21:14 · 229 阅读 · 0 评论 -
【MyBatis】动态SQL==><foreach>实现批量插入
public interface EmployeeMapperDynamicSQL { public void addEmps(@Param("emps")List<Employee> emps);} public class MyBatisTest { public SqlSessionFactory getSqlSessionFactory() throws IOException { String resource = "mybatis-config.xml";原创 2021-04-29 14:19:37 · 93 阅读 · 0 评论 -
【MyBatis】动态SQL==><foreach>实现in集合
public interface EmployeeMapperDynamicSQL { public List<Employee> getEmpsByConditionForeach(List<Integer> ids);}public class MyBatisTest { public SqlSessionFactory getSqlSessionFactory() throws IOException { String resource = "mybatis原创 2021-04-29 14:18:16 · 110 阅读 · 0 评论 -
【MyBatis】动态SQL==><set>
public interface EmployeeMapperDynamicSQL { public void updateEmp(Employee employee);}public class MyBatisTest { public SqlSessionFactory getSqlSessionFactory() throws IOException { String resource = "mybatis-config.xml"; InputStream inputStrea原创 2021-04-29 14:17:04 · 68 阅读 · 0 评论 -
【MyBatis】动态SQL==><trim>
public interface EmployeeMapperDynamicSQL { public List<Employee> getEmpsByConditionTrim(Employee employee);}public class MyBatisTest { public SqlSessionFactory getSqlSessionFactory() throws IOException { String resource = "mybatis-config.x原创 2021-04-29 14:15:53 · 66 阅读 · 0 评论 -
【MyBatis】动态SQL==><choose>
public class Employee { private Integer id; private String lastName; private String email; private String gender; public Employee() {public interface EmployeeMapperDynamicSQL { public List<Employee> getEmpsByConditionChoose(Employee employe原创 2021-04-29 14:14:21 · 76 阅读 · 0 评论 -
【MyBatis】动态SQL==><if>与<where>
public class Employee { private Integer id; private String lastName; private String email; private String gender; }public interface EmployeeMapperDynamicSQL { //携带了哪个字段查询条件就带上这个字段的值 public List<Employee> getEmpsByConditionIf(Employee emplo原创 2021-04-29 14:12:45 · 117 阅读 · 0 评论 -
【MyBatis】<typeAliases> --(别名处理器 )
为Java类型起个短名,避免resultType引用javabean全限定类名public class Employee { private Integer id; private String lastName; private String email; private String gender;}public interface EmployeeMapper { public Employee getEmpById(Integer id);}public class原创 2021-04-29 14:09:02 · 55 阅读 · 0 评论 -
【MyBatis】DB运行环境切换
CREATE TABLE tbl_employee( //mysql内id INT(11) PRIMARY KEY AUTO_INCREMENT,last_name VARCHAR(255),gender CHAR(1),email VARCHAR(255));CREATE TABLE employees( //Oracle内EMPLOYEE_ID INT PRIMARY KEY,LAST_NAME VARCHAR2(255),EMAIL VARCHAR2(255)原创 2021-04-29 14:08:46 · 118 阅读 · 0 评论 -
【MyBatis】javabean属性名与DB字段名不一致解决:开启mapUnderscoreToCamelCase
CREATE TABLE tbl_employee(id INT(11) PRIMARY KEY AUTO_INCREMENT,last_name VARCHAR(255),gender CHAR(1),email VARCHAR(255));public class Employee { private Integer id; private String lastName; //与DB内last_name不一致 private String email; private S.原创 2021-04-28 13:32:40 · 76 阅读 · 0 评论 -
【MyBatis】<properties>--把数据源配置,从mybatis.xml中单独抽取出
package com.atguigu.mybatis.bean;public class Employee { private Integer id; private String last_name; private String email; private String gender;}package com.atguigu.mybatis.dao;import com.atguigu.mybatis.bean.Employee;public interface Em.原创 2021-04-28 13:15:22 · 145 阅读 · 0 评论 -
【MyBatis】创建Maven项目型MyBatis
①Eclipse 中打开 【File】----【New】选择【Other】②选择【 Maven】 下的 【Maven Project】,点击【Next 】③选择【Create a simple project (skip archetype selection )】前的复选框,点击【Next】④输入 Group Id(tk.mybatis )、 Artifact Id (simpleMaven)、 Version (0.0.1-SNAPSHOT), 点击 【Finish】Maven创建完成,如图。原创 2021-04-28 13:13:36 · 58 阅读 · 0 评论 -
【MyBatis】第1个MyBatis,创建Java项目之MyBatis
CREATE TABLE tbl_employee(id INT(11) PRIMARY KEY AUTO_INCREMENT,last_name VARCHAR(255),gender CHAR(1),email VARCHAR(255));–实体类package com.atguigu.mybatis.bean;public class Employee { //对应DB内那个表:来完成映射 private Integer id; private String la...原创 2021-04-28 13:09:30 · 129 阅读 · 0 评论