日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

SpringBoot整合Mybatis(配置文件)

發布時間:2023/12/14 javascript 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SpringBoot整合Mybatis(配置文件) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、引入jar

<dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>1.3.3</version> </dependency>

二、創建JavaBean

public class Employee {private Integer id;private String lastName;private Integer gender;private String email;private Integer dId;public Integer getId() {return id;} ...

三、創建Mapper接口

public interface EmployeeMapper {public Employee getEmpById(Integer id);public void insertEmp(Employee employee); }

四、搭建XML文件配置

1)、結構:可自行定義

?2)、yml文件中指定mybatis全局配置文件和接口映射文件位置

mybatis:config-location: classpath:mybatis/mybatis-config.xmlmapper-locations: classpath:mybatis/mapper/*.xml

?3)、查看官網復制主配置文件模板修改如下

? 網址:http://www.mybatis.org/mybatis-3/

<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration><settings><setting name="mapUnderscoreToCamelCase" value="true"/></settings> </configuration>

?4)、查看官網復制接口映射文件模板修改如下

<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.zhq.springboot.mapper.EmployeeMapper"><!--查詢--><select id="getEmpById" resultType="com.zhq.springboot.bean.Employee">select * from employee where id=#{id}</select><!--插入--><insert id="insertEmp" >insert into employee(lastName,email,gender,d_id) values(#{lastName},#{email},#{gender},#{d_id})</insert> </mapper>

五、編寫接口測試

@GetMapping("emp/{id}")public Employee getEmp(@PathVariable("id") Integer id){Employee emp = employeeMapper.getEmpById(id);return emp;}

總結

以上是生活随笔為你收集整理的SpringBoot整合Mybatis(配置文件)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。