2021-09-11

本文介绍了在SpringBoot中如何正确处理Date类型参数的转换问题,以及@RequestParam在接收前端请求参数时的使用和误区。重点讲解了String类型替代Date的原因,以及RequestParam的作用和适用场景。
摘要由CSDN通过智能技术生成

今天学到的两点

第一个:

示例:

    @GetMapping("/getRecordList")
	public Object getRecordList(@Param("DisabledListReq") DisabledListReq disabledListReq,
	HttpServletRequest request) throws ParseException {}

	// 类
	public class DisabledListReq {
    	private static final long serialVersionUID = 1L;

    	// 服务时间 YYYY-MM
    	private String paramMonth;
	}

springboot框架中 ,我一开始是用 Date 类型

    	private Date paramMonth;

然后在接收参数时,报类型转换错误,但是呢,我还想用Date,然后我就用了@Jsonformat ,结果肯定还是错误。因为Jsonformat 对返回参数做日期格式化。
最后,我还是用了 String。

第二个:

还是上面的代码

  @GetMapping("/getRecordList")
	public Object getRecordList(@RequestParam ("DisabledListReq") DisabledListReq disabledListReq,
	HttpServletRequest request) throws ParseException {}

@RequestParam 这里,我一开始用的时@RequestParam ,然后传参(json对象)的过程中就一直报错,

org.springframework.web.bind.MissingServletRequestParameterException: Required DisabledListReq parameter 'disabledListReq' is not present

提示没有获取到相应的参数,接下我就来来回回看前后端,尝试修改,浪费了好长时间
最后把RequestParam 去掉就可以获取到参数了
原来:RequestParam 是为了解决前台参数名称与后台接收参数变量名称不一致的问题
然后就没有DisabledListReq 这个参数,能不报错吗

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值