1.实体类
@Data 相当于生成了get set
@AllArgsConstructor 有参构造函数
@NoArgsConstructor
@Column(name = "id") 字段名
@Table(name = "user")
@Id 主键
@KeySql="True" 自动增长,可以不加
Lombok插件
TKMapper插件:
MyBatis的第三方插件
2.DAO层
定义操作数据库的接口
@Repository 表示DAO层
继承Mapper
3.Service层
定义业务逻辑
@Service 表示业务层
@Autowired 将dao层注入业务层
private UserDao userDao;
4.Controller层
@RestController 表示控制层
@Resource 调用业务层
private UserService userService;
@RequestMapping("/login")
5.启动类
@MapperScan("com.example.maventwo.dao")扫描dao
6.Swagger
用于生成在线文档,测试接口
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.28</version>
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>4.2.3</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.6</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.7</version>
</dependency>
package com.example.maventwo.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableSwagger2
@Configuration
public class SwaggerConfig {
@Bean
public Docket getDocket(){
//创建封面
ApiInfoBuilder apiInfoBuilder = new ApiInfoBuilder();
apiInfoBuilder
.title("《后台管理系统》后端接口说明文档")
.description("后端接口规范")
.version("v1.0.0")
.contact(new Contact("lee","www.xiaoming.com","22@qq.com"));
ApiInfo apiInfo = apiInfoBuilder.build();
Docket docket = new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo) //生成指定文档封面
.select()
.apis(RequestHandlerSelectors.basePackage("com.example.maventwo.controller"))
.paths(PathSelectors.any())
.build();
return docket;
}
}