classpath到底是什么?
spring项目打包后会生成下面这个目录
classpath指的就是classes文件夹
classpath与classpath*的区别?
classpath之代表当前目录下的文件,而classpath*代表当前目录下的递归文件
我们配置时一般采用:mapper-locations: classpath:mapper/*.xml
这样springboot会扫描mapper目录下所有xml文件,而如果使用classpath*,则会递归扫描classes目录下所有文件,效率低
@RestController
@RestController = @Controller + @ResponseBody
使用@Controller,将返回一个包含页面的ModelAndView;而有些时候我们采用前后端分离,发送ajax请求,只需要返回json数据,使用 @ResponseBody可以实现只返回数据
@RequestBody
用来接收前端传递给后端的json字符串中的数据的(请求体中的数据的)
RequestBody 接收的是请求体里面的数据;而RequestParam接收的是key-value里面的参数
MyBatis-Plus无法进行多表查询
数据库存储时间类型bigint,datetime、timestamp选哪一个?
如果需要对时间字段进行操作(如通过时间范围查找或者排序等),推荐使用bigint,如果时间字段不需要进行任何操作,推荐使用timestamp,使用4个字节保存比较节省空间,但是只能记录到2038年记录的时间有限
链接:https://www.jianshu.com/p/b22ac1754372
Swagger
发展
前几年
前端主要负责静态页面,后端负责逻辑以及对页面渲染(模板引擎),返回视图
前后端分离时代
前端负责页面设计以及数据渲染,通过ajax请求获取数据
后端负责业务逻辑,三层模型,提供接口,返回json数据
因此,前后端的交互非常重要,前后端通过接口松耦合。如何保持数据的一致性,实时更新同步?
Swagger!
- restful api文档自动生成
- 在线运行测试
- 支持多种语言
安装与使用
- Swagger2
- Swagger UI
maven repository导入依赖
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
选择2.9.2版本,3.0.0版本有bug,显示404
配置swagger
基本信息配置ApiInfo
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket docket(){
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo());
}
private ApiInfo apiInfo(){
Contact contact = new Contact("Mark", "", "lffmark@qq.com");
return new ApiInfo("Marked-Blog",
"Api Documentation of Marked-Blog",
"1.0",
"urn:tos",
contact,
"Apache 2.0",
"http://www.apache.org/licenses/LICENSE-2.0",
new ArrayList<>());
}
}
配置扫描接口select
以及开关enable
public Docket docket(){
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.enable(true)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.ant("/blog/**"))
.build();
}
配置api分组
groupname
public Docket docket(){
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.groupName("mark")
.enable(true)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.ant("/blog/**"))
.build();
}
当存在多个Docket,对每一个Docket配置,就可以设置多个分组,多人协作时可以不同的人在不同分组