模型映射器映射错误

时间:2019-03-15 07:13:34

标签: java mysql spring hibernate rest

> PurchaseOrderHeaderDto

package com.assignment.dto;

import java.util.List;

import com.assignment.entity.PurchaseItem;

public class PurchaseOrderHeaderDto{

    private List<PurchaseItem> itemList;
    public List<PurchaseItem> getItemList() {
        return itemList;
    }
    public void setItemList(List<PurchaseItem> itemList) {
        this.itemList = itemList;
    }
    public int getPonumber() {
        return ponumber;
    }
    public void setPonumber(int ponumber) {
        this.ponumber = ponumber;
    }
    public String getVendor() {
        return vendor;
    }
    public void setVendor(String vendor) {
        this.vendor = vendor;
    }
    public String getPaymentterms() {
        return paymentterms;
    }
    public void setPaymentterms(String paymentterms) {
        this.paymentterms = paymentterms;
    }

    public String getCompanycode() {
        return companycode;
    }
    public void setCompanycode(String companycode) {
        this.companycode = companycode;
    }
    private int ponumber;
    private String vendor;
    private String paymentterms;
    private String status;
    public String getStatus() {
        return status;
    }
    public void setStatus(String status) {
        this.status = status;
    }
    private String companycode;
}

above is the code for the DTO class

> PurchaseOrderHeader
package com.assignment.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;
import com.fasterxml.jackson.annotation.JsonBackReference;



@Entity
@Table(name="PurchaseOrderHeader")
/*@FilterDef(name ="poFilter", parameters =@ParamDef(name ="ponumber", type ="int"))
@Filter(name ="poFilter", condition ="ponumber>=:ponumber") 
*/
public class PurchaseOrderHeader implements Serializable{


    /**
     * 
     */
    private static final long serialVersionUID = 2293787550626038248L;

    @Id
    @GenericGenerator(name = "generator", strategy = "increment")
    @GeneratedValue(generator = "generator")
    @Column(name="ponumber")
    private int ponumber;

    @JsonBackReference
    @OneToMany( fetch = FetchType.EAGER,mappedBy = "purchaseorder",cascade = CascadeType.ALL) 
    private List<PurchaseItem> itemList;  






    public List<PurchaseItem> getItemList() {

        return itemList;
    }

    public int getPonumber() {

        return ponumber;
    }

    public void setPonumber(int ponumber) {

        this.ponumber = ponumber;
    }

    public void setItemList(List<PurchaseItem> itemList) {

        this.itemList = itemList;
    }

    public Integer getCompanycode() {

        return companycode;
    }

    public void setCompanycode(Integer companycode)
    {
        this.companycode = companycode;
    }

    public String getStatus() {

        return status;
    }


    public void setStatus(String status) {

        this.status = status;
    }

    public String getVendor() {

        return vendor;
    }

    public void setVendor(String vendor) {

        this.vendor = vendor;
    }

    public String getPaymentterms() {
        return paymentterms;
    }

    public void setPaymentterms(String paymentterms) {
        this.paymentterms = paymentterms;
    }



    @Column(name="companycode")
    private Integer companycode;

    @Column(name="status")
    private String status;

    @Column(name="vendor")
    private String vendor;

    @Column(name="paymentterms")
    private String paymentterms;



public PurchaseOrderHeader() {

    }




    public PurchaseOrderHeader(int ponumber, Integer companycode, String status, String vendor, String paymentterms) {

        this.ponumber = ponumber;
        this.companycode = companycode;
        this.status = status;
        this.vendor = vendor;
        this.paymentterms = paymentterms;
    }

}

上面是DO类的代码

model mapper mapping errors ,Unable to convert String to Integer

DTO class has company code as String and the DO class has the company code
as Integer type when data is passed in json if string value is passed
for company code it should throw 400 bad request error in postman.

NumberFormatException关于在邮递员中传递数据。 用于数据库事务的Mysql数据库。

严重:路径为[/ Pro]的上下文中的servlet [spring]的Servlet.service()抛出异常[请求处理失败;嵌套的异常是org.modelmapper.MappingException:ModelMapper映射错误:

1) Converter org.modelmapper.internal.converter.NumberConverter@6279a752 failed to convert java.lang.String to java.lang.Integer.

1 error] with root cause
java.lang.NumberFormatException: For input string: "asdfghertyu"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)

0 个答案:

没有答案