springboot整合jsp,完成公交车站路线图
转:
springboot整合jsp,完成公交车站路线图
点赞再看,养成习惯
开发环境:
- jdk 8
- intellij idea
- tomcat 8
- mysql 5.7
- maven 3.6
所用技术:
- springboot
- jsp
- 数据静态初始化
项目介绍
使用springboot整合jsp,在后端写入公交路线名称和详细站点,前端页面可条件查询具体的内容,如公交路线,公交名称,车俩信息等。
运行效果
前台用户端:
- 路线选择
- 路线详情
数据准备:
- BusData.txt
准备工作:
- pom.xml加入jsp模板引擎支持:
org.apache.tomcat.embed
tomcat-embed-jasper
provided
- springboot配置jsp
spring.mvc.view.prefix=/
spring.mvc.view.suffix=.jsp
重要代码:
- bus数据初始化
@PostConstruct
private void initBusData(){
try{
File file = new File(BusMap.getClass().getResource("/").getPath());
FileReader fileReader = new FileReader(file.getPath()+"/static/BusData.txt","GBK"); //初始化BusData.txt 数据
List readLines = fileReader.readLines();
for(String str:readLines){
if(!"".equals(str)){
String[] data=str.split("#");
String way=data[0]; //几路线
String location=data[1];/ /地名
String[] locations=location.split(",");
List list=new ArrayList<>();
for(int i=0;i
路线查询
@RequestMapping("/way")
public String search(HttpServletRequest request,String way) {
try {
if(null==way||"".equalsIgnoreCase(way)){
request.setAttribute("list", BusMap.WayList); //没有搜索默认显示所有路线
return "way";
}else{
List wayList=new ArrayList<>();
//模糊查询路线
for(String str:BusMap.WayList){
if(str.indexOf(way)>-1){
wayList.add(str);
}
}
if(wayList.size()>0){
request.setAttribute("list", wayList); //模糊搜索出来的路线列表
return "way";
}else{
return "noView"; //没有所选路线
}
}
} catch (Exception e) {
e.printStackTrace();
}
return "way";
}
公交车路线站展示
@RequestMapping("/view")
public String view(HttpServletRequest request,String way) {
try {
List list= BusMap.getBusMap(way);
if(list.size()>0){
request.setAttribute("list",list ); //获取总路线
request.setAttribute("firstBus", list.get(0).getLocation()); //第一站
request.setAttribute("lastBus", list.get(list.size()-1).getLocation()); //最后一站
int size = list.size();
size =(size-1)*99;
request.setAttribute("size",size);
return "view";
}
} catch (Exception e) {
e.printStackTrace();
}
return "noView";//没有对应公交车站
}
//前端页面数据渲染
${firstBus}<----->${lastBus}
( 首/末班车时间:6:00 / 23:00)
项目总结
项目存放路径最好不要带中文路径,否则可能存在静态busData资源初始化失败页面时间车站路线所采用时间轴方式展示,长度动态计算,部分浏览器显示可能有点错位其他后续迭代功能后续开发,敬请关注
转:
springboot整合jsp,完成公交车站路线图
springboot整合jsp,完成公交车站路线图的更多相关文章
- SpringBoot整合Jsp和Thymeleaf (附工程)
前言 本篇文章主要讲述SpringBoot整合Jsp以及SpringBoot整合Thymeleaf,实现一个简单的用户增删改查示例工程.事先说明,有三个项目,两个是单独整合的,一个是将它们整合在一起的 ...
- 03-01:springboot 整合jsp
1.修改pom文件,添加坐标 <!-- jstl --> <dependency> <groupId>javax.servlet ...
- springboot整合jsp模板
springboot整合jsp模板 在使用springboot框架里使用jsp的时候,页面模板使用jsp在pom.xnl中需要引入相关的依赖,否则在controller中无法返回到指定页面 〇.搭建s ...
- SpringBoot整合jsp技术
1.修改pom.xml文件 <?xml version="1.0" encoding="UTF-8"?> <project xmlns=&qu ...
- Idea中SpringBoot整合JSP
最近在学习SpringBoot,看到SpringBoot整合jsp,顺带记录一下. 1.创建一个SpringBoot项目 点击Next 注意:packaging选中War,点击Next Webà选中W ...
- 【SpringBoot】08.SpringBoot整合jsp
SpringBoot整合jsp 1.修改pom文件加入两个坐标jstl标签库和jasper <project xmlns="http://maven.apache.org/POM/4. ...
- 1、SpringBoot整合之SpringBoot整合JSP
SpringBoot整合JSP 一.创建SpringBoot项目,仅选择Web模块即可 二.在POM文件中添加依赖 <!-- 添加servlet依赖模块 --> <dependenc ...
- springboot整合jsp报错
今天在学springboot整合jsp时遇到了一个问题,虽然jsp不被spring官方推荐使用,但抱着学习的心态还是想解决一下这个问题.在写好了需要pom文件之后,访问网站得到了500的错误提示,后台 ...
- springboot整合JSP以及发布项目到独立的tomcat中与打成jar包使用
之前研究了springboot整合freemarker与thymeleaf的使用.也研究了springboot发布到独立的tomcat的使用以及使用自带的tomcat打成jar包的使用,下面研究集成J ...
随机推荐
- windows10上下载远程控制软件之后导致windows10亮度调节功能不能使用
出现了通用即插即用监视器就可以了
- 20162017-acmicpc-south-pacific-regional-contest-sppc-16 B.Ballon Warehouse
题意:给你一个无限长且元素均为\(0\)的排列,每次给你一对\((x,y)\),表示在所有\(x\)的后面插入一个元素\(y\),最后给你一个区间\((l,r)\),输出\([l,r-1]\)中的所有 ...
- 一、Python简介及下载安装
一.关于Python Python是目前比较受欢迎的脚本语言之一,具有简洁性.易读性以及可扩展性的特点. Python与Java均可以写网页,也可以写后台功能,区别是Python执行效率低,开发效率高 ...
- postcss 运用及原理
postcss 入坑指南 目标: 掌握 postcss 的使用 自定义 postcss 插件 掌握 stylelint 的使用 自定义 stylelint rule 扩展 css parser 解释器 ...
- Navicat 快捷键 for Mysql
常用快捷键: 1. ctrl + q: 打开新查询窗口 2. ctrl + r: 运行当前窗口内的所有语句 3. ctrl + w: 关闭当前窗口 4. F6: 打开一个MySQL命令行窗口 5. ...
- cmder设置方法
一.添加鼠标右键 Cmder.exe /REGISTER ALL 二.添加系统环境变量 我的电脑 > 右键属性 > 高级系统设置 > 环境变量 > 系统变量,在path中添加 ...
- JxBrowser: 6.6.1 Crack
JxBrowser: 6.6.1. 1. RELEASE NOTES Download:HomePage JxBrowser is a cross-platform library that prov ...
- vuepress & ReferenceError: window is not defined
vuepress & ReferenceError: window is not defined bug Client Compiled successfully in 15.35s Serv ...
- Redux React & Online Video Tutorials
Redux React & Online Video Tutorials https://scrimba.com/@xgqfrms https://scrimba.com/c/cEwvKNud ...
- web cache & web storage all in one
web cache & web storage all in one web cache in action web cache best practices web storage in a ...