SpringMVC报错The request sent by the client was syntactically incorrect ()
2024-10-18 22:29:32
springmvc数据绑定出的错
在数据绑定的时候一定要主意Controller方法中的参数名和jsp页面里的参数名字是否一致或者按照绑定的规范来写,
如果不一致,可能回报如下错误:
The request sent by the client was syntactically incorrect ().
从字面上理解是:客户端发送的请求语法错误。
实际就是springmvc无法实现数据绑定。
查看一下你传的参数是不是有date类型等Springmvc不支持参数绑定的类型,需自己绑定
date时间类型绑定 String-->date
String--> date 时间格式
package com.online.util; import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale; import org.springframework.format.Formatter; public class DateFormatter implements Formatter<Date>{ public String print(Date object, Locale locale) {
return null;
} public Date parse(String text, Locale locale) throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = null;
try {
date = format.parse(text);
} catch (Exception e) {
format = new SimpleDateFormat("yyyy-MM-dd");
date = format.parse(text);
}
return date;
}
}
在Spring的applicationContext.xml中注入这个类
<!-- 时间类型转换 -->
<bean id="conversionService"
class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<property name="formatters">
<set>
<bean class="com.online.util.DateFormatter"></bean>
</set>
</property>
</bean>
在Springmvc.xml中使用 mvc:annotation-driven注解配置
<mvc:annotation-driven conversion-service="conversionService"/>
这样就是现了string-->date类型的转换
最新文章
- Android Studio中获取SHA1或MD5的方法
- sqldeveloper
- linux 解压xz包
- BZOJ 3670 &;&; BZOJ 3620 &;&; BZOJ 3942 KMP
- 无线电源传输 Wireless Power Consortium (WPC) Communication
- Tor
- 20145317彭垚 《Java程序设计》第7周学习总结
- python中关于正则表达式
- createdb test时报global/pg_filenode.map不存在
- C++指针的引用
- 简谈HTML5与APP技术应用
- 使用Filter防止浏览器缓存页面或请求结果
- [RxJS] What RxJS operators are
- 查看SQLServer数据库信息的SQL语句
- 学习ExpressionTree(做装配脑袋出的练习题)
- java代理的深入浅出(二)-CGLIB
- python web框架之Tornado
- mybatis 开发规范
- SQL笔记之SELECT语句
- “指定的参数已超出有效值的范围”在【 parameterUpdate.Add(new OracleParameter(";STATUS";, 0));】报错