Good evening. I am trying to send the user object from the frontend to the spring controller. For some reason, the error 400 crashes (Bad Request). My service:
service.createUser = function (user) { console.log("Service. Creating user ",user); return http({ method: 'GET', url: '/user/createUser', contentType: 'application/json', data: {user: user} }) };
frontend user (filled with data. 1-2 roles):
$scope.user = { firstName: "", lastName: "", email: "", password: "", roles: [] };
Spring Controller:
@RestController @RequestMapping("/user") public class UserController { @RequestMapping(value = "/createUser", method = RequestMethod.GET) public boolean createUser(@RequestBody UserDTO userDTO) { System.out.println(userDTO); return true; }}
Userdto
public class UserDTO { private Long id; private String email; private String firstName; private String lastName; private String password; private List<Role> roles; //getters and setters }
Please tell me how to fix it. Thank.
UPD:
Corrected the situation by adding .csrf (). Disable () to the spring security configuration. Now there is another error. The object for some reason comes empty (the fields are not initialized), although it is full before being sent to the console.
UPDT 2: The problem was that in the userdto field of roles there was a Role interface and not its implementation of RoleImpl.