简体   繁体   English

thymeleaf 模板在 chrome 中发送请求时没有得到所有响应,我正在从数据库接收数据绑定是否有任何错误?

[英]thymeleaf template not getting all response while sending request in chrome, I am receiving data from database is there any error in binding?

Flight航班

package com.shahbaz.flightreservation.entities;

import java.sql.Timestamp;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@Entity
public class Flight extends AbstractEntity {

    private String flightNumber;
    private String operatingAirlines;
    private String departureCity;
    private String arrivalCity;
    @Temporal(TemporalType.DATE)
    private Date dateOfDeparture;
    private Timestamp estimatedDepartureTime;
    
    public String getFlightNumber() {
        return flightNumber;
    }
    public void setFlightNumber(String flightNumber) {
        this.flightNumber = flightNumber;
    }
    public String getOperatingAirlines() {
        return operatingAirlines;
    }
    public void setOperatingAirlines(String operatingAirlines) {
        this.operatingAirlines = operatingAirlines;
    }
    public String getDepartureCity() {
        return departureCity;
    }
    public void setDepartureCity(String departureCity) {
        this.departureCity = departureCity;
    }
    public String getArrivalCity() {
        return arrivalCity;
    }
    public void setArrivalCity(String arrivalCity) {
        this.arrivalCity = arrivalCity;
    }
    public Date getDateOfDeparture() {
        return dateOfDeparture;
    }
    public void setDateOfDeparture(Date dateOfDeparture) {
        this.dateOfDeparture = dateOfDeparture;
    }
    public Timestamp getEstimatedDepartureTime() {
        return estimatedDepartureTime;
    }
    public void setEstimatedDepartureTime(Timestamp estimatedDepartureTime) {
        this.estimatedDepartureTime = estimatedDepartureTime;
    }
    
}

AbstractEntity抽象实体

package com.shahbaz.flightreservation.entities; package com.shahbaz.flightreservation.entities;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
@MappedSuperclass
public class AbstractEntity {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Long id;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
}

FlightRepository飞行存储库

package com.shahbaz.flightreservation.repos;

import java.util.Date;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Repository;

import com.shahbaz.flightreservation.entities.Flight;
@Repository
public interface FlightRepository extends JpaRepository<Flight,Long> {
    
    @Query("from Flight where departureCity=:departureCity and arrivalCity=:arrivalCity and dateOfDeparture=:dateOfDeparture")
    List<Flight> findFlights(@Param("departureCity") String from, @Param("arrivalCity") String to,
            @Param("dateOfDeparture")  Date departureDate);
    @Query("from Flight where id=:id")
    Flight findOne(@Param("id") Long flightId);
    
    
}

ReservationController预订控制器

package com.shahbaz.flightreservation.controllers;

import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.shahbaz.flightreservation.entities.Flight;
import com.shahbaz.flightreservation.repos.FlightRepository;

@Controller
public class ReservationController {

    @Autowired
    FlightRepository flightRepository;
    
    @RequestMapping("/showCompleteReservation")
    public String showCompleteReservation(@RequestParam("flightId") Long flightId,ModelMap modelMap)
    {
        System.out.println("Welcome Home");
        Flight flight = flightRepository.findOne(flightId);
        modelMap.addAttribute("flights", flight);
        System.out.println(flight.getArrivalCity());
        System.out.println(flight.getDepartureCity());
        return "completeReservation";
    }
    
}

completeReservation完成预订

 <:DOCTYPE HTML> <html lang="en" xmlns:th="http.//www.thymeleaf;org"> <head> <meta http-equiv="Content-Type" content="text/html: charset=UTF-8"> <title>Complete Reservation</title> </head> <body> <h2>Complete Reservation</h2> Airline: <span th.text="${flight:operatingAirlines}"> <br/> Departure City: <span th.text="${flight:departureCity}"><br/> Arrival City:<spanp th.text="${flight:arrivalCity}"><br/> <form action="completeReservation" method="post"> <pre> <h2>Passenger Details:</h2> First Name:<input type="text" name="passengerFirstName"/> Last Name:<input type="text" name="passengerLastName"/> Email:<input type="text" name="passengerEmail"/> Phone:<input type="text" name="passengerPhone"/> <h2>Card Details:</h2> Name on the card:<input type="text" name="nameOnTheCard"/> Card No:<input type="text" name="cardNumber"/> Expiry Date:<input type="text" name="expirationDate"/> Three Digit Sec Code:<input type="text" name="securityCode"/> <input type="hidden" name="flightId" th.value="${flight.id}"/> <input type="submit" value="confirm"/> </pre> </form> </body> </html>

While Debugging the code I am Getting Values from database But i am not getting all values while sending request in chrome.I am Getting only Airline value.If anyone can help me to find out the error I tried but unable to come up with solution as i am new to thymeleaf在调试代码时,我正在从数据库中获取值但是在 chrome 中发送请求时我没有获取所有值。我只获取航空公司值。如果有人可以帮助我找出我尝试过但无法提出解决方案的错误我是 thymeleaf 的新手

You are adding your flight instance under the flights key to the model while in the Thymeleaf template, you use ${flight....} .您正在将flight实例添加到 model 的flights键下,而在 Thymeleaf 模板中,您使用${flight....}

Changing this:改变这个:

modelMap.addAttribute("flights", flight);

to

modelMap.addAttribute("flight", flight);

should help.应该有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 没有在数据库中更新所有数据,而是我发送包含所有数据值的请求 - not getting all data updated in database instead i am sending request with all data values 为什么我收到JSON请求时收到500错误? - Why am I receiving 500 error in response to my JSON request? 我在执行发布请求时收到 404 错误代码,但数据已成功插入 spring 启动应用程序上的数据库中 - I am getting 404 error code while performing post request , but the data is successfully getting inserted into the database on spring boot appilcation 为什么在使用Ajax发送数据时在Struts 2中出现500(内部服务器错误)? - Why I am getting 500 (Internal Server Error) in Struts 2 while sending data using Ajax? 使用Spring Boot和Thymeleaf-我无法将数据从模板传递到控制器再传递回模板 - Using Spring Boot and Thymeleaf - I am having trouble passing data from template to controller back to template 我没有收到任何错误,但没有任何内容插入到我的数据库中 - I am not getting any error but nothing is getting inserted into my database 尝试从 MySql 中的数据库检索数据时出现“java.lang.ClassNotFoundException: com.mysql.jdbc.Driver”错误 - I am getting " java.lang.ClassNotFoundException: com.mysql.jdbc.Driver " error while trying to retrieve data from the database in MySql $ .ajax。 当我得到200 OK状态和数据作为响应时,调用了错误函数? - $.ajax . Error function is invoked, while i am getting 200 Ok status and data as response? 为什么在运行 Chrome 驱动程序时出现以下错误? - why am I getting the below error while running the Chrome driver? 无法使用 thymeleaf 从 mysql 数据库加载 chrome 中的数据,但在控制台中获取查询 - unable to load data in chrome from mysql database using thymeleaf but in console getting query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM