火车车次信息管理试题讲解

余生长醉 提交于 2019-11-29 08:32:58

火车车次信息管理试题

本试题使用Jsp+Spring+Mybatis+Mysql+Maven等技术实现火车车次信息管理。

题目:火车车次信息管理

语言和环境

A、实现语言
Java
B、环境要求
JDK1.8、Eclipse、Tomcat7、Spring、Mybatis、Mysql、Maven

功能要求

使用JSP+Servlet+Spring+Mybatis实现火车车次信息管理功能,MySql作为后台数据库,功能包括车次信息浏览、火车车次信息详情和车次信息删除两大功能。具体要求如下:
(1)打开火车车次信息管理首页,以列表方式显示所有车次信息,页面列表要求实现隔行变色效果,如下图所示。

在这里插入图片描述
(2)单击“删除”链接可以进行火车车次信息删除,如果没有复选框被选中,当单击“删除”链接时需要提示“请选择车次!”信息,如下图所示。
在这里插入图片描述
(3)如果选中复选框,单击“删除”链接,执行删除车次信息操作,并根据删除结果给出相应的信息提示,如下图所示。在这里插入图片描述
点击确定后,跳转至车次信息列表页面,并显示更新后的车次列表信息,如下图所示。
在这里插入图片描述
(4)单击车次超链接,则跳转至指定车次的火车车次详情页面,如下图所示。
在这里插入图片描述

数据库设计

数据库表名称及要求:
在这里插入图片描述

视频讲解及源码地址

https://download.csdn.net/download/pcbhyy/10763118

主要代码

数据库

create table train_info(
	train_no varchar(30) primary key,
	start_station varchar(30) not null,
	arrival_station varchar(30) not null,
	start_time varchar(30) not null,
	arrival_time varchar(30) not null,
	type varchar(30) not null,
	runtime varchar(30) not null,
	mile double(10,1)  not null
)

INSERT INTO `train_info` VALUES ('D73', '沈阳', '深圳', '10-24-16:40', '10-25-20:08', '特快', '20', '2000');
INSERT INTO `train_info` VALUES ('D74', '沈阳', '阜新', '10-24-16:40', '10-25-20:08', '特快', '2', '200');
INSERT INTO `train_info` VALUES ('D75', '沈阳', '北京', '10-24-16:40', '10-25-20:08', '高铁', '4', '1000');

INSERT INTO `train_info` VALUES ('D123', '沈阳北', '北京', '10:40', '16:05', '动车', '3d', '500');
INSERT INTO `train_info` VALUES ('G388', '沈阳北', '锦州', '16:40', '07:05', '高铁', '1d', '300');
INSERT INTO `train_info` VALUES ('k388', '沈阳北', '重庆北', '16:40', '07:05', '快', '39d', '1500');
INSERT INTO `train_info` VALUES ('K6206', '沈阳北', '成都北', '16:40', '07:05', '快', '39d', '1500');
INSERT INTO `train_info` VALUES ('Z17', '沈阳北', '北京北', '16:40', '09:05', '直达', '9d', '500');

Servlet

package com.yy.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.yy.eitity.TrainInfo;
import com.yy.service.TrainInfoService;

public class TrainInfoServlet extends HttpServlet {	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String method = request.getParameter("method");
		
		if("getTrainInfo".equals(method)) {
			doGetTrainInfo(request,response);
		}else if("getTrainById".equals(method)) {
			doGetTrainById(request,response);
		}else if("dels".equals(method)) {
			doDels(request,response);
		}
	}

	private void doDels(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String[] nos = request.getParameterValues("no");
		
		ServletContext sc = request.getServletContext();
		
		WebApplicationContext context = 
				WebApplicationContextUtils.getWebApplicationContext(sc);
		
		TrainInfoService service = context.getBean(TrainInfoService.class);
		
		int n = service.batchDelete(nos);
		
		doGetTrainInfo(request,response);		
	}

	private void doGetTrainById(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String no = request.getParameter("no");
		
		ServletContext sc = request.getServletContext();
		
		WebApplicationContext context = 
				WebApplicationContextUtils.getWebApplicationContext(sc);
		
		TrainInfoService service = context.getBean(TrainInfoService.class);
		
		TrainInfo info = service.getById(no);
		
		request.setAttribute("train", info);
		
		request.getRequestDispatcher("/WEB-INF/train/getTrain.jsp").forward(request, response);		
	}

	private void doGetTrainInfo(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ServletContext sc = request.getServletContext();
		
		WebApplicationContext context = 
				WebApplicationContextUtils.getWebApplicationContext(sc);
		
		TrainInfoService service = context.getBean(TrainInfoService.class);
		
		List<TrainInfo> list = service.getAll();
		
		request.setAttribute("list", list);
		
		request.getRequestDispatcher("/WEB-INF/train/getall.jsp").forward(request, response);		
	}
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}

