• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

springboot整合jsp,实现公交车站路线图

springboot 搞代码 4年前 (2022-01-05) 11次浏览 已收录 0个评论
文章目录[隐藏]

这篇文章主要介绍了springboot整合jsp,实现公交车站路线图的步骤,帮助大家更好的理解和使用springboot框架,感兴趣的朋友可以了解下

开发环境:

  1. jdk 8
  2. intellij idea
  3. tomcat 8
  4. mysql 5.7
  5. maven 3.6

所用技术:

  • springboot
  • jsp
  • 数据静态初始化

项目介绍

使用springboot整合jsp,在后端写入公交路线名称和详细站点,前端页面可条件查询具体的内容,如公交路线,公交名称,车俩信息等。

运行效果

前台用户端:

  • 路线选择

  • 路线详情

数据准备:

BusData.txt

准备工作:

pom.xml加入jsp模板引擎支持:

  org.apache.tomcat.embed<mark style="color:transparent">来源gaodaimacom搞#^代%!码&网</mark>tomcat-embed-jasperprovided

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<locations.length;i++){ int busnum=0; if(i%4==0){        //随机busnum busnum=1; }if(i%5==0){ busnum=2; } Bus bus=new Bus(locations[i],busnum); list.add(bus); } WayList.add(way);      //添加路线 BusMap.put(way,list);    //添加车站 } } }catch (Exception e){ e.printStackTrace(); } }

路线查询

 @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";//没有对应公交车站 } //前端页面数据渲染 <div class="pageContent" style="background: #eeeeee"> <div class="pageFormContent"> <div class="timeText">${firstBus}${lastBus} <span>( 首/末班车时间:<span style="color: red">6:00 / 23:00</span>)</span></div><div class="timezone" style="margin-top: 20px">  <div class="time"  style="top: ${s.index*100+25}px;" a="1"  >${s.index+1}<h2>${list.location}</h2>0}"> <span class="timezone3"></span><div> <p><span style="padding-left: 30px">${list.busNum}辆公交</span></p></div></div></div></div><div class="formBar"></div></div>

项目总结

  1. 项目存放路径最好不要带中文路径,否则可能存在静态busData资源初始化失败
  2. 页面时间车站路线所采用时间轴方式展示,长度动态计算,部分浏览器显示可能有点错位
  3. 其他后续迭代功能后续开发,敬请关注

以上就是springboot整合jsp,实现公交车站路线图的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:springboot整合jsp,实现公交车站路线图

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址