现在尝试连接我的有角度的前端和springboot后端。
2019-03-19 04:50:49.853 WARN 32028 --- [nio-8095-exec-3] .wsmsDefaultHandlerExceptionResolver:已解决[org.springframework.http.converter.HttpMessageNotReadableException:缺少所需的请求正文:public void lk.arpico.proddb.controller.OccupationController.add(lk.arpico.proddb.dto.OccupationDto)] 2019-03-19 05:01:27.749错误32028-[nio-8095-exec-6] oaccC [。[。[/]。[dispatcherServlet]:Servlet [dispatcherServlet]的Servlet.service()路径[]引发异常[请求处理失败;嵌套的异常是org.springframework.orm.jpa.JpaSystemException:此类的ID必须在调用save()之前手动分配:lk.arpico.proddb.entity.OccupationEntity;嵌套的异常是org.hibernate.id.IdentifierGenerationException:此类的ID必须在根本原因之前调用save():lk.arpico.proddb.entity.OccupationEntity]之前手动分配。
org.hibernate.id.IdentifierGenerationException:此类的ID必须在调用save()之前手动分配:lk.arpico.proddb.entity.OccupationEntity 在org.hibernate.id.Assigned.generate(Assigned.java:33)〜[hibernate-core-5.4.0.Final.jar:5.4.0.Final]
但是我将@requestbody注释放入了我的职业控制器中...
package lk.arpico.proddb.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import lk.arpico.proddb.dto.NumberParamDto;
import lk.arpico.proddb.dto.OccupationDto;
import lk.arpico.proddb.entity.NumberParamsEntity;
import lk.arpico.proddb.entity.OccupationEntity;
import lk.arpico.proddb.service.OccupationService;
@RestController
@RequestMapping("occupation")
@CrossOrigin("*")
public class OccupationController {
@Autowired
private OccupationService occupationService;
@PostMapping("/add")
public void add(@RequestBody OccupationDto occupation) {
occupationService.add(occupation);
System.out.println("malinga"+occupation);
}
}
这是我的职业实体。
package lk.arpico.proddb.entity;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@Entity
@Table(name = "occupation")
public class OccupationEntity {
@Id
@Column(name = "occupation_Id", length = 11, nullable = false)
private String occupationId;
@Column(name = "code",length = 10, nullable = false)
private String code;
@Column(name = "createBy", length = 50, nullable = false)
private String createBy;
@Column(name = "createDate", nullable = false,
columnDefinition="DATETIME")
@Temporal(TemporalType.TIMESTAMP)
private Date createDate;
@Column(name = "isEnable", length = 11, nullable = false,
columnDefinition = "SMALLINT(1)")
private Integer isEnable;
@Column(name = "modifyBy", length = 50, nullable = true)
private String modifyBy;
@Column(name = "modifyDate", nullable = true,
columnDefinition="DATETIME")
@Temporal(TemporalType.TIMESTAMP)
private Date modifyDate;
@Column(name = "name", length = 60, nullable = false)
private String name;
@Column(name = "shortName", length = 15, nullable = false)
private String sName;
@OneToMany(mappedBy = "occupationEntity", targetEntity =
OccupationLoadingEntity.class)
private List<OccupationLoadingEntity> occupationLoadingEntities= new
ArrayList<>();
public OccupationEntity() {
// TODO Auto-generated constructor stub
}
public OccupationEntity(String occupationId, String code, String
createBy, Date createDate, Integer isEnable,
String modifyBy, Date modifyDate, String name, String sName,
List<OccupationLoadingEntity> occupationLoadingEntities) {
super();
this.occupationId = occupationId;
this.code = code;
this.createBy = createBy;
this.createDate = createDate;
this.isEnable = isEnable;
this.modifyBy = modifyBy;
this.modifyDate = modifyDate;
this.name = name;
this.sName = sName;
this.occupationLoadingEntities = occupationLoadingEntities;
}
public String getOccupationId() {
return occupationId;
}
public void setOccupationId(String occupationId) {
this.occupationId = occupationId;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getCreateBy() {
return createBy;
}
public void setCreateBy(String createBy) {
this.createBy = createBy;
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public Integer getIsEnable() {
return isEnable;
}
public void setIsEnable(Integer isEnable) {
this.isEnable = isEnable;
}
public String getModifyBy() {
return modifyBy;
}
public void setModifyBy(String modifyBy) {
this.modifyBy = modifyBy;
}
public Date getModifyDate() {
return modifyDate;
}
public void setModifyDate(Date modifyDate) {
this.modifyDate = modifyDate;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getsName() {
return sName;
}
public void setsName(String sName) {
this.sName = sName;
}
public List<OccupationLoadingEntity> getOccupationLoadingEntities() {
return occupationLoadingEntities;
}
public void setOccupationLoadingEntities(List<OccupationLoadingEntity> occupationLoadingEntities) {
this.occupationLoadingEntities = occupationLoadingEntities;
}
@Override
public String toString() {
return "OccupationEntity [occupationId=" + occupationId + ",
code=" + code + ", createBy=" + createBy
+ ", createDate=" + createDate + ", isEnable=" + isEnable
+ ", modifyBy=" + modifyBy + ", modifyDate="
+ modifyDate + ", name=" + name + ", sName=" + sName + ",
occupationLoadingEntities="
+ occupationLoadingEntities + "]";
}
}
那为什么 调用save()和之前,必须手动分配此类的ID。 缺少所需的请求正文 错误来了?