春季启动:PUT不会更新ManyToOne字段,但会更新所有其他字段

时间:2018-09-13 13:55:20

标签: java spring rest spring-boot

我正在编写Spring Boot Rest API。我的行为有些混乱。当我想使用PUT更新资源时,spring不会更新每个字段。就我而言,我可以更新字符串值,但不能更新关系值。

我打开了显示以下内容的debug日志:

2018-09-13 16:41:09.041 DEBUG 17152 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing PUT request for [/dimensionAttributeValues/27109/]
2018-09-13 16:41:09.043 DEBUG 17152 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /dimensionAttributeValues/27109/
2018-09-13 16:41:09.045 DEBUG 17152 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/dimensionAttributeValues/27109/]
2018-09-13 16:41:09.325 DEBUG 17152 --- [nio-8080-exec-1] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Written [Resource { content: de.pentasys.dwhservice.data.dimensionattributevalue.DimensionAttributeValue@28f1ee36, links: [<http://localhost:8080/dimensionAttributeValues/27109>;rel="self", <http://localhost:8080/dimensionAttributeValues/27109>;rel="dimensionAttributeValue"] }] as "application/hal+json" using [org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration$ResourceSupportHttpMessageConverter@5e7be36b]
2018-09-13 16:41:09.325 DEBUG 17152 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2018-09-13 16:41:09.325 DEBUG 17152 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Successfully completed request

请求:PUT http://localhost:8080/dimensionAttributeValues/27109/

{
   "dimensionAttributeValueID":27109,
   "chrValue":null,
   "intValue":null,
   "decValue":null,
   "datValue":null,
   "blnValue":null,
   "startDate":"2018-08-13",
   "_links":{
      "self":{
         "href":"http://localhost:8080/dimensionAttributeValues/27109"
      }
   },
   "lstValue":"http://localhost:8080/dimensionAttributeLists/4",
   "masterData":"http://localhost:8080/masterData/2",
   "dimensionAttribute":"http://localhost:8080/dimensionAttributes/8"
}

作为回应,我得到了下面的status 200 JSON。但是跟随链接未导致我更新的lstValue。在startDate更新时,我查看了数据库,它仍然是旧值。

{
    "dimensionAttributeValueID": 27109,
    "chrValue": null,
    "intValue": null,
    "decValue": null,
    "datValue": null,
    "blnValue": null,
    "startDate": "2018-08-13",
    "_links": {
        "self": {
            "href": "http://localhost:8080/dimensionAttributeValues/27109"
        },
        "dimensionAttributeValue": {
            "href": "http://localhost:8080/dimensionAttributeValues/27109"
        },
        "lstValue": {
            "href": "http://localhost:8080/dimensionAttributeValues/27109/lstValue"
        },
        "dimensionAttribute": {
            "href": "http://localhost:8080/dimensionAttributeValues/27109/dimensionAttribute"
        },
        "masterData": {
            "href": "http://localhost:8080/dimensionAttributeValues/27109/masterData"
        }
    }
}

实体类:

@Entity
@Table(name = "DimensionAttributeValue")
public class DimensionAttributeValue {

    @Id
    @GeneratedValue
    @Column(name = "DimensionAttributeValue_ID")
    private long dimensionAttributeValueID;

    @ManyToOne
    @JoinColumn(name = "DimensionAttribute_ID")
    private DimensionAttribute dimensionAttribute;

    @ManyToOne
    @JoinColumn(name = "MasterData_ID")
    private MasterData masterData;

    @Column (name = "ChrValue")
    private String chrValue;

    @Column (name = "IntValue")
    private Long intValue;

    @Column (name = "DecValue")
    private Double decValue;

    @Column (name = "DatValue")
    private String datValue;

    @Column (name = "BlnValue")
    private Boolean blnValue;

    @ManyToOne
    @JoinColumn (name = "LstValue")
    private DimensionAttributeList lstValue;

    @Column (name = "StartDate")
    private Date startDate;

    public DimensionAttributeValue() {
    }

    public DimensionAttributeValue(DimensionAttribute dimensionAttribute, MasterData masterData, String chrValue, long intValue, double decValue, String datValue, DimensionAttributeList lstValue, Date startDate) {
        this.dimensionAttribute = dimensionAttribute;
        this.masterData = masterData;
        this.chrValue = chrValue;
        this.intValue = intValue;
        this.decValue = decValue;
        this.datValue = datValue;
        this.lstValue = lstValue;
        this.startDate = startDate;
    }

    public long getDimensionAttributeValueID() {
        return dimensionAttributeValueID;
    }

    public DimensionAttribute getDimensionAttribute() {
        return dimensionAttribute;
    }

    public MasterData getMasterData() {
        return masterData;
    }

    public String getChrValue() {
        return chrValue;
    }

    public Long getIntValue() {
        return intValue;
    }

    public Double getDecValue() {
        return decValue;
    }

    public String getDatValue() {
        return datValue;
    }

    public DimensionAttributeList getLstValue() {
        return lstValue;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setDimensionAttributeValueID(long dimensionAttributeValueID) {
        this.dimensionAttributeValueID = dimensionAttributeValueID;
    }

    public void setDimensionAttribute(DimensionAttribute dimensionAttribute) {
        this.dimensionAttribute = dimensionAttribute;
    }

    public void setMasterData(MasterData masterData) {
        this.masterData = masterData;
    }

    public void setChrValue(String chrValue) {
        this.chrValue = chrValue;
    }

    public void setIntValue(Long intValue) {
        this.intValue = intValue;
    }

    public void setDecValue(Double decValue) {
        this.decValue = decValue;
    }

    public void setDatValue(String datValue) {
        this.datValue = datValue;
    }

    public void setLstValue(DimensionAttributeList lstValue) {
        this.lstValue = lstValue;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Boolean getBlnValue() {
        return blnValue;
    }

    public void setBlnValue(Boolean blnValue) {
        this.blnValue = blnValue;
    }
}

0 个答案:

没有答案