Like it and see. Make it a habit

Development environment:

  1. jdk 8
  2. intellij idea
  3. tomcat 8
  4. Mysql 5.7
  5. Maven 3.6

Technology used:

  1. springboot
  2. jsp
  3. Data is statically initialized

Project introduction

Use Springboot integration JSP, back-end write bus route name and detailed site, front-end page can be conditional query specific content, such as bus route, bus name, car information and so on.

Running effect

Front end client:

  • Route selection

  • Route details

Data preparation:

  • BusData.txt

Preparations:

  1. Pom.xml added JSP template engine support:
<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
    <scope>provided</scope>
</dependency>
Copy the code
  1. JSP springboot configuration
spring.mvc.view.prefix=/
spring.mvc.view.suffix=.jsp
Copy the code

Important code:

  1. Bus data is initialized
@PostConstruct private void initBusData(){ try{ File file = new File(BusMap.getClass().getResource("/").getPath()); FileReader fileReader = new FileReader(file.getPath()+"/static/BusData.txt","GBK"); List<String> readLines = filereader.readlines (); for(String str:readLines){ if(!" ".equals(str)){ String[] data=str.split("#"); String way=data[0]; // String location=data[1]; [] locations=location.split(","); List<Bus> 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(); }}Copy the code
  1. The route query
@RequestMapping("/way") public String search(HttpServletRequest request,String way) { try { if(null==way||"".equalsIgnoreCase(way)){ request.setAttribute("list", BusMap.WayList); Return "way"; }else{ List<String> 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"; }Copy the code
  1. Bus route station display
@RequestMapping("/view") public String view(HttpServletRequest request,String way) { try { List<Bus> 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" layoutH="55"> <div class="timeText">${firstBus}<----->${lastBus} <span> <span style="color: red"> 6:00/23:00 </span>) </span> </div> <div class="timezone" style="margin-top: 20px"> <c:forEach var="list" items="${list}" varStatus="s"> <div class="time" <c:if test="${s.index! =0}"> style="top: ${s.index*100+25}px;" a="1" </c:if> ><a onclick="javascript:alert(1);" >${s.index+1}</a> <h2>${list.location}</h2> <c:if test="${list.busNum>0}"> <span class="timezone3"></span> <div> <p><span style="padding-left: 30px;" > ${list. BusNum} bus < / span > < / p > < / div > < / c: if > < / div > < / c: forEach > < / div > < / div > < div class = "formBar" > < / div > < / div >Copy the code

Project summary

  1. Do not save the project path in Chinese. Otherwise, static busData resource initialization may fail
  2. Page time station route is displayed in the way of timeline, the length of dynamic calculation, some browser display may be a little misplaced
  3. Other subsequent iteration functions will be developed in the future, please pay attention