这个错误纠结了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。
结果:
错误消失了!!!!!