I want to create a simple spring boot application, where it takes in form of JSON and compares the input with given credential, i.e, username:1111 and password:1 . But I am not able to compare the input value to the above mentioned values.
//Controller class//
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.models.Login_object;
@RestController
public class AppController {
@PostMapping(path="/login")
String login(@RequestBody Login_object login_credential) {
if(login_credential.getUsername()=="1111" && login_credential.getPassword()=="1") {
return "welcome";
}
else {
return "you entered:"+login_credential.getUsername()+":"+login_credential.getPassword();
}
}
}
//Login_object class//
public class Login_object {
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;
}
}
The result should be: Welcome. But here I am not getting the expected output.