0
私のコードに問題があります...Spring Boot JSON多対1
私はSpring BootとAngularjsでシングルページアプリケーションを作成します。ここで
は私のユーザークラスです:
@Entity
@Table(name = "admins")
public class Admin {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer adminid;
private String name;
private String surname;
private String email;
private String login;
private String password;
@ManyToOne
@JoinColumn(name = "groupid")
private Group groupid;
private Boolean active;
@Temporal(TemporalType.TIMESTAMP)
private Date modifydate;
@Temporal(TemporalType.TIMESTAMP)
private Date createdate;
public Admin() {
}
//setters ang getters
}
そして、私のsecendエンティティクラスは
@Entity
@Table(name = "groups")
public class Group {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer groupid;
private String groupname;
@Temporal(TemporalType.TIMESTAMP)
private Date modifydate;
@Temporal(TemporalType.TIMESTAMP)
private Date createdate;
@OneToMany(fetch = FetchType.EAGER, mappedBy = "groupid")
@JsonIgnore
private List<Admin> groupusers;
public Group() {
}
public Group(Integer groupid) {
this.groupid = groupid;
}
}
私のフロントエンドアプリケーションは、私が持っているこの
{adminid: null, name: "dsa", surname: "dsa", email: "d", login: "sada", groupid: "1", active: true}
のように、サーバーに要求を送信見えます新しい管理者を追加しようとすると、groupidプロパティの問題...
WARN 27742 --- [nio-8080-exec-8] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not construct instance of com.patryk.model.Group: no String-argument constructor/factory method to deserialize from String value ('1')
at [Source: [email protected]; line: 1, column: 83] (through reference chain: com.patryk.model.Admin["groupid"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.patryk.model.Group: no String-argument constructor/factory method to deserialize from String value ('1')
at [Source: [email protected]; line: 1, column: 83] (through reference chain: com.patryk.model.Admin["groupid"])
マイコントローラ:
@RestController
@RequestMapping("/api/admins")
public class AdminController {
@Autowired
private AdminService adminService;
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<?> addUser(@RequestBody Admin admin)
{
adminService.save(admin);
return new ResponseEntity<Admin> (admin,HttpStatus.OK);
}
}
どのように解決策を見つけることができますか?誰でも私が間違っていることを知っていますか?