无法将'java.lang.String'类型的值转换为所需类型

时间:2015-07-10 08:42:47

标签: java spring-boot

我正在运行以下代码,它将显示错误消息。如何解决这个错误?

 @RequestMapping(value = "/Testresult", method = RequestMethod.POST)
    @ResponseBody
    public String testresult(
            HttpServletRequest request,
            @Valid TestCustomer<Customer> req
               ,BindingResult resultMsg) 
     {
        String content = "";
        if(resultMsg.hasFieldErrors() ){
            System.out.println("the error counts:" + resultMsg.getErrorCount());

        }
        return resultMsg.getErrorCount;
    }

//TestCustomer.java

public class TestCustomer<T> extends BaseUser {

    @Valid
    private T req;

    public T getReq() {
        return req;
    }

    public void setReq(T req) {
        this.req = req;
    }

}

//BaseUser.java
public class BaseUser {

    @Size(min=3, max=20)
    private String app;

    public String getApp() {
        return app;
    }

    public void setApp(String app) {
        this.app = app;
    }
}
//Customer.java
public class Customer implements Serializable{

    @Size(min=3, max=4)
    private String cust_id;

    private String order_id;

    public String getCust_id() {
        return cust_id;
    }

    public void setCust_id(String cust_id) {
        this.cust_id = cust_id;
    }

    public String getOrder_id() {
        return order_id;
    }

    public void setOrder_id(String order_id) {
        this.order_id = order_id;
    }
}

我发布了以下网址

  

http://localhost:8080/jd/order/Testresult?app=122&req= {\“cust_id \”:\“\”,\“order_id \”:\“122 \”}

firefox海报错误是:

  

/ *       [        “timestamp”:1436514495544,        “身份”:500,        “错误”:“内部服务器错误”,        “exception”:“org.springframework.beans.ConversionNotSupportedException”,        “message”:“无法将类型'java.lang.String'的值转换为必需类型'cn.vcredit.jd.emergencymoney.restservice.TestCustomer';嵌套异常是java.lang.IllegalStateException:无法转换类型的值[ java.lang.String]到必需的类型[cn.vcredit.jd.emergencymoney.restservice.TestCustomer]:找不到匹配的编辑器或转换策略“]   * /

0 个答案:

没有答案