Init
This commit is contained in:
commit
35ec24f344
29
.gitignore
vendored
Normal file
29
.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
### IntelliJ IDEA ###
|
||||||
|
out/
|
||||||
|
!**/src/main/**/out/
|
||||||
|
!**/src/test/**/out/
|
||||||
|
.idea
|
||||||
|
### Eclipse ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
bin/
|
||||||
|
!**/src/main/**/bin/
|
||||||
|
!**/src/test/**/bin/
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
### Mac OS ###
|
||||||
|
.DS_Store
|
24
JavaWeb-Flight-System.iml
Normal file
24
JavaWeb-Flight-System.iml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="FacetManager">
|
||||||
|
<facet type="web" name="Web">
|
||||||
|
<configuration>
|
||||||
|
<descriptors>
|
||||||
|
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/web/WEB-INF/web.xml" />
|
||||||
|
</descriptors>
|
||||||
|
<webroots>
|
||||||
|
<root url="file://$MODULE_DIR$/web" relative="/" />
|
||||||
|
</webroots>
|
||||||
|
</configuration>
|
||||||
|
</facet>
|
||||||
|
</component>
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="libs" level="project" />
|
||||||
|
</component>
|
||||||
|
</module>
|
BIN
libs/commons-lang3-3.12.0.jar
Normal file
BIN
libs/commons-lang3-3.12.0.jar
Normal file
Binary file not shown.
BIN
libs/jakarta.servlet.jsp.jstl-2.0.0.jar
Normal file
BIN
libs/jakarta.servlet.jsp.jstl-2.0.0.jar
Normal file
Binary file not shown.
BIN
libs/jakarta.servlet.jsp.jstl-api-2.0.0.jar
Normal file
BIN
libs/jakarta.servlet.jsp.jstl-api-2.0.0.jar
Normal file
Binary file not shown.
BIN
libs/mysql-connector-j-8.0.31.jar
Normal file
BIN
libs/mysql-connector-j-8.0.31.jar
Normal file
Binary file not shown.
BIN
libs/servlet-api.jar
Normal file
BIN
libs/servlet-api.jar
Normal file
Binary file not shown.
174
src/com/landaiqing/dao/FlightDao.java
Normal file
174
src/com/landaiqing/dao/FlightDao.java
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
package com.landaiqing.dao;
|
||||||
|
|
||||||
|
import com.landaiqing.entity.FlightEntity;
|
||||||
|
import com.landaiqing.utils.JDBCUtil;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class FlightDao {
|
||||||
|
/*
|
||||||
|
* 查询所有的航班信息
|
||||||
|
* */
|
||||||
|
public List<FlightEntity> getByAll() {
|
||||||
|
Connection connection = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
try {
|
||||||
|
connection = JDBCUtil.getConnection();
|
||||||
|
preparedStatement = connection.prepareStatement("select * from flight where is_delete=0;");
|
||||||
|
resultSet = preparedStatement.executeQuery();
|
||||||
|
ArrayList<FlightEntity> flightEntities = new ArrayList<>();
|
||||||
|
while (resultSet.next()) {
|
||||||
|
Integer id = resultSet.getInt("id");
|
||||||
|
String flightId = resultSet.getString("flight_id");
|
||||||
|
String company = resultSet.getString("company");
|
||||||
|
String departureAirport = resultSet.getString("departure_airport");
|
||||||
|
String arriveAirport = resultSet.getString("arrive_airport");
|
||||||
|
Date departureTime = resultSet.getDate("departure_time");
|
||||||
|
Date arriveTime = resultSet.getDate("arrive_time");
|
||||||
|
String model = resultSet.getString("model");
|
||||||
|
Integer isDelete = resultSet.getInt("is_delete");
|
||||||
|
FlightEntity flightEntity = new FlightEntity(id, flightId, company, departureAirport, arriveAirport, departureTime, arriveTime, model, isDelete);
|
||||||
|
flightEntities.add(flightEntity);
|
||||||
|
}
|
||||||
|
return flightEntities;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} finally {
|
||||||
|
JDBCUtil.closeConnection(resultSet, preparedStatement, connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public int deleteFlghtById(Integer id) {
|
||||||
|
Connection connection = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
try {
|
||||||
|
connection = JDBCUtil.getConnection();
|
||||||
|
JDBCUtil.beginTransaction(connection);
|
||||||
|
preparedStatement = connection.prepareStatement("delete from flight where id=?;");
|
||||||
|
preparedStatement.setInt(1, id);
|
||||||
|
Integer result = preparedStatement.executeUpdate();
|
||||||
|
JDBCUtil.commitTransaction(connection);
|
||||||
|
return result;
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
JDBCUtil.rollBackTransaction(connection);
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
JDBCUtil.closeConnection(null, preparedStatement, connection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public FlightEntity getByIdFlight(Integer id) {
|
||||||
|
|
||||||
|
Connection connection = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
try {
|
||||||
|
connection = JDBCUtil.getConnection();
|
||||||
|
preparedStatement = connection.prepareStatement("select * from flight where id=?;");
|
||||||
|
preparedStatement.setInt(1, id);
|
||||||
|
resultSet = preparedStatement.executeQuery();
|
||||||
|
if (!resultSet.next()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Integer dbId = resultSet.getInt("id");
|
||||||
|
String flightId = resultSet.getString("flight_id");
|
||||||
|
String company = resultSet.getString("company");
|
||||||
|
String departureAirport = resultSet.getString("departure_airport");
|
||||||
|
String arriveAirport = resultSet.getString("arrive_airport");
|
||||||
|
Date departureTime = resultSet.getDate("departure_time");
|
||||||
|
Date arriveTime = resultSet.getDate("arrive_time");
|
||||||
|
String model = resultSet.getString("model");
|
||||||
|
Integer isDelete = resultSet.getInt("is_delete");
|
||||||
|
FlightEntity flightEntity = new FlightEntity(dbId, flightId, company, departureAirport, arriveAirport, departureTime, arriveTime, model, isDelete);
|
||||||
|
|
||||||
|
return flightEntity;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} finally {
|
||||||
|
JDBCUtil.closeConnection(resultSet, preparedStatement, connection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int updateFlight(FlightEntity flightEntity){
|
||||||
|
Connection connection = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
try {
|
||||||
|
connection = JDBCUtil.getConnection();
|
||||||
|
JDBCUtil.beginTransaction(connection);
|
||||||
|
preparedStatement = connection.prepareStatement("UPDATE `testdb`.`flight` SET `flight_id` = ?, `company` = ?, `departure_airport` = ?, `arrive_airport` = ?, `departure_time` = ?, `arrive_time` = ?, `model` = ?, `is_delete` = '0' WHERE `id` = ?;");
|
||||||
|
preparedStatement.setString(1,flightEntity.getFlightId());
|
||||||
|
preparedStatement.setString(2,flightEntity.getCompany());
|
||||||
|
preparedStatement.setString(3,flightEntity.getDepartureAirport());
|
||||||
|
preparedStatement.setString(4,flightEntity.getArriveAirport());
|
||||||
|
preparedStatement.setDate(5, new Date(flightEntity.getDepartureTime().getTime()));
|
||||||
|
preparedStatement.setDate(6, new Date(flightEntity.getArriveTime().getTime()));
|
||||||
|
preparedStatement.setString(7,flightEntity.getModel());
|
||||||
|
preparedStatement.setInt(8,flightEntity.getId());
|
||||||
|
Integer result = preparedStatement.executeUpdate();
|
||||||
|
JDBCUtil.commitTransaction(connection);
|
||||||
|
return result;
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
JDBCUtil.rollBackTransaction(connection);
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
JDBCUtil.closeConnection(null, preparedStatement, connection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int insertFlight(FlightEntity flightEntity){
|
||||||
|
Connection connection = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
try {
|
||||||
|
connection = JDBCUtil.getConnection();
|
||||||
|
JDBCUtil.beginTransaction(connection);
|
||||||
|
preparedStatement = connection.prepareStatement("INSERT INTO `testdb`.`flight` (`id`, `flight_id`, `company`, `departure_airport`, `arrive_airport`, `departure_time`, `arrive_time`, `model`, `is_delete`) VALUES (null, ?, ?, ?, ?, ?, ?, ?, '0');");
|
||||||
|
preparedStatement.setString(1,flightEntity.getFlightId());
|
||||||
|
preparedStatement.setString(2,flightEntity.getCompany());
|
||||||
|
preparedStatement.setString(3,flightEntity.getDepartureAirport());
|
||||||
|
preparedStatement.setString(4,flightEntity.getArriveAirport());
|
||||||
|
preparedStatement.setDate(5, new Date(flightEntity.getDepartureTime().getTime()));
|
||||||
|
preparedStatement.setDate(6, new Date(flightEntity.getArriveTime().getTime()));
|
||||||
|
preparedStatement.setString(7,flightEntity.getModel());
|
||||||
|
// preparedStatement.setInt(8,flightEntity.getId());
|
||||||
|
Integer result = preparedStatement.executeUpdate();
|
||||||
|
JDBCUtil.commitTransaction(connection);
|
||||||
|
return result;
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
JDBCUtil.rollBackTransaction(connection);
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
JDBCUtil.closeConnection(null, preparedStatement, connection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int updateDelete(Integer id){
|
||||||
|
Connection connection = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
try {
|
||||||
|
connection = JDBCUtil.getConnection();
|
||||||
|
JDBCUtil.beginTransaction(connection);
|
||||||
|
preparedStatement = connection.prepareStatement("UPDATE `testdb`.`flight` SET `is_delete` = ? WHERE `id` = ?;");
|
||||||
|
preparedStatement.setInt(1,1);
|
||||||
|
preparedStatement.setInt(2,id);
|
||||||
|
Integer result = preparedStatement.executeUpdate();
|
||||||
|
JDBCUtil.commitTransaction(connection);
|
||||||
|
return result;
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
JDBCUtil.rollBackTransaction(connection);
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
JDBCUtil.closeConnection(null, preparedStatement, connection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
117
src/com/landaiqing/entity/FlightEntity.java
Normal file
117
src/com/landaiqing/entity/FlightEntity.java
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
package com.landaiqing.entity;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class FlightEntity {
|
||||||
|
/*
|
||||||
|
* CREATE TABLE `flight` (
|
||||||
|
`id` int NOT NULL AUTO_INCREMENT COMMENT 'id列',
|
||||||
|
`flight_id` varchar(20) DEFAULT NULL COMMENT '航班号',
|
||||||
|
`company` varchar(255) DEFAULT NULL COMMENT '航空公司',
|
||||||
|
`departure_airport` varchar(255) DEFAULT NULL COMMENT '出发机场',
|
||||||
|
`arrive_airport` varchar(255) DEFAULT NULL COMMENT '到达机场',
|
||||||
|
`departure_time` datetime DEFAULT NULL COMMENT '出发时间',
|
||||||
|
`arrive_time` datetime DEFAULT NULL COMMENT '到达时间',
|
||||||
|
`model` varchar(255) DEFAULT NULL COMMENT '机型',
|
||||||
|
`is_delete` varchar(255) DEFAULT NULL COMMENT '是否隐藏0显示1隐藏',
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
||||||
|
* */
|
||||||
|
private Integer id;
|
||||||
|
private String flightId;
|
||||||
|
|
||||||
|
private String company;
|
||||||
|
private String departureAirport;
|
||||||
|
private String arriveAirport;
|
||||||
|
private Date departureTime;
|
||||||
|
private Date arriveTime;
|
||||||
|
private String model;
|
||||||
|
private Integer isDelete;
|
||||||
|
|
||||||
|
public FlightEntity(){
|
||||||
|
|
||||||
|
}
|
||||||
|
public FlightEntity(Integer id, String flightId, String company, String departureAirport, String arriveAirport, Date departureTime, Date arriveTime, String model, Integer isDelete) {
|
||||||
|
this.id = id;
|
||||||
|
this.flightId = flightId;
|
||||||
|
this.company = company;
|
||||||
|
this.departureAirport = departureAirport;
|
||||||
|
this.arriveAirport = arriveAirport;
|
||||||
|
this.departureTime = departureTime;
|
||||||
|
this.arriveTime = arriveTime;
|
||||||
|
this.model = model;
|
||||||
|
this.isDelete = isDelete;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFlightId() {
|
||||||
|
return flightId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFlightId(String flightId) {
|
||||||
|
this.flightId = flightId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCompany() {
|
||||||
|
return company;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCompany(String company) {
|
||||||
|
this.company = company;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDepartureAirport() {
|
||||||
|
return departureAirport;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDepartureAirport(String departureAirport) {
|
||||||
|
this.departureAirport = departureAirport;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getArriveAirport() {
|
||||||
|
return arriveAirport;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setArriveAirport(String arriveAirport) {
|
||||||
|
this.arriveAirport = arriveAirport;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDepartureTime() {
|
||||||
|
return departureTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDepartureTime(Date departureTime) {
|
||||||
|
this.departureTime = departureTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getArriveTime() {
|
||||||
|
return arriveTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setArriveTime(Date arriveTime) {
|
||||||
|
this.arriveTime = arriveTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getModel() {
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setModel(String model) {
|
||||||
|
this.model = model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getIsDelete() {
|
||||||
|
return isDelete;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsDelete(Integer isDelete) {
|
||||||
|
this.isDelete = isDelete;
|
||||||
|
}
|
||||||
|
}
|
29
src/com/landaiqing/service/FlightService.java
Normal file
29
src/com/landaiqing/service/FlightService.java
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package com.landaiqing.service;
|
||||||
|
|
||||||
|
import com.landaiqing.dao.FlightDao;
|
||||||
|
import com.landaiqing.entity.FlightEntity;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class FlightService {
|
||||||
|
private FlightDao flightDao= new FlightDao();
|
||||||
|
public List<FlightEntity> getByAll() {
|
||||||
|
return flightDao.getByAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int deleteFlghtById(Integer id) {
|
||||||
|
return flightDao.deleteFlghtById(id);
|
||||||
|
}
|
||||||
|
public FlightEntity getByIdFlight(Integer id) {
|
||||||
|
return flightDao.getByIdFlight(id);
|
||||||
|
}
|
||||||
|
public int updateFlight(FlightEntity flightEntity){
|
||||||
|
return flightDao.updateFlight(flightEntity);
|
||||||
|
}
|
||||||
|
public int insertFlight(FlightEntity flightEntity){
|
||||||
|
return flightDao.insertFlight(flightEntity);
|
||||||
|
}
|
||||||
|
public int updateDelete(Integer id){
|
||||||
|
return flightDao.updateDelete(id);
|
||||||
|
}
|
||||||
|
}
|
45
src/com/landaiqing/servlet/DeleteFlightServlet.java
Normal file
45
src/com/landaiqing/servlet/DeleteFlightServlet.java
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
package com.landaiqing.servlet;
|
||||||
|
|
||||||
|
import com.landaiqing.service.FlightService;
|
||||||
|
import jakarta.servlet.ServletException;
|
||||||
|
import jakarta.servlet.annotation.WebServlet;
|
||||||
|
import jakarta.servlet.http.HttpServlet;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@WebServlet("/deleteFlight")
|
||||||
|
public class DeleteFlightServlet extends HttpServlet {
|
||||||
|
private FlightService flightService= new FlightService();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
String idStr = req.getParameter("id");
|
||||||
|
if (idStr==null || idStr==""){
|
||||||
|
req.setAttribute("errorMsg","ID的值不能为空!!!");
|
||||||
|
req.getRequestDispatcher("error.jsp").forward(req,resp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Integer id = Integer.parseInt(idStr);
|
||||||
|
int result = flightService.updateDelete(id);
|
||||||
|
if (result > 0) {
|
||||||
|
// req.getRequestDispatcher("showFlight.jsp").forward(req,resp);
|
||||||
|
resp.sendRedirect("show.jsp");
|
||||||
|
|
||||||
|
}else {
|
||||||
|
req.setAttribute("errorMsg","删除失败!!!");
|
||||||
|
req.getRequestDispatcher("error.jsp").forward(req,resp);
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
req.setAttribute("errorMsg","类型转换异常,id 不能转换成Int类型!!!");
|
||||||
|
req.getRequestDispatcher("error.jsp").forward(req,resp);
|
||||||
|
e.printStackTrace();
|
||||||
|
}catch (Exception e){
|
||||||
|
req.setAttribute("errorMsg","系统异常!!!");
|
||||||
|
req.getRequestDispatcher("error.jsp").forward(req,resp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
98
src/com/landaiqing/servlet/InsertServlet.java
Normal file
98
src/com/landaiqing/servlet/InsertServlet.java
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
package com.landaiqing.servlet;
|
||||||
|
|
||||||
|
import com.landaiqing.entity.FlightEntity;
|
||||||
|
import com.landaiqing.service.FlightService;
|
||||||
|
import com.landaiqing.utils.DateUtils;
|
||||||
|
import com.mysql.cj.util.StringUtils;
|
||||||
|
import jakarta.servlet.ServletException;
|
||||||
|
import jakarta.servlet.annotation.WebServlet;
|
||||||
|
import jakarta.servlet.http.HttpServlet;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@WebServlet("/insert")
|
||||||
|
public class InsertServlet extends HttpServlet {
|
||||||
|
private FlightService flightService= new FlightService();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
req.getRequestDispatcher("insertFlight.jsp").forward(req,resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
try {
|
||||||
|
String flightId = req.getParameter("flightId");
|
||||||
|
if (StringUtils.isNullOrEmpty(flightId)){
|
||||||
|
req.setAttribute("errorMsg","flightId 的值不能为空!!!");
|
||||||
|
req.getRequestDispatcher("error.jsp").forward(req,resp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String company = req.getParameter("company");
|
||||||
|
if (StringUtils.isNullOrEmpty(company)){
|
||||||
|
req.setAttribute("errorMsg","company 的值不能为空!!!");
|
||||||
|
req.getRequestDispatcher("error.jsp").forward(req,resp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String departureAirport = req.getParameter("departureAirport");
|
||||||
|
if (StringUtils.isNullOrEmpty(departureAirport)){
|
||||||
|
req.setAttribute("errorMsg","departureAirport 的值不能为空!!!");
|
||||||
|
req.getRequestDispatcher("error.jsp").forward(req,resp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String arriveAirport = req.getParameter("arriveAirport");
|
||||||
|
if (StringUtils.isNullOrEmpty(arriveAirport)){
|
||||||
|
req.setAttribute("errorMsg","arriveAirport 的值不能为空!!!");
|
||||||
|
req.getRequestDispatcher("error.jsp").forward(req,resp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String departureTimeStr = req.getParameter("departureTime");
|
||||||
|
if (StringUtils.isNullOrEmpty(departureTimeStr)){
|
||||||
|
req.setAttribute("errorMsg","departureTimeStr 的值不能为空!!!");
|
||||||
|
req.getRequestDispatcher("error.jsp").forward(req,resp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Date departureTime = DateUtils.stringToDate(departureTimeStr);
|
||||||
|
|
||||||
|
String arriveTimeStr = req.getParameter("arriveTime");
|
||||||
|
if (StringUtils.isNullOrEmpty(arriveTimeStr)){
|
||||||
|
req.setAttribute("errorMsg","arriveTimeStr 的值不能为空!!!");
|
||||||
|
req.getRequestDispatcher("error.jsp").forward(req,resp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Date arriveTime = DateUtils.stringToDate(arriveTimeStr);
|
||||||
|
|
||||||
|
String model = req.getParameter("model");
|
||||||
|
if (StringUtils.isNullOrEmpty(model)){
|
||||||
|
req.setAttribute("errorMsg","model 的值不能为空!!!");
|
||||||
|
req.getRequestDispatcher("error.jsp").forward(req,resp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FlightEntity flightEntity=new FlightEntity();
|
||||||
|
flightEntity.setFlightId(flightId);
|
||||||
|
flightEntity.setDepartureAirport(departureAirport);
|
||||||
|
flightEntity.setArriveAirport(arriveAirport);
|
||||||
|
flightEntity.setDepartureTime(departureTime);
|
||||||
|
flightEntity.setArriveTime(arriveTime);
|
||||||
|
flightEntity.setModel(model);
|
||||||
|
flightEntity.setCompany(company);
|
||||||
|
int result = flightService.insertFlight(flightEntity);
|
||||||
|
if (result<=0){
|
||||||
|
req.setAttribute("errorMsg","插入失败!!!");
|
||||||
|
req.getRequestDispatcher("error.jsp").forward(req,resp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
resp.sendRedirect("showFlight");
|
||||||
|
} catch (Exception e) {
|
||||||
|
req.setAttribute("errorMsg","系统异常!!!");
|
||||||
|
req.getRequestDispatcher("error.jsp").forward(req,resp);
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
29
src/com/landaiqing/servlet/ShowFlightServlet.java
Normal file
29
src/com/landaiqing/servlet/ShowFlightServlet.java
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package com.landaiqing.servlet;
|
||||||
|
|
||||||
|
import com.landaiqing.entity.FlightEntity;
|
||||||
|
import com.landaiqing.service.FlightService;
|
||||||
|
import jakarta.servlet.ServletException;
|
||||||
|
import jakarta.servlet.annotation.WebServlet;
|
||||||
|
import jakarta.servlet.http.HttpServlet;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@WebServlet("/showFlight")
|
||||||
|
public class ShowFlightServlet extends HttpServlet {
|
||||||
|
private FlightService flightService= new FlightService();
|
||||||
|
@Override
|
||||||
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
List<FlightEntity> flightEntities = flightService.getByAll();
|
||||||
|
req.setAttribute("flights",flightEntities);
|
||||||
|
req.getRequestDispatcher("show.jsp").forward(req,resp);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
125
src/com/landaiqing/servlet/UpdateFlightServlet.java
Normal file
125
src/com/landaiqing/servlet/UpdateFlightServlet.java
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
package com.landaiqing.servlet;
|
||||||
|
|
||||||
|
import com.landaiqing.entity.FlightEntity;
|
||||||
|
import com.landaiqing.service.FlightService;
|
||||||
|
import com.landaiqing.utils.DateUtils;
|
||||||
|
import com.mysql.cj.util.StringUtils;
|
||||||
|
import jakarta.servlet.ServletException;
|
||||||
|
import jakarta.servlet.annotation.WebServlet;
|
||||||
|
import jakarta.servlet.http.HttpServlet;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@WebServlet("/update")
|
||||||
|
public class UpdateFlightServlet extends HttpServlet {
|
||||||
|
private FlightService flightService= new FlightService();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
String idStr = req.getParameter("id");
|
||||||
|
if (idStr==null || idStr==""){
|
||||||
|
req.setAttribute("errorMsg","ID的值不能为空!!!");
|
||||||
|
req.getRequestDispatcher("error.jsp").forward(req,resp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Integer id = Integer.parseInt(idStr);
|
||||||
|
FlightEntity flightEntity = flightService.getByIdFlight(id);
|
||||||
|
if (flightEntity==null){
|
||||||
|
req.setAttribute("errorMsg","id不存在!!!");
|
||||||
|
req.getRequestDispatcher("error.jsp").forward(req,resp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
req.setAttribute("flight",flightEntity);
|
||||||
|
req.getRequestDispatcher("updateFlight.jsp").forward(req,resp);
|
||||||
|
}catch (Exception e){
|
||||||
|
req.setAttribute("errorMsg","系统异常!!!");
|
||||||
|
req.getRequestDispatcher("error.jsp").forward(req,resp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
try {
|
||||||
|
String idStr = req.getParameter("id");
|
||||||
|
if (StringUtils.isNullOrEmpty(idStr)){
|
||||||
|
req.setAttribute("errorMsg","id的值不能为空!!!");
|
||||||
|
req.getRequestDispatcher("error.jsp").forward(req,resp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Integer id = Integer.parseInt(idStr);
|
||||||
|
String flightId = req.getParameter("flightId");
|
||||||
|
if (StringUtils.isNullOrEmpty(flightId)){
|
||||||
|
req.setAttribute("errorMsg","flightId 的值不能为空!!!");
|
||||||
|
req.getRequestDispatcher("error.jsp").forward(req,resp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String company = req.getParameter("company");
|
||||||
|
if (StringUtils.isNullOrEmpty(company)){
|
||||||
|
req.setAttribute("errorMsg","company 的值不能为空!!!");
|
||||||
|
req.getRequestDispatcher("error.jsp").forward(req,resp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String departureAirport = req.getParameter("departureAirport");
|
||||||
|
if (StringUtils.isNullOrEmpty(departureAirport)){
|
||||||
|
req.setAttribute("errorMsg","departureAirport 的值不能为空!!!");
|
||||||
|
req.getRequestDispatcher("error.jsp").forward(req,resp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String arriveAirport = req.getParameter("arriveAirport");
|
||||||
|
if (StringUtils.isNullOrEmpty(arriveAirport)){
|
||||||
|
req.setAttribute("errorMsg","arriveAirport 的值不能为空!!!");
|
||||||
|
req.getRequestDispatcher("error.jsp").forward(req,resp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String departureTimeStr = req.getParameter("departureTime");
|
||||||
|
if (StringUtils.isNullOrEmpty(departureTimeStr)){
|
||||||
|
req.setAttribute("errorMsg","departureTimeStr 的值不能为空!!!");
|
||||||
|
req.getRequestDispatcher("error.jsp").forward(req,resp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Date departureTime = DateUtils.stringToDate(departureTimeStr);
|
||||||
|
|
||||||
|
String arriveTimeStr = req.getParameter("arriveTime");
|
||||||
|
if (StringUtils.isNullOrEmpty(arriveTimeStr)){
|
||||||
|
req.setAttribute("errorMsg","arriveTimeStr 的值不能为空!!!");
|
||||||
|
req.getRequestDispatcher("error.jsp").forward(req,resp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Date arriveTime = DateUtils.stringToDate(arriveTimeStr);
|
||||||
|
|
||||||
|
String model = req.getParameter("model");
|
||||||
|
if (StringUtils.isNullOrEmpty(model)){
|
||||||
|
req.setAttribute("errorMsg","model 的值不能为空!!!");
|
||||||
|
req.getRequestDispatcher("error.jsp").forward(req,resp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FlightEntity flightEntity=new FlightEntity();
|
||||||
|
flightEntity.setId(id);
|
||||||
|
flightEntity.setFlightId(flightId);
|
||||||
|
flightEntity.setDepartureAirport(departureAirport);
|
||||||
|
flightEntity.setArriveAirport(arriveAirport);
|
||||||
|
flightEntity.setDepartureTime(departureTime);
|
||||||
|
flightEntity.setArriveTime(arriveTime);
|
||||||
|
flightEntity.setModel(model);
|
||||||
|
flightEntity.setCompany(company);
|
||||||
|
int result = flightService.updateFlight(flightEntity);
|
||||||
|
if (result<=0){
|
||||||
|
req.setAttribute("errorMsg","修改失败!!!");
|
||||||
|
req.getRequestDispatcher("error.jsp").forward(req,resp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
resp.sendRedirect("showFlight");
|
||||||
|
} catch (Exception e) {
|
||||||
|
req.setAttribute("errorMsg","系统异常!!!");
|
||||||
|
req.getRequestDispatcher("error.jsp").forward(req,resp);
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
23
src/com/landaiqing/test/Test01.java
Normal file
23
src/com/landaiqing/test/Test01.java
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package com.landaiqing.test;
|
||||||
|
|
||||||
|
import com.landaiqing.dao.FlightDao;
|
||||||
|
import com.landaiqing.entity.FlightEntity;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class Test01 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
FlightDao flightDao=new FlightDao();
|
||||||
|
FlightEntity flightEntity=new FlightEntity();
|
||||||
|
flightEntity.setId(3);
|
||||||
|
flightEntity.setFlightId("002");
|
||||||
|
flightEntity.setDepartureAirport("乌鲁木齐");
|
||||||
|
flightEntity.setArriveAirport("陕西");
|
||||||
|
flightEntity.setDepartureTime(new Date());
|
||||||
|
flightEntity.setArriveTime(new Date());
|
||||||
|
flightEntity.setModel("SSS");
|
||||||
|
flightEntity.setCompany("中国");
|
||||||
|
flightDao.updateFlight(flightEntity);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
486
src/com/landaiqing/utils/DateUtils.java
Normal file
486
src/com/landaiqing/utils/DateUtils.java
Normal file
@ -0,0 +1,486 @@
|
|||||||
|
package com.landaiqing.utils;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
|
public class DateUtils {
|
||||||
|
/**
|
||||||
|
* 预定的日期格式
|
||||||
|
*/
|
||||||
|
public static final String[] DATEFORMAT = {"yyyy-MM-dd HH:mm:ss", "yyyy/MM/dd HH:mm:ss", "yyyy年MM月dd日HH时mm分ss秒", "yyyy-MM-dd", "yyyy/MM/dd", "yy-MM-dd", "yy/MM/dd", "yyyy年MM月dd日", "HH:mm:ss",
|
||||||
|
"yyyyMMddHHmmss", "yyyyMMdd", "yyyy.MM.dd", "yy.MM.dd", "yyyyMMddHHmmssSSS", "yyyy-MM-dd HH:mm:ss:SSS", "yyyy-MM-dd HH:mm:ss.SSS", "yyyy", "yyyyMM", "yyyyMMdd HH", "yyyyMMdd HH:mm",
|
||||||
|
"yyyyMMdd HH:mm:ss", "yyyy-MM" };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 线程绑定的日期格式转换器缓存
|
||||||
|
*/
|
||||||
|
private static final ThreadLocal<Map<String, SimpleDateFormat>> DATEFORMATERSCACHE = new ThreadLocal<Map<String, SimpleDateFormat>>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前系统时间
|
||||||
|
*/
|
||||||
|
public static Calendar getSystemCurrentTime() {
|
||||||
|
final Calendar currentTime = Calendar.getInstance();
|
||||||
|
return currentTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前系统时间
|
||||||
|
*/
|
||||||
|
public static String getSystemCurrentTime(int format) {
|
||||||
|
return toDateStrByFormatIndex(getSystemCurrentTime(), format);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取系统当前date类型时间
|
||||||
|
*/
|
||||||
|
public static Date getCurrentDate() {
|
||||||
|
return new Date();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取系统当前日期和时间,格式为yyyy-MM-dd HH:mm:ss
|
||||||
|
*/
|
||||||
|
public static String getCurrentDateTime() {
|
||||||
|
return getFormatCurrentDate("yyyy-MM-dd HH:mm:ss");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回格式化的当前日期/时间
|
||||||
|
*/
|
||||||
|
public static String getFormatCurrentDate(String strFormat) {
|
||||||
|
return msFormatDateTime(getCurrentDate(), strFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日期/时间格式化显示(年、月、日、时、分、秒、毫秒、星期)
|
||||||
|
*/
|
||||||
|
public static String msFormatDateTime(Date dtmDate, String strFormat) {
|
||||||
|
|
||||||
|
if (strFormat.equals("")) {
|
||||||
|
strFormat = "yyyy-MM-dd HH:mm:ss";
|
||||||
|
}
|
||||||
|
|
||||||
|
final SimpleDateFormat myFormat = new SimpleDateFormat(strFormat);
|
||||||
|
|
||||||
|
return myFormat.format(dtmDate.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日期/时间格式化显示(年、月、日)
|
||||||
|
*/
|
||||||
|
public static String msFormatDate(Date dtmDate, String strFormat) {
|
||||||
|
|
||||||
|
if (strFormat.equals("")) {
|
||||||
|
strFormat = "yyyy-MM-dd";
|
||||||
|
}
|
||||||
|
|
||||||
|
final SimpleDateFormat myFormat = new SimpleDateFormat(strFormat);
|
||||||
|
|
||||||
|
return myFormat.format(dtmDate.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前系统时间
|
||||||
|
*/
|
||||||
|
public static String getSystemCurrentTime(String format) {
|
||||||
|
return toDateStrByFormat(getSystemCurrentTime(), format);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================日期转字符串基础格式化方法======================================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name 中文名称
|
||||||
|
*/
|
||||||
|
private static SimpleDateFormat getDateFormater(String format) {
|
||||||
|
Map<String, SimpleDateFormat> dateFormaters = DATEFORMATERSCACHE.get();
|
||||||
|
SimpleDateFormat dateFormater = null;
|
||||||
|
boolean formatersIsNull = false;
|
||||||
|
|
||||||
|
if (dateFormaters == null) {
|
||||||
|
dateFormaters = new HashMap<String, SimpleDateFormat>(3, 0.2f);
|
||||||
|
DATEFORMATERSCACHE.set(dateFormaters);
|
||||||
|
formatersIsNull = true;
|
||||||
|
}
|
||||||
|
dateFormater = dateFormaters.get(format);
|
||||||
|
if (formatersIsNull || dateFormater == null) {
|
||||||
|
dateFormater = new SimpleDateFormat(format);
|
||||||
|
dateFormaters.put(format, dateFormater);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dateFormater;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static SimpleDateFormat getDateFormater(int format) {
|
||||||
|
return getDateFormater(DATEFORMAT[format]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================日期转字符串基础方法======================================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Calendar日期转指定日期格式的字符串
|
||||||
|
*/
|
||||||
|
public static String toDateStrByFormat(Calendar date, String format) {
|
||||||
|
if (date == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return getDateFormater(format).format(date.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Calendar日期转指定日期格式的字符串
|
||||||
|
*/
|
||||||
|
public static String toDateStrByFormatIndex(Calendar date, int format) {
|
||||||
|
return toDateStrByFormat(date, DATEFORMAT[format]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* java.util.Date日期转指定日期格式的字符串
|
||||||
|
*/
|
||||||
|
public static String toDateStrByFormat(Date date, String format) {
|
||||||
|
if (date == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return getDateFormater(format).format(date.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* java.util.Date日期转指定格式的字符串
|
||||||
|
*/
|
||||||
|
public static String toDateStrByFormatIndex(Date date, int format) {
|
||||||
|
return toDateStrByFormat(date, DATEFORMAT[format]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================日期转字符串方法======================================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calendar日期转日期字符串
|
||||||
|
*/
|
||||||
|
public static String toDateTimeStr(Calendar date) {
|
||||||
|
return toDateStrByFormatIndex(date, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calendar日期转指定日期格式的字符串
|
||||||
|
*/
|
||||||
|
public static String toDateTimeStr(int format, Calendar date) {
|
||||||
|
return toDateStrByFormatIndex(date, format);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calendar日期转日期字符串
|
||||||
|
*/
|
||||||
|
public static String toDateStr(Calendar date) {
|
||||||
|
return toDateStrByFormatIndex(date, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* java.util.Date日期转指定格式的日期字符串
|
||||||
|
*/
|
||||||
|
public static String dateToString(Date date, int format) {
|
||||||
|
return toDateStrByFormatIndex(date, format);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* java.util.Date日期转日期字符串
|
||||||
|
*/
|
||||||
|
public static String dateToString(Date date) {
|
||||||
|
return toDateStrByFormatIndex(date, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================xx转Date方法======================================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calendar日期转java.util.Date日期
|
||||||
|
*/
|
||||||
|
public static Date convertCalendarToDate(Calendar c) {
|
||||||
|
final Date d = new Date();
|
||||||
|
d.setTime(c.getTimeInMillis());
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日期字符串转java.util.Date日期
|
||||||
|
*/
|
||||||
|
public static Date stringToDate(String dateStr) throws Exception {
|
||||||
|
return parseDate(dateStr, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日期字符串转指定格式的java.util.Date日期
|
||||||
|
*/
|
||||||
|
public static Date parseDate(String dateStr, int format) throws Exception {
|
||||||
|
if (dateStr == null || dateStr.length() == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return getDateFormater(format).parse(dateStr);
|
||||||
|
} catch (ParseException ex) {
|
||||||
|
return parseDate(dateStr, format + 1);
|
||||||
|
} catch (ArrayIndexOutOfBoundsException ex) {
|
||||||
|
throw new Exception("UT-07001:日志字符串" + dateStr + "格式不支持", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================xx转Calendar方法======================================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* java.util.Date转Calendar
|
||||||
|
*/
|
||||||
|
public static Calendar convUtilDateToUtilCalendar(Date date) {
|
||||||
|
if (date == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final GregorianCalendar gc = new GregorianCalendar();
|
||||||
|
gc.setTimeInMillis(date.getTime());
|
||||||
|
|
||||||
|
return gc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* java.sql.Timestamp转Calendar
|
||||||
|
*/
|
||||||
|
public static Calendar convSqlTimestampToUtilCalendar(Timestamp date) {
|
||||||
|
if (date == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final GregorianCalendar gc = new GregorianCalendar();
|
||||||
|
gc.setTimeInMillis(date.getTime());
|
||||||
|
return gc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日期字符串转Calendar
|
||||||
|
*/
|
||||||
|
public static Calendar parseDate(String dateStr) throws Exception {
|
||||||
|
final Date result = parseDate(dateStr, 0);
|
||||||
|
Calendar cal = null;
|
||||||
|
|
||||||
|
if (result != null) {
|
||||||
|
cal = new GregorianCalendar(0, 0, 0, 0, 0, 0);
|
||||||
|
cal.setTime(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cal;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================日期转Timestamp方法======================================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* java.util.Date转java.sql.Timestamp
|
||||||
|
*/
|
||||||
|
public static Timestamp convUtilDateToSqlTimestamp(Date date) {
|
||||||
|
if (date == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Timestamp(date.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calendar日期对象转Timestamp日期对象
|
||||||
|
*/
|
||||||
|
public static Timestamp convUtilCalendarToSqlTimestamp(Calendar date) {
|
||||||
|
if (date == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Timestamp(date.getTimeInMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calendar日期对象转Timestamp日期对象
|
||||||
|
*/
|
||||||
|
public static Timestamp parseTimestamp(Calendar calendar) {
|
||||||
|
return new Timestamp(calendar.getTimeInMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日期字符串转java.sql.Timestamp
|
||||||
|
*/
|
||||||
|
public static Timestamp parseTimestamp(String dateStr) throws Exception {
|
||||||
|
try {
|
||||||
|
return new Timestamp(getDateFormater(3).parse(dateStr).getTime());
|
||||||
|
} catch (ParseException ex) {
|
||||||
|
throw new Exception("UT-07001:日志字符串" + dateStr + "格式不正确,格式:" + DATEFORMAT[3], ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据指定日期格式,日期字符串转java.sql.Timestamp
|
||||||
|
*/
|
||||||
|
public static Timestamp parseTimestamp(String dateStr, int format) throws Exception {
|
||||||
|
try {
|
||||||
|
return new Timestamp(getDateFormater(format).parse(dateStr).getTime());
|
||||||
|
} catch (ParseException ex) {
|
||||||
|
throw new Exception("UT-07001:日志字符串" + dateStr + "格式不支持", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================日期计算方法======================================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取两个Calendar日期对象的天数差
|
||||||
|
*/
|
||||||
|
public static int calendarMinus(Calendar d1, Calendar d2) {
|
||||||
|
if (d1 == null || d2 == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
d1.set(11, 0);
|
||||||
|
d1.set(12, 0);
|
||||||
|
d1.set(13, 0);
|
||||||
|
d1.set(14, 0);
|
||||||
|
|
||||||
|
d2.set(11, 0);
|
||||||
|
d2.set(12, 0);
|
||||||
|
d2.set(13, 0);
|
||||||
|
d2.set(14, 0);
|
||||||
|
|
||||||
|
long t1 = d1.getTimeInMillis();
|
||||||
|
long t2 = d2.getTimeInMillis();
|
||||||
|
final long daylong = 86400000L;
|
||||||
|
t1 -= t1 % daylong;
|
||||||
|
t2 -= t2 % daylong;
|
||||||
|
|
||||||
|
final long t = t1 - t2;
|
||||||
|
final int value = (int) (t / daylong);
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取两个Calendar日期对象的天数差
|
||||||
|
*/
|
||||||
|
public static long calendarminus(Calendar d1, Calendar d2) {
|
||||||
|
if (d1 == null || d2 == null) {
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
return (d1.getTimeInMillis() - d2.getTimeInMillis()) / 86400000L;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 给定任意日期Calendar对象,计算所在月天数
|
||||||
|
*/
|
||||||
|
public static int calcMonthDays(Calendar date) {
|
||||||
|
final Calendar t1 = (Calendar) date.clone();
|
||||||
|
final Calendar t2 = (Calendar) date.clone();
|
||||||
|
final int year = date.get(1);
|
||||||
|
final int month = date.get(2);
|
||||||
|
t1.set(year, month, 1);
|
||||||
|
t2.set(year, month + 1, 1);
|
||||||
|
t2.add(6, -1);
|
||||||
|
return calendarMinus(t2, t1) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int calcDays(long t1, long t2) {
|
||||||
|
final long millis = t1 - t2;
|
||||||
|
if (millis == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return (int) (millis / (24 * 3600 * 1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取两个Calendar日期对象的天数差
|
||||||
|
*/
|
||||||
|
public static int calcDays(Calendar c1, Calendar c2) {
|
||||||
|
return calcDays(c1.getTimeInMillis(), c2.getTimeInMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取两个java.util.Date日期对象的天数差
|
||||||
|
*/
|
||||||
|
public static int calcDays(Date d1, Date d2) {
|
||||||
|
return calcDays(d1.getTime(), d2.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 给定任意日期Calendar对象,计算所在月的最后一天
|
||||||
|
*/
|
||||||
|
public static Calendar lastDay(Calendar c) {
|
||||||
|
final Calendar t = (Calendar) c.clone();
|
||||||
|
t.set(Calendar.DAY_OF_MONTH, 1);
|
||||||
|
t.add(Calendar.MONTH, 1);
|
||||||
|
t.add(Calendar.DAY_OF_MONTH, -1);
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 给定任意日期字符串,计算所在月的最后一天
|
||||||
|
*/
|
||||||
|
public static Calendar lastDay(String dateStr) throws Exception {
|
||||||
|
final Calendar t = parseDate(dateStr);
|
||||||
|
t.set(Calendar.DAY_OF_MONTH, 1);
|
||||||
|
t.add(Calendar.MONTH, 1);
|
||||||
|
t.add(Calendar.DAY_OF_MONTH, -1);
|
||||||
|
return t;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 给定任意日期,计算所在季的季起日期和季终日期
|
||||||
|
*/
|
||||||
|
public static Calendar[] calcAQuarter(Calendar day) {
|
||||||
|
final Calendar[] quarter = new Calendar[2];
|
||||||
|
|
||||||
|
int month = 0;
|
||||||
|
quarter[0] = (Calendar) day.clone();
|
||||||
|
month = quarter[0].get(Calendar.MONTH);
|
||||||
|
|
||||||
|
if (month < 3) {
|
||||||
|
month = 0;
|
||||||
|
} else if (month < 6) {
|
||||||
|
month = 3;
|
||||||
|
} else if (month < 9) {
|
||||||
|
month = 6;
|
||||||
|
} else {
|
||||||
|
month = 9;
|
||||||
|
}
|
||||||
|
|
||||||
|
quarter[0].set(Calendar.MONTH, month);
|
||||||
|
quarter[0].set(Calendar.DAY_OF_MONTH, 1);
|
||||||
|
|
||||||
|
quarter[1] = (Calendar) quarter[0].clone();
|
||||||
|
quarter[1].set(Calendar.MONTH, month + 2);
|
||||||
|
quarter[1] = lastDay(quarter[1]);
|
||||||
|
|
||||||
|
return quarter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取年、月、日、时、分、秒、毫秒
|
||||||
|
*/
|
||||||
|
public static int[] getYearMonthDayHH24MiMM(Calendar calendar) {
|
||||||
|
return new int[] {calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE),
|
||||||
|
calendar.get(Calendar.SECOND), calendar.get(Calendar.MILLISECOND) };
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取年、月、日、时、分、秒、毫秒
|
||||||
|
*/
|
||||||
|
public static int[] getYearMonthDayHH24MiMM(Date date) {
|
||||||
|
final Calendar calendar = getSystemCurrentTime();
|
||||||
|
calendar.setTime(date);
|
||||||
|
return getYearMonthDayHH24MiMM(calendar);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 好微妙转毫秒
|
||||||
|
*/
|
||||||
|
public static long nsToMs(long nsTime) {
|
||||||
|
return nsTime / 1000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
140
src/com/landaiqing/utils/JDBCUtil.java
Normal file
140
src/com/landaiqing/utils/JDBCUtil.java
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
package com.landaiqing.utils;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 余胜军
|
||||||
|
* @ClassName MayiktJdbcUtils
|
||||||
|
* @qq 644064779
|
||||||
|
* @addres www.mayikt.com
|
||||||
|
* 微信:yushengjun644
|
||||||
|
*/
|
||||||
|
public class JDBCUtil {
|
||||||
|
/**
|
||||||
|
* 1.需要将我们的构造方法私有化 ---工具类 不需要 new出来 是通过类名称.方法名称访问
|
||||||
|
*/
|
||||||
|
private JDBCUtil() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 2.定义工具类 需要 声明 变量
|
||||||
|
*/
|
||||||
|
private static String driverClass;
|
||||||
|
private static String url;
|
||||||
|
private static String user;
|
||||||
|
private static String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*3.使用静态代码快 来给我们声明好 jdbc变量赋值(读取config.properties)
|
||||||
|
*/
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
// 1.读取config.properties IO 路径 相对路径
|
||||||
|
InputStream resourceAsStream = JDBCUtil.class.getClassLoader().
|
||||||
|
getResourceAsStream("config.properties");
|
||||||
|
// 2.赋值给我们声明好的变量
|
||||||
|
Properties properties = new Properties();
|
||||||
|
properties.load(resourceAsStream);
|
||||||
|
driverClass = properties.getProperty("driverClass");
|
||||||
|
url = properties.getProperty("url");
|
||||||
|
user = properties.getProperty("user");
|
||||||
|
password = properties.getProperty("password");
|
||||||
|
// 3.注册驱动类
|
||||||
|
Class.forName(driverClass);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 4.封装连接方法
|
||||||
|
*/
|
||||||
|
public static Connection getConnection() throws SQLException {
|
||||||
|
Connection connection = DriverManager.getConnection(url, user, password);
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 5.封装释放连接方法 (重载)
|
||||||
|
*/
|
||||||
|
public static void closeConnection(ResultSet resultSet, Statement statement, Connection connection) {
|
||||||
|
// 1.查询 释放连接 resultSet statement connection
|
||||||
|
try {
|
||||||
|
if (resultSet != null)
|
||||||
|
resultSet.close();
|
||||||
|
if (statement != null)
|
||||||
|
statement.close();
|
||||||
|
if (connection != null)
|
||||||
|
connection.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 增删改---释放jdbc资源
|
||||||
|
*
|
||||||
|
* @param statement
|
||||||
|
* @param connection
|
||||||
|
*/
|
||||||
|
public static void closeConnection(Statement statement, Connection connection) {
|
||||||
|
// 1.查询 释放连接 resultSet statement connection
|
||||||
|
closeConnection(null, statement, connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开启事务
|
||||||
|
*
|
||||||
|
* @param connection
|
||||||
|
* @throws SQLException
|
||||||
|
*/
|
||||||
|
public static void beginTransaction(Connection connection) throws SQLException {
|
||||||
|
connection.setAutoCommit(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提交事务
|
||||||
|
*
|
||||||
|
* @param connection
|
||||||
|
* @throws SQLException
|
||||||
|
*/
|
||||||
|
public static void commitTransaction(Connection connection) throws SQLException {
|
||||||
|
connection.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 回滚事务
|
||||||
|
*
|
||||||
|
* @param connection
|
||||||
|
*/
|
||||||
|
public static void rollBackTransaction(Connection connection) {
|
||||||
|
if (connection != null) {
|
||||||
|
try {
|
||||||
|
connection.rollback();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关闭事务
|
||||||
|
*
|
||||||
|
* @param connection
|
||||||
|
*/
|
||||||
|
public static void endTransaction(Connection connection) {
|
||||||
|
if (connection != null) {
|
||||||
|
try {
|
||||||
|
connection.setAutoCommit(true);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
4
src/config.properties
Normal file
4
src/config.properties
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
driverClass=com.mysql.cj.jdbc.Driver
|
||||||
|
url=jdbc:mysql://127.0.0.1:3306/testdb?serverTimezone=GMT%2B8
|
||||||
|
user=root
|
||||||
|
password=1611
|
6
web/WEB-INF/web.xml
Normal file
6
web/WEB-INF/web.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
|
||||||
|
version="4.0">
|
||||||
|
</web-app>
|
16
web/error.jsp
Normal file
16
web/error.jsp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<%--
|
||||||
|
Created by IntelliJ IDEA.
|
||||||
|
User: LDQ
|
||||||
|
Date: 2023/6/5
|
||||||
|
Time: 19:06
|
||||||
|
To change this template use File | Settings | File Templates.
|
||||||
|
--%>
|
||||||
|
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>ERROR</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>系统错误,错误信息:${errorMsg}</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
34
web/flight.html
Normal file
34
web/flight.html
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Title</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
|
||||||
|
<table border="1" align="center" style="border-collapse: collapse;width: 80%">
|
||||||
|
<tr align="center">
|
||||||
|
<th align="center">航号</th>
|
||||||
|
<th align="center">航空公司</th>
|
||||||
|
<th align="center">出发机场</th>
|
||||||
|
<th align="center">达到机场</th>
|
||||||
|
<th align="center">出发时间</th>
|
||||||
|
<th align="center">到达时间</th>
|
||||||
|
<th align="center">机型</th>
|
||||||
|
<th align="center">操作</th>
|
||||||
|
</tr>
|
||||||
|
<tr align="center">
|
||||||
|
<td align="center">MYKT001</td>
|
||||||
|
<td align="center">中国东方航空</td>
|
||||||
|
<td align="center">武汉天河机场</td>
|
||||||
|
<td align="center">北京首都机场</td>
|
||||||
|
<td align="center">2022年5月25日 12:00</td>
|
||||||
|
<td align="center">2022年5月25日 14:00</td>
|
||||||
|
<td align="center">735</td>
|
||||||
|
<td align="center"><a href="#">修改</a> <a href="#">删除</a></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
16
web/index.jsp
Normal file
16
web/index.jsp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<%--
|
||||||
|
Created by IntelliJ IDEA.
|
||||||
|
User: LDQ
|
||||||
|
Date: 2023/6/5
|
||||||
|
Time: 17:52
|
||||||
|
To change this template use File | Settings | File Templates.
|
||||||
|
--%>
|
||||||
|
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>$Title$</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
$END$
|
||||||
|
</body>
|
||||||
|
</html>
|
26
web/insertFlight.jsp
Normal file
26
web/insertFlight.jsp
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
|
||||||
|
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>添加航班信息</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div>
|
||||||
|
<h1>添加数据</h1>
|
||||||
|
|
||||||
|
<form action="insert" method="post">
|
||||||
|
<label>航 号: <input type="text" name="flightId" value="${flight.flightId}"></label><br>
|
||||||
|
<label>航空公司: <input type="text" name="company"></label><br>
|
||||||
|
<label>出发机场: <input type="text" name="departureAirport"></label><br>
|
||||||
|
<label>达到机场: <input type="text" name="arriveAirport"></label><br>
|
||||||
|
<label>出发时间: <input type="text" name="departureTime"></label><br>
|
||||||
|
<label>到达时间: <input type="text" name="arriveTime"></label><br>
|
||||||
|
<label>机 型: <input type="text" name="model"></label><br>
|
||||||
|
<input type="submit" value="提交">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
46
web/show.jsp
Normal file
46
web/show.jsp
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<%--
|
||||||
|
Created by IntelliJ IDEA.
|
||||||
|
User: LDQ
|
||||||
|
Date: 2023/6/5
|
||||||
|
Time: 18:42
|
||||||
|
To change this template use File | Settings | File Templates.
|
||||||
|
--%>
|
||||||
|
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
|
||||||
|
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>航班系统</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table border="1" align="center" style="border-collapse: collapse;width: 80%">
|
||||||
|
<tr align="center">
|
||||||
|
<th align="center">序号</th>
|
||||||
|
<th align="center">航号</th>
|
||||||
|
<th align="center">航空公司</th>
|
||||||
|
<th align="center">出发机场</th>
|
||||||
|
<th align="center">达到机场</th>
|
||||||
|
<th align="center">出发时间</th>
|
||||||
|
<th align="center">到达时间</th>
|
||||||
|
<th align="center">机型</th>
|
||||||
|
<th align="center">操作</th>
|
||||||
|
</tr>
|
||||||
|
<c:forEach items="${flights}" var="f" varStatus="i">
|
||||||
|
<tr align="center">
|
||||||
|
<td align="center">${i.index+1}</td>
|
||||||
|
<td align="center">${f.flightId}</td>
|
||||||
|
<td align="center">${f.company}</td>
|
||||||
|
<td align="center">${f.departureAirport}</td>
|
||||||
|
<td align="center">${f.arriveAirport}</td>
|
||||||
|
<td align="center">${f.departureTime}</td>
|
||||||
|
<td align="center">${f.arriveTime}</td>
|
||||||
|
<td align="center">${f.model}</td>
|
||||||
|
<td align="center"><a href="/JavaWeb_Flight_System_war_exploded/update?id=${f.id}">修改</a> <a href="/JavaWeb_Flight_System_war_exploded/deleteFlight?id=${f.id}">删除</a></td>
|
||||||
|
</tr>
|
||||||
|
</c:forEach>
|
||||||
|
|
||||||
|
<a href="insertFlight.jsp">点击添加航班</a>
|
||||||
|
|
||||||
|
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
24
web/updateFlight.html
Normal file
24
web/updateFlight.html
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Title</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div >
|
||||||
|
<h1>修改数据</h1>
|
||||||
|
|
||||||
|
<form>
|
||||||
|
<label>航 号: <input type="text"></label><br>
|
||||||
|
<label>航空公司: <input type="text"></label><br>
|
||||||
|
<label>出发机场: <input type="text"></label><br>
|
||||||
|
<label>达到机场: <input type="text"></label><br>
|
||||||
|
<label>出发时间: <input type="text"></label><br>
|
||||||
|
<label>到达时间: <input type="text"></label><br>
|
||||||
|
<label>机 型: <input type="text"></label><br>
|
||||||
|
<input type="submit" value="提交">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
27
web/updateFlight.jsp
Normal file
27
web/updateFlight.jsp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
|
||||||
|
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>修改航班信息</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div>
|
||||||
|
<h1>修改数据</h1>
|
||||||
|
|
||||||
|
<form action="update" method="post">
|
||||||
|
<input type="hidden" name="id" value="${flight.id}"></label><br>
|
||||||
|
<label>航 号: <input type="text" name="flightId" value="${flight.flightId}"></label><br>
|
||||||
|
<label>航空公司: <input type="text" value="${flight.company}" name="company"></label><br>
|
||||||
|
<label>出发机场: <input type="text" value="${flight.departureAirport}" name="departureAirport"></label><br>
|
||||||
|
<label>达到机场: <input type="text" value="${flight.arriveAirport}" name="arriveAirport"></label><br>
|
||||||
|
<label>出发时间: <input type="text" value="${flight.departureTime}" name="departureTime"></label><br>
|
||||||
|
<label>到达时间: <input type="text" value="${flight.arriveTime}" name="arriveTime"></label><br>
|
||||||
|
<label>机 型: <input type="text" value="${flight.model}" name="model"></label><br>
|
||||||
|
<input type="submit" value="提交">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user