TkMybatis 笔记

TkMybatis 笔记1 通用 TkMybatis 笔记 1 引入 1 1 作用替我们生成常用增删改查操作的 SQL 语句 1 2 代码官方发布地址 https gitee com freehttps gitee com free Mapper wikis 1 1 java parent 1 integration1 3 前置知识 MyBatisSprin 快速入门 2 1 创建测试数据 SQ

https://gitee.com/free https://gitee.com/free/Mapper/wikis/1.1-java?parent=1.integration
CREATE TABLE `tabple_emp` ( `emp_id` int NOT NULL AUTO_INCREMENT , `emp_name` varchar(500) NULL , `emp_salary` double(15,5) NULL , `emp_age` int NULL , PRIMARY KEY (`emp_id`) ); INSERT INTO `tabple_emp` (`emp_name`, `emp_salary`, `emp_age`) VALUES ('tom', '1254.37', '27'); INSERT INTO `tabple_emp` (`emp_name`, `emp_salary`, `emp_age`) VALUES ('jerry', '6635.42', '38'); INSERT INTO `tabple_emp` (`emp_name`, `emp_salary`, `emp_age`) VALUES ('bob', '5560.11', '40'); INSERT INTO `tabple_emp` (`emp_name`, `emp_salary`, `emp_age`) VALUES ('kate', '2209.11', '22'); INSERT INTO `tabple_emp` (`emp_name`, `emp_salary`, `emp_age`) VALUES ('justin', '4203.15', '30');
public class Employee { private Integer empId; private String empName; private Double empSalary; private Integer empAge; public Employee() { } public Employee(Integer empId, String empName, Double empSalary, Integer empAge) { super(); this.empId = empId; this.empName = empName; this.empSalary = empSalary; this.empAge = empAge; } @Override public String toString() { return "Employee [empId=" + empId + ", empName=" + empName + ", empSalary=" + empSalary + ", empAge=" + empAge + "]"; } public Integer getEmpId() { return empId; } public void setEmpId(Integer empId) { this.empId = empId; } public String getEmpName() { return empName; } public void setEmpName(String empName) { this.empName = empName; } public Double getEmpSalary() { return empSalary; } public void setEmpSalary(Double empSalary) { this.empSalary = empSalary; } public Integer getEmpAge() { return empAge; } public void setEmpAge(Integer empAge) { this.empAge = empAge; } }
 
   
   
     tk.mybatis 
    
   
     mapper 
    
   
     4.0.0-beta3 
    
  
 
   
   
   
   
    
  
/ * 具体操作数据库的Mapper 接口, 需要继承通用Mapper 提供的核心接口: Mapper 
  
    * 泛型类型就是实体类的类型 * @author Lenovo */ public interface EmployeeMapper extends Mapper 
   
     { } 
    
  
SELECT emp_id,emp_name,emp_salary_apple,emp_age FROM tabple_emp WHERE emp_id = ? AND emp_name = ? AND emp_salary_apple = ? AND emp_age = ?
@Transient private String otherThings; //非数据库表中字段
//目标:WHERE (emp_salary>? AND emp_age 
  ?) //1.创建Example 对象 Example example = new Example(Employee.class); //* //i.设置排序信息 example.orderBy("empSalary").asc().orderBy("empAge").desc(); //ii.设置“去重” example.setDistinct(true); //iii.设置select 字段 example.selectProperties("empName","empSalary"); //* //2.通过Example 对象创建Criteria 对象 Criteria criteria01 = example.createCriteria(); Criteria criteria02 = example.createCriteria(); //3.在两个Criteria 对象中分别设置查询条件 //property 参数:实体类的属性名 //value 参数:实体类的属性值 criteria01.andGreaterThan("empSalary", 3000) .andLessThan("empAge", 25); criteria02.andLessThan("empSalary", 5000) .andGreaterThan("empAge", 30); //4.使用OR 关键词组装两个Criteria 对象 example.or(criteria02); //5.执行查询 List 
  
    empList = employeeService.getEmpListByExample(example); for (Employee employee : empList) { System.out.println(employee); } 
  
 
   
    
    
    
      mappers=com.atguigu.mapper.mine_mappers.MyMapper 
     
    
  
tk.mybatis.mapper.additional.insert.InsertListMapper 
  
    tk.mybatis.mapper.additional.insert.InsertListProvider 
  
UPDATE tabple_emp SET emp_name=?,emp_age=?,emp_salary=? where emp_id=? ; UPDATE tabple_emp SET emp_name=?,emp_age=?,emp_salary=? where emp_id=? ; UPDATE tabple_emp SET emp_name=?,emp_age=?,emp_salary=? where emp_id=? ; ……
 
  
    UPDATE tabple_emp SET emp_name=#{record.empName}, emp_age=#{record.empAge}, emp_salary=#{record.empSalary} where emp_id=#{record.empId} 
  
 
   
    
  
