程序员的资源宝库

网站首页 > gitee 正文

spring boot_04_整合第三方

sanyeah 2024-04-02 19:56:43 gitee 9 ℃ 0 评论

1. spring boot整合第三方

1.1 整合mybatis-plus

导入mybatis-plus

         <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.4.3</version>
        </dependency>

配置application.yml文件

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
    username: root
    password: root
#表名配置加上
mybatis-plus:
  global-config:
    db-config:
      table-prefix: tbl_

dao包代码

@Mapper
@Component
public interface Bookdao extends BaseMapper<Book> {}

domain包代码

public class Book {
    private Integer id;
    private String type;
    private String name;
    private String description;

    @Override
    public String toString(){
        return "Book{" +
                "id=" + id +
                ", type='" + type + '\'' +
                ", name='" + name + '\'' +
                ", description='" + description + '\'' +
                '}';
    }

    public Integer getId() {
        return id;
    }

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

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getName() {
        return name;
    }

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

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
}


测试类代码

@SpringBootTest
class Springboot06ApplicationTests {

    @Autowired
    private Bookdao bookdao;

    @Test
    void contextLoads() {
        System.out.println(bookdao.selectById(1));
        System.out.println(bookdao.selectList(null));
    }

}

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表