# sprongboot-initialize-vue **Repository Path**: wywteach/sprongboot-initialize-vue ## Basic Information - **Project Name**: sprongboot-initialize-vue - **Description**: 分模块项目------------------模块拆分 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-10-16 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 模块拆分 > 模块化是解决一个复杂问题时自顶向下逐层把系统划分成若干模块去定义, 同时模块也可以说一种处理复杂系统分解为更好的可管理模块的方式 >其次模块化的好处??
- 实现了业务间的解耦和复用: ```text 在实现一个业务时,会出现方法的重复定义,以及变量的冲突,所以如果对业务进行模块化拆分后,各个都是一个独立的模块,每个模块负责的功能不同,他们之间没有了依赖关系,实现了业务模块间的解耦.同时模块功能比较单一,可在多个项目中使用,达到了复用 ``` -提高了开发的效率 ```text 每个模块实际上是单独完整的项目,可以进行单独的编译和调试,那如果是团队开发时,每个人负责不同的模块,模块之间没有依赖关系,因此提高了开发和测试效率. ``` ## 工具 Spring注解之@validated的使用 参数校验无侵入性。 ```text @AssertFalse 校验false @AssertTrue 校验true @DecimalMax(value=,inclusive=) 小于等于value, inclusive=true,是小于等于 @DecimalMin(value=,inclusive=) 与上类似 @Max(value=) 小于等于value @Min(value=) 大于等于value @NotNull 检查Null @Past 检查日期 @Pattern(regex=,flag=) 正则 @Size(min=, max=) 字符串,集合,map限制大小 @Validate 对po实体类进行校验 如果一个类中包含了另外一个实体类,那么在上面加上@Validated即可,比如上面的 public class XoPO { @validated private List personList; } spring-boot可能目前并不支持对参数的验证:https://jira.spring.io/browse... public Result xoById( @NotNull @NotBlank @Size(min=10,max=32)@PathVariable(value="accountId") String id) {} 但目前还无法抛出异常, 可能在spring的下一个版本中解决,或者不用@Pathvariable,而在service中 Class XoService{ public xoMethon( @NotNull String id){ } } ``` ### SecurityContextHolder.getContext().getAuthentication()为null的情况 ```text UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication() .getPrincipal(); 如果想用上面的代码获得当前用户,必须在spring security过滤器执行中执行,否则在过滤链执行完时org.springframework.security.web.context.SecurityContextPersistenceFilter类会 调用SecurityContextHolder.clearContext();而把SecurityContextHolder清空,所以会得到null。 经过spring security认证后,security会把一个SecurityContextImpl对象存储到session中,此对象中有当前用户的各种资料。 出现地方: 在日志进行 操作的时候 因为是异步执行mybatis plus 自动填入 获取不到 用户信息。。。 ``` ### 阿里云短信, ```text 可以 依赖,也可以单独分成项目 使用消息中间件 分离短信 和业务。未配置消息中间件。。。 ``` ### Swagger3.0 ```text @RestController @Api(tags = "测试接口") // description属性已过期废弃 public class HelloController { @ApiOperation(value = "测试接口1", notes = "测试Get接口") @ApiImplicitParams({ @ApiImplicitParam(name = "name", value="姓名", required = true, dataTypeClass = String.class), @ApiImplicitParam(name = "age", value="年龄", required = true, dataTypeClass = Integer.class), }) @GetMapping("getTest") public String getTest(String name, Integer age) { return name + age; } @ApiOperation(value = "测试接口2", notes = "测试Post接口") @ApiImplicitParam(name = "hello", value="对象参数", required = true, dataType = "Hello", dataTypeClass = Hello.class) @PostMapping("postTest") public String postTest(@RequestBody Hello hello) { return hello.getName(); } } ```