卖狗人怎么做网站,宝安建设与住宅局网站,网站开发建设推荐用书,wordpress视频主题模板一.日期参数
当浏览器发起的请求参数类型是日期参数时#xff0c;我们通常使用LocalDateTime对象来接收#xff0c;前面使用DateTimeFormat注解来完成日期的格式转换#xff08;日期时间格式有多种#xff0c;需要哪种就设置为哪种#xff1a;如yyyy-MM-dd HH:mm:ss…一.日期参数
当浏览器发起的请求参数类型是日期参数时我们通常使用LocalDateTime对象来接收前面使用DateTimeFormat注解来完成日期的格式转换日期时间格式有多种需要哪种就设置为哪种如yyyy-MM-dd HH:mm:ss package com.gjw.controller;
/*** 目标掌握原始方式和springboot方式对于简单参数的请求响应* 掌握springboot方式对于实体参数的请求响应*/import com.gjw.pojo.User;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;RestController
public class RequestController {// 4.请求-时间日期参数RequestMapping(/dateTimeParam)public String dateTimeParam(DateTimeFormat(pattern yyyy-MM-dd HH:mm:ss) LocalDateTime updateTime){System.out.println(updateTime);return OK;}
}二.JSON参数
当浏览器的请求类型是JSON参数时需要JSON数据键名与形参对象属性名相同需要使用RequestBody作为标识因为JSON格式的数据要放在请求体当中携带到服务端中因此必须发起的是POST请求因此请求类型应为POST且请求体应选择RAW类型为JSON。 JSON中所有的key都要用”“引起来 必须保证JSON参数的键名与对象的属性名相同且JSON格式的数据要封装在一个实体对象当中前面必须加上注解RequestBody
package com.gjw.controller;
/*** 目标掌握原始方式和springboot方式对于简单参数的请求响应* 掌握springboot方式对于实体参数的请求响应*/import com.gjw.pojo.User;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;RestController
public class RequestController {// 5.JSON格式的参数RequestMapping(/jsonParam)public String jsonParam(RequestBody User user){System.out.println(user);return OK;}
}