Однако в настоящее время контроллеры принимают тело следующим образом:
Код: Выделить всё
@RestController
public class HelloController {
@PostMapping("/coolendpointTWO")
public String withRequestBody(@RequestBody MyPojo myPojo) {
System.out.println("received object" + myPojo);
//handle myPojo with my business logic
String ip = ""; //How to get the IP, since I am not using ServerRequest
return "good: " + ip;
}
}
Я понимаю, что эта конструкция позволит получить request.remoteAddress().
Код: Выделить всё
@RestController
public class HelloServerRequestController {
@PostMapping("/coolendpointONE")
public String withServerRequest(ServerRequest request) throws ServletException, IOException {
MyPojo myPojo = request.body(MyPojo.class);
System.out.println("received object" + myPojo);
//handle myPojo with my business logic
String ip = request.remoteAddress().map(InetSocketAddress::getAddress).map(InetAddress::getHostAddress).orElse("0");
return "Message sent: " + ip;
}
}
Вопрос:
Сохраняя подпись
р>
Код: Выделить всё
@PostMapping("/coolendpointTWO")
public String withRequestBody(@RequestBody MyPojo myPojo) {
Подробнее здесь: https://stackoverflow.com/questions/792 ... -web-servl
Мобильная версия