【解决】springmvc 前台表单提交数据返回400错误

这个错误纠结了3天,特此做个标记!

前台表单提交,添加用户,用户属性里有个:Integer  status;属性;

controller中函数:

public ModelAndView addUser(
String flag,
@ModelAttribute User user,
ModelAndView mv){

//。。。。。。

}

前台页面表单提交,进到拦截器里就不进去了,找了很久才知道,是@ModelAttribute进行类型绑定时候不匹配!具体就是status这个属性不匹配!

但是由于页面只返回了一个400错误代码,没有错误地址和原因,后来增加了日志文件,才看到错误信息;

日志配置文件:

log4j.rootLogger=ALL,systemOut,logFile,logDailyFile,logRollingFile,logMail,logDB

#输出到文件 
log4j.appender.logFile= org.apache.log4j.FileAppender 
log4j.appender.logFile.layout= org.apache.log4j.PatternLayout 
log4j.appender.logFile.layout.ConversionPattern= [%-5p][%-22d{yyyy/MM/dd HH:mm:ssS}][%l]%n%m%n 
log4j.appender.logFile.Threshold= DEBUG 
log4j.appender.logFile.ImmediateFlush= TRUE 
log4j.appender.logFile.Append= TRUE 
log4j.appender.logFile.File= F://log4j_Struts.log 
log4j.appender.logFile.Encoding= UTF-8 


找到错误代码:

Failed to resolve argument 2 of type 'org.springframework.web.servlet.ModelAndView'
 org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'modelAndView' on field 'status': rejected value [1]; codes [typeMismatch.modelAndView.status,typeMismatch.status,typeMismatch.org.springframework.http.HttpStatus,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [modelAndView.status,status]; arguments []; default message [status]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'org.springframework.http.HttpStatus' for property 'status'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [org.springframework.http.HttpStatus] for value '1'; nested exception is java.lang.IllegalArgumentException: No enum constant org.springframework.http.HttpStatus.1]


大概意思就是类型转化错误啦。

不太明白什么意思,干脆吧属性名换一个,换成了state,更改了相关的getter,setter方法,和调用他们的类,方法。把前台jsp里、数据库里,所有写着status属性的全换成state。

结果:

错误消失了!!!!!




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值