mercredi 11 décembre 2019

Execute if-else condition injsp

I want to execute the if else condition that I have tested in my controller to my jsp page. I have written the following code

@RequestMapping(value="/displayFlight" ,method=RequestMethod.POST)
public String findFlight(@RequestParam("from")String from, @RequestParam("to")String to 
        ,@RequestParam("departureDate") @DateTimeFormat(pattern="dd/MM/yyyy") Date departureDate
        ,@RequestParam("no_of_passenger")String no_of_passenger
        ,ModelMap modelMap) {

    logger.info("Inside findFlights() From:" + from + " TO:" + to + "Departure Date: " + departureDate +no_of_passenger +"no. of passenger");
    List<Flight> flights=flightRepository.findFlight(from, to, departureDate,no_of_passenger);
    System.out.println(flights.size());
    if(flights.size()==0) {
        modelMap.addAttribute("msg", "There is no flight scheduled for that particular date !!");
    }else {
        modelMap.addAttribute("flights", flights);
    }
    logger.info("Flights found are"+flights.toString());
    return "displayFlight";

I have the basic idea of how we did it in thymeleaf <div th:if="${msg}" th:text="${msg}" ></div>

But I am not sure how can we do it in jsp

Aucun commentaire:

Enregistrer un commentaire