记录一个自己在做商品信息显示与传递数据的时候出现的错误,

HTTP Status 400 – Bad Request
 
Type Status Report
 
Description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).

简单的说我在商品信息里有个Date createDate的属性类型。但是在前台传数据的时候是个String类型,因此会出现这个错误,可能是这个错误吧,我当时没复制,找了个网上问题相似的。我最开始解决这问题是在

SpringMVC.xml里配置了

<bean id="conversionServer"
        class="org.springframework.format.support.FormattingConversionServiceFactoryBean">

<!-- 日期转换器 -->

<property name="converters">

<list>

<bean class="com.mju.band3.Converter.DateConverter" />

</list>

</property>

</bean>

这个是DateConverter代码

package com.mju.band3.Converter;

import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date; public class DateConverter implements Converter<String, Date> {
private String datePattern="yyyy-MM-dd";
@Override
public Date convert(String s) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(datePattern); try {
return simpleDateFormat.parse(s);
} catch (ParseException e) {
throw new IllegalArgumentException("无效的日期格式");
} }
} 然而他出现了一个我弄了好几天都没弄好的问题,也就是我的JSP所有样式失效,而且也蹦掉,怀疑是jar版本问题,因为我再练习这个项目的时候出现了N多个版本问题的错误,
反正我是不知道为啥,那位大神能指点迷津, 那么我就去换了个方法,觉得这个方法也不错。贴上我的Bean
package com.mju.band3.Bean;

import java.text.SimpleDateFormat;
import java.util.Date; public class Item {
private Integer id;
private String name;
private float price;
private String detail;
private String pic;
private Date createtime; public Item(Integer id, String name, float price, String detail, String pic, Date createtime) {
this.id = id;
this.name = name;
this.price = price;
this.detail = detail;
this.pic = pic;
this.createtime = createtime;
} public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public float getPrice() {
return price;
} public void setPrice(float price) {
this.price = price;
} public String getDetail() {
return detail;
} public void setDetail(String detail) {
this.detail = detail;
} public String getPic() {
return pic;
} public void setPic(String pic) {
this.pic = pic;
} public Date getCreatetime() {
return createtime;
} public void setCreatetime(String str) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date createtime;
try {
createtime = sdf.parse(str);
this.createtime = createtime;
} catch (Exception e) {
e.printStackTrace();
}
} public Item() {
super();
} @Override
public String toString() {
return "Item{" +
"id=" + id +
", name='" + name + '\'' +
", price=" + price +
", detail='" + detail + '\'' +
", pic='" + pic + '\'' +
", createtime=" + createtime +
'}';
}
} 着重看setCreatetime方法,完美解决,贴出来分享下小白吧,我自己也是小白。
明天找机会再分享下上传文件显示的问题,也当做给自己成长记录,同时做做笔记吧。
兴许以后会来看自己的代码会觉得可笑,但也挺值得回味的。

SpringMVC错误,商品添加信息HTTP Status 400 – Bad Request的更多相关文章

  1. SpringMVC格式转化错误之HTTP Status [400] – [Bad Request]

    SpringMVC中,如果直接为Date类型的属性赋值,服务器有可能会报HTTP Status [400] – [Bad Request] Type Status Report Description ...

  2. springMVC 文件上传 HTTP Status 400 – Bad Request

    可能原因是:multipartResolver没有配置正确 请看解决方案: <!--文件上传 id必须为multipartResolver,不然报错HTTP Status 400 – Bad R ...

  3. HTTP STATUS 400 – BAD REQUEST ,SPRINGMVC错误

    400大多为前台传的数据于后台接受数据不符合,注意Date数据类型最容易错. 然后需要调用实体类的空参构造方法,,注意创建了有参构造方法后,创建一个空参构造方法.

  4. SSM搭项目报错:HTTP Status 400 – Bad Request

    具体报错如下: Type Status Report Description The server cannot or will not process the request due to some ...

  5. jmeter接口测试 -- status==400(Bad Request)

    一.接口请求信息 二.错误的jmeter接口请求 1.请求内容 2.响应内容 三.正确的接口请求 1.看回原本的接口请求信息,company_id = null  .这里也就不能空 四.原因分析 1. ...

  6. HTTP Status 400 - Required request part 'file' is not present

    今天使用Spring MVC做一个文件上传的功能,在提交表单的时候出现了如下错误:

  7. jersey HTTP Status 400 - Bad Request

    原因是jersey 内置的转换器,只能做简单的类型转换如: 首先客户端提交上来的一定是String; String ----> String/Long/Boolean 这些基本的 可以转换,但是 ...

  8. Spring MVC出现POST 400 Bad Request &405 Request method 'GET' not supported

    首先描述一下出现错误的情景: 我刚学springmvc,想做一个登录界面的东西.然后试着写了一个controller如下: @RequestMapping(value = "/login&q ...

  9. http status 400,http 400,400 错误

    转载:http://blog.csdn.net/xu_zh_h/article/details/2294233 4 请求失败4xx 4xx应答定义了特定服务器响应的请求失败的情况.客户端不应当在不更改 ...

随机推荐

  1. 黑客的探路狗ReconDog网站信息探测收集工具

    工具下载地址:http://pan.baidu.com/s/1pLJnBLL 密码:gqlz   OR  https://github.com/UltimateHackers/ReconDog 下载并 ...

  2. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 辅助类:关闭图标

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  3. 获取网卡MAC、硬盘序列号、CPU_ID、BIOS编号

    抄来的 获取网卡MAC.硬盘序列号.CPU ID.BIOS编号 本文中所有原理及思想均取自网络,有修改.其中获取硬盘序列号.获取CPU编号.获取BIOS编号的原始代码的著作权归各自作者所有. 以下代码 ...

  4. 牛客小白月赛3---G 旅游(树形dp)

    题目链接:https://www.nowcoder.com/acm/contest/87/G 分析: 1.对于点cur,dp[cur][0]表示在该点住宿:dp[cur][1]表示其某个子结点住宿,自 ...

  5. CodeForces - 876D Sorting the Coins

    题意:有n个数的序列,n个数都为0,每次指定某个数变为1,当序列中第i个数为1,第i+1个数为0时,这两个数可交换,将序列从头到尾进行一次交换记为1次,直到某一次从头到尾的交换中没有任何两个数交换.序 ...

  6. 201706 gem 'rails-erd'生成Model关系图

    [工具]一张图理清各个model之间关系 安装 Graphviz 2.22+: 终端机中执行 brew install graphviz Gemfile中添加 gem 'rails-erd' 终端机中 ...

  7. R 再也不用愁变量太多跑回归太麻烦!R语言循环常用方法总结

    在高维数据分析过程中,为了筛选出与目标结局相关的变量,通常会用到回归分析,但是因为自变量较多,往往要进行多次回归.这就是统计编程语言发挥作用的时候了 有些大神们认为超过3次的复制粘贴就可以考虑使用循环 ...

  8. IDEA中利用MAVEN制作和打包普通可执行应用(非SprintBoot的WEB应用)

    我使用IDEA也就半年,开发中常常会遇到一些问题,例如用IDEA编写普通的可执行程序: 之前使用Eclipse编写一个可执行的JAVA程序,然后导出打包,非常方便: 但是我呢,想在 IDEA 中用Ma ...

  9. net Core3.1 Swagger加JWT权限

    1.Swagger中开启JWT服务 #region swagger services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new ...

  10. MongoDB_04_插入和查询

    案列需求: 存在文章评论的数据存放到MongoDB中,数据结构参考如下: 数据库:articledb 专栏文章评论 comment / / 字段名称 字段含义 字段类型 备注 _id ID Objec ...