Springboot

Start

@SpringBootApplication
拆分
@Configuration
允许在上下文中注册额外的bean或导入其他配置类
@EnableAutoConfiguration
启用springboot自动配置机制
@ComponentScan
扫描被@Component(@Service,@Controller)注解的bean,默认扫描该类所在的包下所有的类

@PostMapping实际上就等价于 @RequestMapping(method = RequestMethod.POST),同样的 @DeleteMapping ,@GetMapping也都一样,常用的 HTTP Action 都有一个这种形式的注解所对应。
@PathVariable :取url地址中的参数。@RequestParam url的查询参数值。
@RequestBody:可以将 HttpRequest body 中的 JSON 类型数据反序列化为合适的 Java 类型。
ResponseEntity: 表示整个HTTP Response:状态码,标头和正文内容。我们可以使用它来自定义HTTP Response 的内容。

@EnableConfigurationProperties(prefix=”前缀”)
读取主配置文件前缀相关的配置

SpringBoot异常处理

@ControllerAdvice(assignableTypes = {IndexController.class})

@ExceptionHandler(value = Exception.class)

使用 @ControllerAdvice 和 @ExceptionHandler 处理全局异常
@ExceptionHandler 处理 Controller 级别的异常
ResponseStatusException

异常收集

Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986

SpringBoot 2.0.0 以上都采用内置tomcat8.0以上版本,而tomcat8.0以上版本遵从RFC规范添加了对Url的特殊字符的限制,url中只允许包含英文字母(a-zA-Z)、数字(0-9)、-_.~四个特殊字符以及保留字符( ! ’ ( ) ; : @ & = + $ , / ? # [ ] ) (262+10+4+18=84)这84个字符,请求中出现了{}大括号或者[]


本文链接: http://kiritor.github.io/2017/04/05/springboot/

-- EOF --

如果文章对您有用请随意打赏,谢谢支持!