I started learning spring boot and I ran into problems. I have the following code:
@RestController
public class UserController {
@RequestMapping("/")
public String getMessageInfo(Message message) {
return "Id is " + message.getId() + ", message is " + message.getMessage() + ", parameter good is " + message.isGood();
}
}
Post class:
public class Message {
private String message;
private int id;
private boolean good;
public Message() {}
public Message(int id) {this.id = id;}
public Message(String message) {this.message = message;}
public Message(boolean good) {this.good = good;}
public Message(String message, boolean good, int id) {
this.message = message;
this.good = good;
this.id = id;
}
public String getMessage() {
return message;
}
public int getId() {
return id;
}
public boolean isGood() {
return good;
}
}
And when I try to do something like this:
RestTemplate request = new RestTemplate();
String info = request.getForObject("http://localhost:8080/?id=4", String.class);
value is idignored. The same problem occurs when I send a request using a boolean parameter good(e.g. localhost:8080/?good=true). It is called the default constructor instead of Message(boolean)/ Message(int). But when I do something like localhost:8080/?message=1234, it is not ignored. Could you explain to me what the problem is?
And one more question: is it possible to send an instance of a class Messagein a getMessageInfodifferent way than localhost:8080/?message=1234&good=true&id=145? If I have more than 3 parameters? For example, if a class Messagehas 100 parameters?