I'm creating an endpoint with path variable and request params. How do I combine both path variable and request params into a single object? I'm using springboot 2 with java 8
@RequestMapping(path = "/schedules")
public class SchedulesController {
@GetMapping("/{area}/{subarea}")
public MyObject getFlight(@PathVariable("area") String area, @PathVariable("subarea") String subarea,
MyModel model) {
...
return new MyObject();
}
}
@Data
public class MyModel {
LocalDate datestamp,
String leadName,
String viceLeadName
}
I've looked at the spring documentation and I can't seems to find how to combine PathVariable into MyModel.
Here is my controller without the object.
@RequestMapping(path = "/schedules")
public class SchedulesController {
@GetMapping("/{area}/{subarea}")
public MyObject getFlight(@PathVariable("area") String area, @PathVariable("subarea") String subarea,
@RequestParam(value = "datestamp", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate datestamp,
@RequestParam(value = "leadName", required = false) String leadName,
@RequestParam(value = "viceLeadName", required = false) String viceLeadName) {
...
return new MyObject();
}
}
Is it possible to do the following? Where the path variables and request params are in MyModel object?
@RequestMapping(path = "/schedules")
public class SchedulesController {
@GetMapping("/{area}/{subarea}")
public MyObject getFlight(MyModel model) {
...
return new MyObject();
}
}
@Data
public class MyModel {
String area,
String subArea,
LocalDate datestamp,
String leadName,
String viceLeadName
}