当前位置: 首页 > news >正文

【mybatis-plus问题集锦系列】mybatis使用xml配置文件实现数据的基础增删改查

简单的数据查询,我们可以在mapper接口里面去实现,但是如果是复杂的查询,我们就可以使用xml配置文件去做,
官网链接xml配置文件
在这里插入图片描述

实现效果

在这里插入图片描述

实现代码

  • 根据mapper接口的包结构,在resources包里面新建同名同结构的xml文件

    mapper接口文件

@Mapper
public interface EmpMapper2 {public List<Emp> getAllEmpList();
}
  • 在这里插入图片描述
    在这里插入图片描述
    resources里面对应的xml文件
    namespace对应的是mapper接口的全类名
    select里面的id对应的就是mapper接口里面的方法名
    resultType 单条记录封装的类型
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- mamper接口的全类名-->
<mapper namespace="com.gaofeng.mapper.EmpMapper2">
<!-- resultType 单条记录封装的类型--><select id="getAllEmpList" resultType="com.gaofeng.pojo.Emp">select * from tb_emp</select>
</mapper>
  • 查询测试
@SpringBootTest
public class mybatisTestxml {@Autowiredprivate EmpMapper2 empMapper2;@Testpublic void getEmpList(){List<Emp> allEmpList = empMapper2.getAllEmpList();System.out.println(allEmpList);}
}
  • 条件查询

EmpMapper2文件

public List<Emp> listEmp(String name,Short gender, LocalDate begin,LocalDate end);

xml文件配置

 <select id="listEmp" resultType="com.itheima.pojo.Emp">select * from tb_emp where name like concat('%',#{name},'%') and gender = #{gender}and entrydate between #{begin} and #{end} order by update_time desc;</select>

测试文件

    @Testpublic void testGetEmp(){List<Emp> empList = empMapper2.listEmp("张", (short) 1, LocalDate.of(2010, 1, 1), LocalDate.of(2020, 1, 1));System.out.println(empList);}

在这里插入图片描述
在这里插入图片描述

http://www.lryc.cn/news/515573.html

相关文章:

  • 投稿指南【NO.12_14】【极易投中】期刊投稿(毛纺科技)
  • 机器学习算法的分类
  • Linux操作系统下,挂ILA
  • HTML——26.像素单位
  • 【HTML】Day02
  • AI 自动化编程对编程教育的影响
  • Java100道面试题
  • 解密人工智能:如何改变我们的工作与生活
  • Linux postgresql-15部署文档
  • visual studio 安全模式
  • Pandas-timestamp和datetime64的区别
  • @MapperScan
  • SQL中聚类后字段数据串联字符串方法研究
  • 【嵌入式硬件】直流电机驱动相关
  • CSP初赛知识学习计划(第一天)
  • 【嵌入式硬件】嵌入式显示屏接口
  • 07-ArcGIS For JavaScript--隐藏参数qualitySettings(memory和lod控制)
  • QML自定义数值编辑框SpinBox样式
  • 【数据可视化-10】国防科技大学录取分数线可视化分析
  • 深入探索:将 Elasticsearch 与 Ruby 工具结合使用
  • Istio 补充 Kubernetes 的不足
  • 远程主机执行脚本1、无脚本内容外协。
  • Jmeter进阶篇(32)Jmeter 在 MySQL 数据库压测中的应用
  • Python脚本实现通过Vector VN1630A CAN盒子与ECU通信
  • Spring实现Logback日志模板设置动态参数
  • 内部类 --- (寄生的哲学)
  • Python深度学习GRU、LSTM 、BiLSTM-CNN神经网络空气质量指数AQI时间序列预测及机器学习分析|数据分享...
  • JSP基础
  • 基于Springboot +Vue 在线考试管理系统
  • Node.js 函数