1.先在pom里导坐标
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.15</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.3</version>
</dependency>
2.yml里配置
spring:
datasource:
druid:
url: jdbc:mysql://localhost:3306/test?serverTimezone=UTC&useSSL=false&characterEncoding=UTF-8
username: root
password: root
server:
port: 8080
3.bean
package com.dwe.bean;
import lombok.Data;
@Data
public class Book{
private Integer id;
private String type;
private String name;
private String description;
}
4.controller
@RestController
@RequestMapping("/book")
public class BookController {
@Autowired
BookMapper bookMapper;
@RequestMapping("/ok")
public String ok() {
return "ok";
}
@RequestMapping("/all")
public String queryAll() {
return bookMapper.selectList(null).toString();
}
@RequestMapping("/queryById/{id}")
public String queryById(@PathVariable("id") String id) {
return bookMapper.selectById(id).toString();
}
}
5.启动类里加mapperscan
标签:return,String,CRUD,private,public,操作,数据,id,RequestMapping From: https://www.cnblogs.com/doudou666/p/16914001.html