文章目录
一,SpringBoot
参考博客:SpringBoot开发常用技术整合
1.SpringBoot开发中注解总结
1.Jackson注解
Jackson:处理JSON和XML格式化的类库,快速建立Java类与JSON之间的关系
//忽略显示
@JsonIgnore
private String password;
private Integer age;
//格式化Date类型,String不行
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date birthday;
//为null不显示
@JsonInclude(Include.NON_NULL)
private String desc;
二,SpringBoot其他
1.Security权限框架
参考:Spring-Security@PreAuthorize(“hasAuthority(’’)”)源码分析
//用户具有admin角色才能访问
@PreAuthorize("hasRole(‘admin‘)")
//鉴别当前登录用户所拥有的角色是否有xxx权限访问该接口
@PreAuthorize("hasAuthority('sys:file:del')")
public void delete(@PathVariable String id) {
}
2.Activiti工作流
包含23张数据表,所有的表名默认以“ACT_”开头。
3.Quartz定时任务
包含11张表,所有的表名默认以“QRTZ_”开头。
参考博客:quartz 进行Oracle和Mysql建表语句
4.Redis
参考博客:Windows 中 安装 Redis 解压版
参考博客:spring整合redis缓存注解
常用注解:
//针对方法配置:根据方法的请求参数对其返回结果进行缓存,value=缓存名称,key=缓存的 key
@Cacheable(value="dictBmmxb",key="#type")
//针对方法配置:根据一定的条件对缓存进行清空
@CacheEvict(value="dictBmmxb",key="#type")
@CachePut针对方法配置:根据方法的请求参数对其结果进行缓存,和 @Cacheable 不同的是,它每次都会触发真实方法的调用
5.Swagger2
生成RESTFUL接口的开发文档,且支持做测试。
Swagger默认访问地址:http://localhost:8889/swagger-ui.html
5.1SpringBoot配置Swagger2
依赖
<!--swagger依赖-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
配置类
@Configuration
@EnableSwagger2
public class SwaggerConfig {
//swagger2的配置文件,这里可以配置wagger2的一些基本的内容,比如扫描的包等等
//Docket 类提供了 apis() 和 paths()两 个方法来帮助我们在不同级别上过滤接口
//apis():这种方式我们可以通过指定包名的方式,让 Swagger 只去某些包下面扫描。
//paths():这种方式可以通过筛选 API 的 url 来进行过滤。
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
//为当前包路径
//.apis(RequestHandlerSelectors.basePackage("com.zr"))
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
/**
* 构建 api文档的详细信息函数
* @return
*/
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
//页面标题
.title("Swagger接口文档")
//创建人
//.contact(new Contact("lys", "http://www.baidu.com", "lys@163.com"))
//版本号
.version("1.0")
//描述
//.description("API 描述")
.build();
}
}
5.2Swagger2使用
参考:swagger的描述注释配置详解
常用注解:
//设置对 Controller的描述
@Api(tags = "用户管理接口")
public class UserController { }
//设置对接口的描述
@ApiOperation(value = "保存用户")
public SysUser saveUser(@RequestBody UserDto userDto) { }