标签:add amp into pack tis cal test ESS 文件的
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.url=jdbc:mysql://localhost:3306/test?characterEncoding=utf-8&serverTimezone=UTC&useSSL=false
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
mybatis.type-aliases-package=com.pojo
mybatis.mapper-locations=classpath:mybatis/mapper/*.xml
@Mapper
@Repository
public interface UserMapper {
public static final int age = 111;
List<User> queryUserList();
User getUserById(int id);
int addUser(User user);
int update(User user);
int delete(int id);
}
<?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">
<!-- namespace:该mapper.xml映射文件的 唯一标识 -->
<mapper namespace="com.mapper.UserMapper">
<resultMap type="User" id="userResult">
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="age" column="age"/>
<result property="gender" column="gender"/>
</resultMap>
<resultMap id="user" type="user">
<id column="id" property="id"/>
<result column="id" property="id"/>
<result column="name" property="name"/>
<result column="age" property="age"/>
<result column="sex" property="sex"/>
<result column="birthday" property="birthday" javaType="java.sql.Date"/>
</resultMap>
<!-- 增加一条数据 -->
<insert id="addUser" parameterType="User">
INSERT INTO user
VALUES (null, #{name}, #{age}, #{gender})
</insert>
<!-- 删除一条数据 -->
<delete id="delete" parameterType="int">
DELETE
FROM user
WHERE id = #{id}
</delete>
<!-- 更新一条数据 -->
<update id="update" parameterType="User">
UPDATE user
SET name = #{name},
age = #{age},
gender = #{gender}
WHERE id = #{id}
</update>
<!-- 查询一条数据 -->
<select id="getUserById" resultMap="userResult" parameterType="int">
SELECT *
FROM user
WHERE id = #{id}
</select>
<!-- 查询从start位置开始的count条数据-->
<select id="queryUserList" resultMap="userResult">
SELECT *
FROM user
</select>
</mapper>
@RestController
public class UserController {
@Autowired
private UserMapper mapper;
@GetMapping("/queryUserList")
public List<User> queryUserList() {
List<User> users = mapper.queryUserList();
for (User u1 : users) {
System.out.println(u1);
}
return users;
}
}
【SpringBoot__Mybatis】整合MyBatis 配置文件版2
标签:add amp into pack tis cal test ESS 文件的
原文地址:https://www.cnblogs.com/kikyoqiang/p/14487717.html