我正在尝试测试端点,但收到400错误的请求错误 说明:由于某些被认为是客户端错误的原因(例如格式错误的请求语法,无效的请求消息框架或欺骗性的请求路由),服务器无法或不会处理该请求。
我正在使用spring,hibernate和JPA。
我感觉好像我在看东西,我需要另一双眼睛。
我正在邮递员中传递此信息:
{
"macAddress":{
"userId": 43,
"username": "username",
"password": "password",
"firstName": "firstname",
"lastName": "lastname",
"macAddress": "macaddress"},
"ssid": "ssid",
"ssidPassword": "ssidpassword"
}
RDKAcces.java:
@Entity
@Table(name="RDKAccess", schema="db")
public class RDKAccess implements Serializable {
private static final long serialVersionUID = 1L;
@JoinColumn(name="MAC_Address")
@OneToOne
@Id
private User macAddress;
@Column(name="SSID")
private String ssid;
@Column(name="SSID_Password")
private String ssidPassword;
public RDKAccess(User macAddress, String ssid, String ssidPassword) {
super();
this.macAddress = macAddress;
this.ssid = ssid;
this.ssidPassword = ssidPassword;
}
...
User.java:
@Entity
@Table(name="User", schema="db", uniqueConstraints = {@UniqueConstraint(columnNames= "Username")})
public class User implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name="User_Id")
private Integer userId;
@Column(name="Username", unique=true)
private String username;
@Column(name="Password")
private String password;
@Column(name="First_Name")
private String firstName;
@Column(name="Last_Name")
private String lastName;
@Column(name="MAC_Address", unique=true)
private String macAddress;
@OneToMany(mappedBy = "guestId", fetch = FetchType.EAGER)
private Set<Reservation> guestReservations = new HashSet<>();
@OneToMany(mappedBy= "hostId", fetch = FetchType.EAGER)
private Set<Reservation> hostReservations = new HashSet<>();
@OneToOne(mappedBy="macAddress", fetch = FetchType.EAGER)
private RDKAccess userMAC;
public User(Integer userId, String username, String password, String firstName, String lastName, String macAddress,
Set<Reservation> guestReservations, Set<Reservation> hostReservations) {
super();
this.userId = userId;
this.username = username;
this.password = password;
this.firstName = firstName;
this.lastName = lastName;
this.macAddress = macAddress;
this.guestReservations = guestReservations;
this.hostReservations = hostReservations;
}
....
RDKAccessController.java
@Controller
@RequestMapping("/RDK")
@CrossOrigin(origins="*", allowedHeaders="*", value="*")
public class RDKAccessController {
@Autowired
RDKAccessService rdkServ;
@PostMapping(value="/add")
@ResponseBody
public void add(@RequestBody RDKAccess access) {
rdkServ.add(access);
}
...
我想做的是使用ssid和ssidpassword将macaddress添加到数据库中的表中(该Mac Address应该与用户传递的信息具有一对一的关系,但这不起作用如果可以帮助您,请在此处找到该问题Can I map a single column to two tables at one time?的链接)。
我只希望能够将这些值传递到我的数据库中,却无法弄清楚通话中出了什么问题。