1、
2、添加mybatis的依赖
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.2</version>
</dependency>
3、写配置
spring.datasource.username=root
spring.datasource.password=045800
spring.datasource.url=jdbc:mysql://localhost:3306/vue3Login?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
mybatis.type-aliases-package=com.example.vue3login.pojo
mybatis.mapper-locations=classpath:mappers/*.xml
4、文件结构如下
5、对应文件添加对应的注解
xml文件书写
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.vue3login.mapper.UserMapper">
<resultMap id="DingDingUser" type="User">
<id property="userId" column="user_id" />
<result property="userName" column="user_name" />
<result property="userPwd" column="user_pwd" />
</resultMap>
<select id="selectUser" resultMap="DingDingUser">
select * from user
</select>
</mapper>
注意namespace, resultMap="DingDingUser"
<resultMap id="DingDingUser" type="User">