在我的spring boot应用程序中,我有以下模型:-
@Entity
@Table(name = "STUDENT")
public class Student {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column
private String name;
@Column
private int mobile;
public Student() {
}
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "DEPT_ID", nullable = false)
private Department department;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getMobile() {
return mobile;
}
public void setMobile(int mobile) {
this.mobile = mobile;
}
public Department getDepartment() {
return department;
}
public void setDepartment(Department department) {
this.department = department;
}
@Override
public String toString() {
return "Student{" +
"id=" + id +
", name='" + name + '\'' +
", mobile=" + mobile +
", department=" + department +
'}';
}
}
@Entity
@Table(name = "DEPARTMENT")
@JsonIdentityInfo(
generator = ObjectIdGenerators.PropertyGenerator.class,
property = "id")
public class Department {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column
private String name;
public Department() {
}
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
@OneToMany(mappedBy = "department", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private List<Student> studentList = new ArrayList<>();
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<Student> getStudentList() {
return studentList;
}
public void setStudentList(List<Student> studentList) {
this.studentList = studentList;
}
}
@RestController
public class StudentController {
@Autowired
StudentService studentService;
@Autowired
DepartmentService departmentService;
@RequestMapping(value = "/studentList", method = RequestMethod.GET)
public @ResponseBody
List<Student> getStudents(){
return studentService.getStudents();
}
@PostMapping("/saveStudent/{deptName}")
public String saveStudent(@RequestBody List<Student> studentList, @PathVariable String deptName){
try {
Department dept = departmentService.findDepartment(deptName.toUpperCase());
for(Student student: studentList)
student.setDepartment(dept);
studentService.saveStudent(studentList);
return "Student saved successfully..";
}catch (Exception ex){
ex.printStackTrace();
return "Error in saving Student ..";
}
}
}
{
"student": [{ "name": "masi",
"mobile": 12345,
"department": "hr"
}, { "name": "masi2",
"mobile": 1234500,
"department": "hr"
}]
}
邮递员控制台日志:-
POST http://localhost:8080 /saveStudent/hr
400
183 ms
Network
Request Headers
Content-Type: application/json
User-Agent: PostmanRuntime/7.26.1
Accept: */*
Cache-Control: no-cache
Postman-Token: 57071c5d-e416-4b54-870a-9f318fee7166
Host: localhost:8080
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 160
Request Body
Response Headers
Content-Type: application/json
Transfer-Encoding: chunked
Date: Wed, 15 Jul 2020 09:05:43 GMT
Connection: close
Response Body
{"timestamp":"2020-07-15T09:05:43.864+00:00","status":400,"error":"Bad Request","message":"","path":"/saveStudent/hr"}
我认为我的应用程序工作正常。我如何通过邮差或curl发出正确的JSON请求?
不应像下面这样在后体使用中添加student
[
{
"name": "masi",
"mobile": 12345,
"department": {
"field":"value"
}
},
{
"name": "masi2",
"mobile": 1234500,
"department": {
"field":"value"
}
}
]
我不知道department类的字段,请相应编辑
我有一个生成屏幕截图的类: 我的应用程序是用创建的,我需要对它进行测试。但我得到 我的测试: 我试图防止无头异常: 我使用的是spring启动版本1.5.6。 但这无济于事。我得到日志: java.awt.HeadlessException在sun.awt.HeadlesStoolKit.GetScreenSize(headlesStoolKit.java:284)在org.robinhood.i
嗨,我有一个角色表和一个权限表,它有多对多的关系。我已经创建了下面链接中提到的实体 https://www.baeldung.com/jpa-多对多 角色实体 权限实体 我已经为每个实体创建了JPA存储库,并且正在尝试将权限保存给一个角色。我在表中已经有了一组/列表的权限,我正在尝试将它们映射到某个角色。我正在尝试使用spring JPA存储库执行下面的代码。 在执行我得到的代码时 org.hib
我们有一个 REST 服务,它接受包含保存 的 POST 请求。在 REST 服务中,可能会根据提供的数据创建一个文件。 我们希望对基于其<code>多部分 然而,问题在于从REST客户端发送的MultiPart与REST服务器接收的不同,因为球衣可能会对数据进行一些处理以对其进行流式传输或其他操作。尝试测试(见下文)以下设置将导致 (只是片段,我省略了显而易见的东西): Rest: 服务器端Mu
本文向大家介绍请问如何对登录界面进行测试相关面试题,主要包含被问及请问如何对登录界面进行测试时的应答技巧和注意事项,需要的朋友参考一下 参考回答: 黑盒测试方法 输入正确用户名和密码,验证是否登陆成功 输入正确的用户名和错误的密码,验证是否登陆失败并且提示信息正确 输入未注册的用户名和任意的密码,验证是否登陆失败并且提示信息正确 用户名和密码都为空,验证是否登陆失败并且提示信息正确 用户名和密码两
本文向大家介绍请你说一下如何写测试用例相关面试题,主要包含被问及请你说一下如何写测试用例时的应答技巧和注意事项,需要的朋友参考一下 参考回答: 1、测试人员尽早介入,彻底理解清楚需求,这个是写好测试用例的基础 2、如果以前有类似的需求,可以参考类似需求的测试用例,然后还需要看类似需求的bug情况 3、清楚输入、输出的各种可能性,以及各种输入的之间的关联关系,理解清楚需求的执行逻辑,通过等价类、边界
问题内容: 在AJAX请求之后,有时我的应用程序可能返回一个空对象,例如: 如何检查情况呢? 问题答案: ECMA 5+: Note, though, that this creates an unnecessary array (the return value of keys). Pre-ECMA 5: jQuery: lodash: Underscore: Hoek ExtJS Angula