SpringBoot学习笔记

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配置,就可以设置多个分组,多人协作时可以不同的人在不同分组

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值