Advanced springboot JDBC, Druid, mybatis, swagger, springmvc, mail



  1. After integrating JDBC with springboot, spring boot starter JDBC is introduced to operate the database through jdbctemplate.

  2. Import dependency

  1. Operate the database through jdbctemplate to add, delete, modify and query
public class UserController {

    private JdbcTemplate jdbcTemplate;

    public String delete() {
        String sql = "delete from tb_user where id = 9";
        return "delete ok";

    public String update() {
        String sql = "update tb_user set name= 'tom9' where id = 9";
        return "update ok";

    public String insert() {
        String sql = "insert into tb_user (id,name,age) values (10,'tom10',10)";
        return "insert ok";

    public List<Map<String, Object>> getList() {
        String sql = "select * from tb_user";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        return list;

Back to the top


  1. Import dependency
<!--  -->
  1. application. Yaml configure Druid connection pool
  1. Druid connection pool configuration and druiddatasource binding in yaml
  1. Configure the servlet that accesses Druid
  1. Configure filter for Druid monitoring

Back to the top


  1. Import dependency
  1. mapper. XML storage location
  1. Two ways to configure Dao layer interface

    1. Use @ mapper annotation
    public interface UserDao {
        List<User> getList();
    1. Configure @ mappercans on the startup class
    public class Demo05Application {
        public static void main(String[] args) {
  , args);

Back to the top


  1. Import dependency
<!--  3.0 and springboot integration, direct import starter -- >
  1. to configure
  1. Swagger access address.http://localhost:8080/swagger-ui/index.html
  2. The configuration is only accessible in swagger, Dev and test environments
//from fhadmin. cn
  1. Swagger configuration grouping
//from fhadmin. cn
  1. Swagger annotation
//The entity class will not be scanned. The interface that needs to be scanned and the entity class object can be configured by swagger from fhadmin cn

Back to the top


  1. The web The servlet and filter in XML are configured into the container.
  1. Configure view parser

    1. Mode 1
    1. Mode 2
    public class MyWebMvcConfigurer implements WebMvcConfigurer {
  2. Other configurations

  1. exception handling

This work adoptsCC agreementThe author, link and reprint of this article must be indicated