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

Mybatis配置文件(mybatis-config.xml)和Mapper映射文件(XXXMapper.xml)模板

配置文件

${dirver} ---> com.mysql.jdbc.Driver

${url} ---> jdbc:mysql://localhost:3306/数据库名

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""https://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration><environments default="development">
<!--配置数据源,即数据库信息--><environment id="development"><transactionManager type="JDBC"/><dataSource type="POOLED"><property name="driver" value="${driver}"/><property name="url" value="${url}"/><property name="username" value="${username}"/><property name="password" value="${password}"/></dataSource></environment></environments>
<!--引入映射文件,路径:src/main/resources/mapper/BlogMapper.xml--><mappers><mapper resource="mapper/BlogMapper.xml"/></mappers>
</configuration>

Mapper映射文件

mybatis面向接口编程,需要保持两个一致性:

(1)映射文件中的namespace(命名空间)和Mapper接口的全类名保持一致;

(2)映射文件中sql语句中的id需要和Mapper接口的方法名保持一致;

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.mybatis.example.BlogMapper"><select id="selectBlog" resultType="Blog">select * from Blog where id = #{id}</select>
</mapper>

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

相关文章:

  • 4. 条件查询
  • 【VIM】初步认识VIM-2
  • 《HelloGitHub》第 90 期
  • Apache Hudi初探(五)(与flink的结合)--Flink 中hudi clean操作
  • stream对list数据进行多字段去重
  • 一种基于体素的射线检测
  • 利用Docker安装Protostar
  • go基础语法10问
  • SpringCloud + SpringGateway 解决Get请求传参为特殊字符导致400无法通过网关转发的问题
  • vim基本操作
  • Drift plus penalty 漂移加惩罚Part1——介绍和工作原理
  • (四)动态阈值分割
  • jvm介绍
  • 数据结构与算法课后题-第三章(顺序队和链队)
  • SSM - Springboot - MyBatis-Plus 全栈体系(十六)
  • k8s--storageClass自动创建PV
  • 7.3 调用函数
  • 如果使用pprof来进行性能的观测和优化
  • 在移动固态硬盘上安装Ubuntu系统和ROS2
  • 【iptables 实战】02 iptables常用命令
  • webview_flutter
  • 【GESP考级C++】1级样题 闰年统计
  • CentOS密码重置
  • Tomcat Servlet
  • 国庆day2---select实现服务器并发
  • Grafana 开源了一款 eBPF 采集器 Beyla
  • 亲测可用国产GPT人工智能
  • 适配器模式详解和实现(设计模式 四)
  • IDEA的使用
  • CSS详细基础(二)文本样式