首页 > 其他分享 >spring boot_04

spring boot_04

时间:2022-12-07 21:00:49浏览次数:40  
标签:name 04 spring description boot id type public String

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));
    }

}

标签:name,04,spring,description,boot,id,type,public,String
From: https://www.cnblogs.com/jinghong-wang/p/16963470.html

相关文章