我是Spring MVC的新手,我正在构建一个With angularjs和Spring Boot。
当我尝试通过angularjs进行POST调用时,我收到此错误。但是当我尝试使用邮递员时,它正在使用 x-www-form-urlencoding 但使用表单数据,我收到以下错误。
邮递员错误
{
"timestamp": 1491406541851,
"status": 500,
"error": "Internal Server Error",
"exception": "org.springframework.dao.DataIntegrityViolationException",
"message": "PreparedStatementCallback; SQL [INSERT INTO employeedetails(Name, Company, Location,Age) VALUES (?,?,?,?)]; Column 'Name' cannot be null; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'Name' cannot be null",
"path": "/createEmployee"
}
Angularjs 中的 HTTP 调用
$http({
method: 'POST',
url: "/createEmployee",
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
data: $scope.employee,
}).success(function () {});
@RequestMapping(value="/createEmployee", method=RequestMethod.POST,consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public void createEmployee( employeeDetails empl)
{
System.out.println(empl.getAge());
empdao.createEmployee(empl);
}
@RequestMapping(value="/createEmployee", method=RequestMethod.POST,consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public void createEmployee(@RequestBody @Valid employeeDetails empl)
{
System.out.println(empl.getAge());
empdao.createEmployee(empl);
}