I'm currently working on a project that involves using Angular 2 on the client side and Spring on the server side. I need to send user input data from the client to the server and receive a response back. However, I'm encountering an issue where the 'loginDetailsDTO' is coming up as null on the server side.
If anyone has any suggestions on how to resolve this issue, please let me know. Your help would be greatly appreciated!
Thank you in advance for any assistance provided.
Below you can find a sample of the code snippets involved:
user.component.ts
import { UserService } from './user.service';
import { UserLogin } from './userLogin';
login(value: UserLogin) {
this.UserService.login(value)
.subscribe(data => console.log(data));
}
user.service.ts
import { UserLogin } from './userLogin';
login(loginDetails: UserLogin) {
return this.http
.get(this.loginUrl, JSON.stringify(loginDetails))
.map(res => res.json());
}
userLogin.ts
export class UserLogin {
userName: string;
password: string;
}
userController.java
@RequestMapping(value = "/login", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<LoginResponse> login(LoginDetailsDTO loginDetailsDTO){
LoginResponse loginResponse = new LoginResponse();
loginResponse.setResponseCode(LoginResponse.VALID_USER);
return new ResponseEntity<LoginResponse>(loginResponse, HttpStatus.OK);
}
LoginDetailsDTO.java
public class LoginDetailsDTO {
private String userName;
private String password;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}