【SpringBoot__Mybatis】整合MyBatis 配置文件版2
2021-06-09 21:03
阅读:484
标签:add amp into pack tis cal test ESS 文件的
1、引用pom文件
org.springframework.boot
spring-boot-starter-jdbc
org.springframework.boot
spring-boot-starter-web
org.mybatis.spring.boot
mybatis-spring-boot-starter
2.1.3 mysql
mysql-connector-java
runtime org.springframework.boot
spring-boot-starter-test
test org.projectlombok
lombok
2、yml
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
3、UserMapper
@Mapper
@Repository
public interface UserMapper {
public static final int age = 111;
List queryUserList();
User getUserById(int id);
int addUser(User user);
int update(User user);
int delete(int id);
}
4、mybatis/mapper/UserMapper.xml
INSERT INTO user
VALUES (null, #{name}, #{age}, #{gender})
DELETE
FROM user
WHERE id = #{id}
UPDATE user
SET name = #{name},
age = #{age},
gender = #{gender}
WHERE id = #{id}
5、UserController
@RestController
public class UserController {
@Autowired
private UserMapper mapper;
@GetMapping("/queryUserList")
public List queryUserList() {
List 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
上一篇:【算法实践进阶】任务2 特征工程
文章来自:搜素材网的编程语言模块,转载请注明文章出处。
文章标题:【SpringBoot__Mybatis】整合MyBatis 配置文件版2
文章链接:http://soscw.com/index.php/essay/92841.html
文章标题:【SpringBoot__Mybatis】整合MyBatis 配置文件版2
文章链接:http://soscw.com/index.php/essay/92841.html
评论
亲,登录后才可以留言!