Springboot进阶-JDBC、Druid、Mybatis、Swagger、SpringMVC、Mail
1.Springboot-JDBC
-
Springboot整合JDBC后,引入spring-boot-starter-jdbc,通过JdbcTemplate来操作数据库。
-
导入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
- 通过JdbcTemplate来操作数据库,进行增删改查
@RestController
public class UserController {
@Resource
private JdbcTemplate jdbcTemplate;
//from fhadmin.cn
@GetMapping("/delete")
public String delete() {
String sql = "delete from tb_user where id = 9";
jdbcTemplate.update(sql);
return "delete ok";
}
@GetMapping("/update")
public String update() {
String sql = "update tb_user set name= "tom9" where id = 9";
jdbcTemplate.update(sql);
return "update ok";
}
@GetMapping("/insert")
public String insert() {
String sql = "insert into tb_user (id,name,age) values (10,"tom10",10)";
jdbcTemplate.update(sql);
return "insert ok";
}
@GetMapping("/get")
public List<Map<String, Object>> getList() {
String sql = "select * from tb_user";
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
return list;
}
}
回到顶部
hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » Springboot进阶-JDBC、Druid、Mybatis、Swagger、SpringMVC、Mail
自学咖网 » Springboot进阶-JDBC、Druid、Mybatis、Swagger、SpringMVC、Mail