I am sending following request that need to be handled by Spring-MVC but it does not.
http://localhost:2001/MyProject/flights/find?origin=LAX&destination=WA&departure=&arrival=&return=false
Code
@Controller
@RequestMapping("/flights")
public class FlightController {
@RequestMapping(value = "/find?origin={origin}&destination={destination}&departure={departure}&arrival={arrival}&return={return}", method = RequestMethod.GET)
public String findFlight(@PathVariable String origin,
String destination, Date departure, Date arrival, boolean return) {
That is not the correct way (or place) to use @PathVariable
. You need to use @RequestParam
.
@Controller
@RequestMapping("/flights")
public class FlightController {
@RequestMapping("/find")
public String findFlight(@RequestParam String origin
, @RequestParam String destination
, @RequestParam(required = false) Date departure
, @RequestParam(required = false) Date arrival
, @RequestParam(defaultValue = "false", required = false, value = "return") Boolean ret) { ... }
}
Note that return
is a keyword in Java so you cannot use it as a method parameter name.
You will also have to add a java.beans.PropertyEditor
for reading the dates because the dates will (presumably) be in a specific format.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With