mapper接口

package com.yy.mapper;

import java.util.List;

import com.yy.eitity.TrainInfo;

public interface TrainInfoMapper {
	public List<TrainInfo> getAll();
	public TrainInfo getById(String no);
	public int batchDelete(String[] nos);
}

mapper

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yy.mapper.TrainInfoMapper">
	<resultMap type="com.yy.eitity.TrainInfo" id="basicMap">
		<id property="trainNo" column="train_no" />
		
		<result property="arrivalStation" column="arrival_Station"/>
		<result property="arrivalTime" column="arrival_Time"/>
		<result property="mile" column="mile"/>
		<result property="runtime" column="runtime"/>
		<result property="startStation" column="start_Station"/>
		<result property="startTime" column="start_Time"/>
		<result property="type" column="type"/>
	</resultMap>
	<select id="getAll" resultMap="basicMap">
		select * from train_info
	</select>
	<select id="getById" resultMap="basicMap">
		select * from train_info where train_no = #{trainNo}
	</select>
	
	<delete id="batchDelete">
		delete from train_info 
		where train_no in
		<foreach collection="array" item="trainNo" open="(" close=")" separator=",">
			#{trainNo}
		</foreach>
	</delete>
</mapper>

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.yy</groupId>
	<artifactId>spring_demo</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>war</packaging>
	<build>
		<resources>
			<resource>
				<directory>src/main/java</directory>
				<excludes>
					<exclude>**/*.java</exclude>
				</excludes>
			</resource>
			<resource>
				<directory>src/main/resources</directory>
			</resource>
		</resources>
		<plugins>
			<!-- 资源文件拷贝插件 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-resources-plugin</artifactId>
				<version>2.7</version>
				<configuration>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>
			<!-- java编译插件 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.2</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.tomcat.maven</groupId>
				<artifactId>tomcat7-maven-plugin</artifactId>
				<version>2.2</version>
				<configuration>
					<!-- 部署路径,如:/e3mall,表明部署到/e3mall路径下 -->
					<path>/</path>
					<!-- 端口号 -->
					<port>8089</port>
				</configuration>
			</plugin>
		</plugins>
	</build>
	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.12</version>
		</dependency>
		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>1.2.17</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>4.3.8.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>aopalliance</groupId>
			<artifactId>aopalliance</artifactId>
			<version>1.0</version>
		</dependency>
		<dependency>
			<groupId>org.aspectj</groupId>
			<artifactId>aspectjweaver</artifactId>
			<version>1.8.10</version>
		</dependency>
		<dependency>
			<groupId>commons-dbcp</groupId>
			<artifactId>commons-dbcp</artifactId>
			<version>1.4</version>
		</dependency>
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>5.1.6</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-tx</artifactId>
			<version>4.3.8.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-jdbc</artifactId>
			<version>4.3.8.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-orm</artifactId>
			<version>4.3.8.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis</artifactId>
			<version>3.2.6</version>
		</dependency>
		<dependency>
			<groupId>cglib</groupId>
			<artifactId>cglib</artifactId>
			<version>3.2.5</version>
		</dependency>
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis-spring</artifactId>
			<version>1.2.2</version>
		</dependency>
		<dependency>
			<groupId>jstl</groupId>
			<artifactId>jstl</artifactId>
			<version>1.2</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
			<version>3.1.0</version>
			<scope>provided</scope>
		</dependency>
		<!-- https://mvnrepository.com/artifact/javax.servlet.jsp/jsp-api -->
		<dependency>
			<groupId>javax.servlet.jsp</groupId>
			<artifactId>jsp-api</artifactId>
			<version>2.2</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>4.3.8.RELEASE</version>
		</dependency>
	</dependencies>
</project>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!