@CacheNamespace public interface EmployeeMapper extends MyMapper 
  
    { } 
  
public interface TypeHandler 
  
    { //将parameter 设置到ps 对象中,位置是i //在这个方法中将parameter 转换为字符串 void setParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException; //根据列名从ResultSet 中获取数据,通常是字符串形式 //将字符串还原为Java 对象,以T 类型返回 T getResult(ResultSet rs, String columnName) throws SQLException; T getResult(ResultSet rs, int columnIndex) throws SQLException; T getResult(CallableStatement cs, int columnIndex) throws SQLException; } 10.2.3 继承树 10.2.4 BaseTypeHandler 类中的抽象方法说明 //将parameter 对象转换为字符串存入到ps 对象的i 位置 public abstract void setNonNullParameter( PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException; //从结果集中获取数据库对应查询结果 //将字符串还原为原始的T 类型对象 public abstract T getNullableResult( ResultSet rs, String columnName) throws SQLException; public abstract T getNullableResult( ResultSet rs, int columnIndex) throws SQLException; public abstract T getNullableResult( CallableStatement cs, int columnIndex) throws SQLException; 10.2.5 自定义类型转换器类 public class AddressTypeHandler extends BaseTypeHandler 
  
{ ……
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/207223.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月19日 下午2:18
下一篇 2026年3月19日 下午2:18


相关推荐

  • 舆情分析系统技术解决方案及作用论文_网络舆情解决方案

    舆情分析系统技术解决方案及作用论文_网络舆情解决方案网络舆情分析工作的开展最先需要做好的就是网络舆情的搜集工作,由于互联网信息内容庞杂多样,舆情信息搜集起来困难,所以要进行舆情分析更是难上加难。但若舆情信息收集的不全,就极易导致舆情分析不正确。那么,到底舆情分析工作要怎么做呢?针对此问题,提供了以下舆情分析系统技术解决方案,供各位参考。在了解方案的前,先来说说为什么要采用舆情分析系统进行监测分析。一、使用舆情分析系统进行监测分析的意义网络信息化时代,信息数据量庞大,若一味采用人工进行舆情信息分析,容易出现收集的舆情不全、舆情分析不正确等问题。而通过利用

    2026年1月30日
    6
  • linux系添加路由,Linux添加路由的两种方法「建议收藏」

    linux系添加路由,Linux添加路由的两种方法「建议收藏」Linux中增加软路由的两种方法第一种:routeadd-net172.16.6.0netmask255.255.255.0gw172.16.2.254deveth0/*增加一条网络172.16.6.0/24经过172.16.2.254eth0*//*-net增加网络-host增加主机netmask子网掩码gw网关dev装置,设备,这里是你的网卡名*/ro…

    2022年10月5日
    5
  • 二分法排序C++

    二分法排序C++include includevoidT intarray intn nbsp nbsp nbsp nbsp nbsp nbsp intleft right num nbsp nbsp nbsp nbsp nbsp nbsp intmiddle j i nbsp nbsp nbsp nbsp nbsp nbsp for i 1 i nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp left 0 准备 nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp right i 1

    2026年3月18日
    2
  • log4cpp学习

    log4cpp学习1、linux下log4cpp的下载安装配置http://log4cpp.sourceforge.net/官方网站有下载地址,安装过程配置选项及测试用例。将下载好的tar包解压到/usr/local/下运行./configure(如有需要添加相关配置选项),使用make编译,使用makecheck进行检测,使用makeinstall安装,使用之前的相关命令安装好之后在/usr

    2022年7月13日
    18
  • 语义分割步骤_实时语义分割

    语义分割步骤_实时语义分割 深度学习发展到现在,各路大神都发展出了各种模型,这里就做个伸手党吧。在深度学习实现过程中最重要的最花时间的我觉得应该是数据预处理与后处理,会极大影响最后效果,至于模型,感觉像是拼乐高积木,一个模块一个模块地叠加,拼成最适合自己的模型。1数据预处理1.1图像切割 一般而言,训练集会是一整张大图,所以需要自己切割成小图训练,可以做切割,也可以在训练时划窗读取,最好先做切割,可以检查数据。切…

    2022年8月21日
    10
  • iframe属性allowTransparency

    iframe属性allowTransparencyIE5 5 开始支持浮动框架的内容透明 如果想要为浮动框架定义透明内容 则必须满足下列条件 1 与 iframe 元素一起使用的 allowTranspa 标签属性必须设置为 true 2 在 iframe 内容源文档 background color 或 body 元素的 bgColor 标签属性必须设置为 transparent 具体步骤 1 包含框架页的代码

    2026年3月18日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号