spring boot
ttt唐老鸭
爱做视频,爱玩游戏,爱摸鱼的程序猿
展开
-
spring boot 设置跨域
@Configurationpublic class WebConfig implements WebMvcConfigurer { @Value("${web.upload-path}") private String uploadPath; // 当前跨域请求最大有效时长。这里默认30天 private long maxAge = 30 * 24 * 60 * 60; private CorsConfiguration buildConfig() {原创 2021-11-26 10:40:21 · 132 阅读 · 0 评论 -
springboot 数据验证是放在Controller层还是Service层
规范性验证放在Controller层例如不能为空,不能为null等基本的规范性验证。前端也验证过了,后端验证确保健壮。但其实它不属于任何业务。而且Spring boot 里面的 @Validated,@NotNull @NotBlank 校验注解也是放在Controller层的。所以规范性校验放在Controller层是大家都比较认可的。业务性验证放在Service层需要查询数据库的,比如用户名不能重复,这种校验放在service层比较合适。因为与业务挂钩了。我有可能业务需求是用户名第一个字不能重复,原创 2021-10-28 15:10:15 · 5217 阅读 · 2 评论 -
spring boot @RequestParam
1 @RequestParam 不写也是可以的。 //两者效果是一样的 @PostMapping("/register") public void register(String username) { return xx; } @PostMapping("/register") public void register(@RequestParam(required = false)String username) {原创 2021-10-26 16:15:17 · 240 阅读 · 0 评论 -
idea spring boot mybatis plus使用配置
概况主要在于 mapper-locations 和pom中的区别。mapper-locations 跟据自己实际的位置写。idea编辑器下。如果xml文件放在了java目录则需要配置下面资源目录。否则无需配置。application.yamlmybatis-plus: global-config: #全局配置 db-config: #数据库配置 id-type: auto #主键id自增 configuration: #原来的mybais的配置 l原创 2021-08-30 11:26:22 · 244 阅读 · 0 评论 -
java spring boot 配置log4j2及使用
参考文章How to use Log4j 2 with Spring Boot第三篇 SpringBoot整合log4j2详解maven设置<!-- 去除默认的log --><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <exclusions> &l原创 2021-08-23 11:35:12 · 241 阅读 · 0 评论