1 每一个黑框一个小知识点
//springboot启动时加载自定义类
当一个自定义类实现applicationRuner后,当springboot项目启动时,会执行这个类
//@Value("${xxxx}")注解的配置及使用
Spring 通过@Value注解获取*.porperties文件code的内容,然后赋值给使用该注解的Code属性上。
@Value("${code}")
private String Code;`
//springboot在controller层接收参数
A、处理requet uri 部分(这里指uri template中variable,不含queryString部分)的注解: @PathVariable;
@Controller
@RequestMapping(“/owners/{ownerId}”)
public class RelativePathUriTemplateController {
@RequestMapping(“/pets/{petId}”)
public void findPet(@PathVariable String ownerId, @PathVariable String petId, Model model) {
// implementation omitted
}
}
B、处理request header部分的注解: @RequestHeader, @CookieValue;
把Request请求header部分的值绑定到方法的参数上。
C、处理request body部分的注解:@RequestParam【默认和接收地址栏拼接参数,一个方法可以有多个】
@RequestBody【接收请求体参数,一个方法只能有一个,前端传值json对象字符串,后台接收变Javabean对象】;
D、处理attribute类型是注解: @SessionAttributes, @ModelAttribute;
springboot接收时间格式为2020-09-04 03:01:33,接收字段为date类型时,前端传时间戳还是2020-09-04 03:01:33这种形式,都会转化为date类型Wed Sep 09 11:40:31 CST 2020
例如,后端接收为Date类型
前端传值为:1599622831634或者2020-09-04 03:01:33
最后接收的都是Wed Sep 09 11:40:31 CST 2020这种形式

本文详细介绍了SpringBoot启动时如何加载自定义类,包括实现ApplicationRunner接口的方法。此外,还深入探讨了SpringBoot在Controller层接收各种类型参数的方式,如PathVariable、RequestHeader、RequestParam和RequestBody等注解的使用,以及如何处理日期格式。
620

被折叠的 条评论
为什么被折叠?



