Я создал простой сервис Spring REST (POST, PUT) . Но когда я звоню в эту службу от почтальона, когда значение хранится в null .
Ученик Класса Пойо
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import org.springframework.hateoas.ResourceSupport;
@SuppressWarnings("serial")
@Entity
@Table(schema="fishpool")
public class Student extends ResourceSupport implements Serializable {
@Id @GeneratedValue(strategy=GenerationType.AUTO)
private Long sId;
private String name;
private String email;
public Student() {
}
public Student(Long sId, String name, String email) {
this.sId = sId;
this.name = name;
this.email = email;
}
public Long getsId() {
return sId;
}
public void setsId(Long sId) {
this.sId = sId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Override
public String toString() {
return "Student [sId=" + sId + ", name=" + name + ", email=" + email + "]";
}
}
Класс RestController
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.domain.Student;
import com.example.studentService.StudentSerivce;
@RestController
@RequestMapping(value="/api")
public class StudentController {
@Autowired
private StudentSerivce studentService;
private final static Logger log = LoggerFactory.getLogger(StudentController.class);
public StudentController(final StudentSerivce studentService) {
this.studentService = studentService;
}
@GetMapping("/students")
public List<Student> getAllStudent() {
return studentService.findAllStudent();
}
@GetMapping("/student/{id}")
public Student getStudentById(@PathVariable("id") Long id) {
return studentService.findByStudentId(id);
}
@PostMapping("/createStudent")
public ResponseEntity<Student> createStudent(Student student) {
HttpHeaders headers = new HttpHeaders();
headers.add("Reader", "StudentController");
log.info("Post Create Student : " + student);
return new ResponseEntity<Student>(student, headers, HttpStatus.CREATED);
}
@PutMapping("/updateStudent")
public Student updateStudent(Student student) {
log.info("Put Update Student : " + student);
return studentService.updateStudent(student);
}
@DeleteMapping("/deleteStudent/{id}")
public void deleteStudentById(@PathVariable Long id) {
studentService.deleteByStudentId(id);
}
}
Error.log
2018-07-06 14:31:05.405[0;39m [32m INFO[0;39m [35m20240[0;39m [2m---[0;39m [2m[nio-8080-exec-7][0;39m [36mc.example.controller.StudentController [0;39m [2m:[0;39m Put Update Student : Student [sId=null, name=null, email=null]
[2m2018-07-06 14:31:05.705[0;39m [32mDEBUG[0;39m [35m20240[0;39m [2m---[0;39m [2m[nio-8080-exec-7][0;39m [36morg.hibernate.SQL [0;39m [2m:[0;39m insert into student (email, name) values (?, ?)
Hibernate: insert into student (email, name) values (?, ?)
[2m2018-07-06 14:31:44.984[0;39m [32m INFO[0;39m [35m20240[0;39m [2m---[0;39m [2m[nio-8080-exec-8][0;39m [36mc.example.controller.StudentController [0;39m [2m:[0;39m Post Create Student : Student [sId=null, name=null, email=null]
Я не знаю, где моя ошибка, пожалуйста, найдите мою ошибку и предложите мне. Пожалуйста, помогите мне. Я полностью запутался, где моя ошибка.