java

关注公众号 jb51net

关闭
首页 > 软件编程 > java > springboot整合 druid

springboot整合mybatis plus与druid详情

作者:<编程路上>

这篇文章主要介绍了springboot整合mybatis plus与druid详情,文章围绕主题展开详细的内容介绍,具有一定的参考价值,需要的下伙伴可以参考一下

加坐标可以使用https://mvnrepository.com/来查找

先加以下坐标:

使用的数据库介绍:

配置连接数据库:

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/spring?serverTimezone=UTC
    username: root
    password: 123456

定义类:

package com.spring1.domain;

import com.baomidou.mybatisplus.annotation.TableName;

@TableName("student")
public class student {
    private Integer id;
    private String name;
    private String age;

    @Override
    public String toString() {
        return "student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age='" + age + '\'' +
                '}';
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }
}

测试:

package com.spring1;

import com.spring1.dao.StudentDao;
import com.spring1.domain.student;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class Spring1ApplicationTests {

    @Autowired
    private StudentDao studentDao;
    @Test
    void contextLoads() {
        System.out.println(studentDao.selectList(null));
    }

}
[student{id=1000, name='Li Ming', age='22'}, student{id=1001, name='Danny', age='17'}, student{id=1002, name='Li Gang', age='22'}, student{id=1003, name='Jenny', age='19'}, student{id=1004, name='Jim', age='19'}]

添加druid

添加坐标:

配置修改:

spring:
  datasource:
    druid:
       driver-class-name: com.mysql.cj.jdbc.Driver
       url: jdbc:mysql://localhost:3306/spring?serverTimezone=UTC
       username: root
       password: 123456

到此这篇关于springboot整合mybatis plus与druid详情的文章就介绍到这了,更多相关springboot整合 druid内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:
阅读全文