qwb0614

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
  187 随笔 :: 0 文章 :: 0 评论 :: 2048 阅读

1.index.html

复制代码
<!DOCTYPE html>
<html lang="en" xmlns="">
<head>
    <meta charset="UTF-8">
    <title>品牌</title>

</head>
<body>

<div id="subway">

    <template>

        <el-tabs :tab-position="tabPosition" style="height: 200px;">
            <el-tab-pane label="换乘查询">

                <el-form :inline="true" :model="formInline" class="demo-form-inline">
                    <el-form-item label="起始站点">
                        <el-input v-model="startName" placeholder="请输入起始站点"></el-input>
                    </el-form-item>
                    <el-form-item label="终点站点">
                        <el-input v-model="endName" placeholder="请输入终点站点"></el-input>
                    </el-form-item>
                    <el-form-item >
                        <el-button type="primary" @click="selectShortestPath">查询</el-button>
                    </el-form-item>
                </el-form>

            </el-tab-pane>

            <el-tab-pane label="线路查询">
                <el-form :inline="true" :model="formInline" class="demo-form-inline">
                    <el-form-item label="线路名称">
                        <el-input v-model="routeName" placeholder="请输入线路名称"></el-input>
                    </el-form-item>
                    <el-form-item >
                        <el-button type="primary" @click="check_route">查询</el-button>
                    </el-form-item>
                </el-form>
            </el-tab-pane>

            <el-tab-pane label="站点查询">

                <el-form :inline="true" :model="formInline" class="demo-form-inline">
                    <el-form-item label="站点名称">
                        <el-input v-model="input" placeholder="请输入站点"></el-input>
                    </el-form-item>
                    <el-form-item >
                        <el-button type="primary" @click="check_point">查询</el-button>
                    </el-form-item>
                </el-form>



            </el-tab-pane>
        </el-tabs>
    </template>




<!--    <el-button type="text" @click="dialogVisible = true">点击打开 Dialog</el-button>-->

    <el-dialog
            title="提示"
            :visible.sync="dialogVisible"
            width="70%"
            :before-close="handleClose">
        <span slot="footer" class="dialog-footer">
                <template>
                    <el-table
                            :data="tableData"
                            border
                            style="width: 100%">
                        <el-table-column
                                align="center"
                                type="index"
                                width="30">
                        </el-table-column>
                        <el-table-column
                                align="center"
                                prop="subwayName"
                                label="地铁站点名称"
                                width="320">
                        </el-table-column>
                        <el-table-column
                                align="center"
                                prop="routeName"
                                label="所属线路"
                                width="320">
                        </el-table-column>
                        <el-table-column
                                align="center"
                                prop="subwaySerial"
                                label="邻接站点"
                                width="320">
                        </el-table-column>
                    </el-table>
                </template>

    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
  </span>
    </el-dialog>

    <el-dialog
            title="提示"
            :visible.sync="dialogVisible2"
            width="80%"
            :before-close="handleClose">
        <span slot="footer" class="dialog-footer">
             <template>
                <el-table
                        :data="tableData2"
                        border
                        style="width: 100%">
                <el-table-column
                        align="center"
                        type="index"
                        width="50">
                </el-table-column>
                <el-table-column
                        align="center"
                        prop="route"
                        label="地铁站点名称"
                        width="1100">
                </el-table-column>
                </el-table>
            </template>

    <el-button @click="dialogVisible2 = false">取 消</el-button>
    <el-button type="primary" @click="dialogVisible2 = false">确 定</el-button>
  </span>
    </el-dialog>

    <el-dialog
            title="提示"
            :visible.sync="dialogVisible3"
            width="80%"
            :before-close="handleClose">
        <span slot="footer" class="dialog-footer">
             <template>
                <el-table
                        :data="tableData3"
                        border
                        style="width: 100%">
                <el-table-column
                        align="center"
                        type="index"
                        width="50">
                </el-table-column>
                <el-table-column
                        align="center"
                        prop="findpath"
                        label="路线"
                        width="1100">
                </el-table-column>
                </el-table>
            </template>

    <el-button @click="dialogVisible3 = false">取 消</el-button>
    <el-button type="primary" @click="dialogVisible3 = false">确 定</el-button>
  </span>
    </el-dialog>

</div>
<script src="js/axios-0.18.0.js"></script>
<script src="js/vue.js"></script>
<script src="element-ui/lib/index.js"></script>
<link rel="stylesheet" href="element-ui/lib/theme-chalk/index.css">

<script>
    new Vue({
        el:"#subway",
        data(){

            return {
                dialogVisible: false,
                dialogVisible2:false,
                dialogVisible3:false,
                activeName: 'second',
                input: "",
                tabPosition: 'left',
                tableData:[],
                tableData2:[],
                tableData3:[],
                routeName:"",
                startName:"",
                endName:""

            }
        },

        mounted(){
            // 页面加载完成后,发送异步请求,查询数据
            // var _this = this;
            // axios({
            //     method:"get",
            //     url:"http://localhost:8080/Login/selectAllServlet"
            // }).then(function (resp) {
            //     _this.brands = resp.data;
            // })
        },

        methods:{

            handleClose(done) {
                this.$confirm('确认关闭?')
                    .then(_ => {
                        done();
                    })
                    .catch(_ => {});
            },

            handleClick(tab, event) {
                console.log(tab, event);
            },
            check_point()
            {
               // var _this=this;
                axios({
                    method:"post",
                    url:"http://localhost:8080/subway/sub/check_point",
                    data:this.input
                }).then(resp=> {
                    this.tableData=resp.data;
                    console.log("+++"+resp.data);
                })
                this.dialogVisible = true;
            },
            check_route()
            {
                axios({
                    method:"post",
                    url:"http://localhost:8080/subway/sub/check_route",
                    data:this.routeName
                }).then(resp=> {
                    this.tableData2=resp.data;
                })
                this.dialogVisible2 = true;
            },
            selectShortestPath()
            {
                axios({
                    method:"post",
                    url:"http://localhost:8080/subway/sub/selectShortestPath?startName="+this.startName+"&endName="+this.endName,
                    // data:this.routeName
                }).then(resp=> {
                    this.tableData3=resp.data;
                })
                this.dialogVisible3 = true;
            }
        }


    })
</script>
</body>
</html>
复制代码

2.subwayServelt

复制代码
package com.itheima.web;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.itheima.pojo.SubCheck;
import com.itheima.pojo.Subway_point;
import com.itheima.service.SubwayService;
import com.itheima.service.impl.SubwayServiceImpl;
import com.itheima.util.FindPathUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.net.SocketTimeoutException;
import java.util.List;

@WebServlet("/sub/*")
public class SubwayServlet extends BaseServlet {
    private SubwayService subwayService = new SubwayServiceImpl();
    private FindPathUtils FindPathUtil = new FindPathUtils();
    public void check_point(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");

        //1. 接收品牌数据
        BufferedReader br = request.getReader();
        String params = br.readLine();//json字符串
        System.out.println(params);
        //转为Brand对象
       // String subway_name = JSON.parseObject(params, String.class);

        //1. 调用service查询
        Subway_point point = subwayService.check_point(params);

        System.out.println(point);
        //2. 转为JSON
        String jsonString = JSON.toJSONString(point, SerializerFeature.IgnoreErrorGetter);

        System.out.println(jsonString);
        //3. 写数据
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write("["+jsonString+"]");
    }
    public void check_route(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");

        //1. 接收品牌数据
        BufferedReader br = request.getReader();
        String params = br.readLine();//json字符串
        System.out.println(params);
        //转为Brand对象
        // String subway_name = JSON.parseObject(params, String.class);

        //1. 调用service查询
        String checkRoute = subwayService.check_route(params);

        System.out.println(checkRoute);
        //2. 转为JSON
        String jsonString = JSON.toJSONString(checkRoute, SerializerFeature.IgnoreErrorGetter);

        System.out.println("[{\"route\":"+jsonString+"}]");
        //3. 写数据
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write("[{\"route\":"+jsonString+"}]");
    }
    public void selectShortestPath(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
//        String startName = request.getParameter("startName");
//        String endName = request.getParameter("endName");
        String startName = new String(request.getParameter("startName").getBytes("iso-8859-1"), "utf-8");
        String endName = new String(request.getParameter("endName").getBytes("iso-8859-1"), "utf-8");
        System.out.println(startName);
        System.out.println(endName);

        Subway_point sub_start = subwayService.check_point(startName);
        Subway_point sub_end = subwayService.check_point(endName);

        SubCheck sc_start=new SubCheck();
        sc_start.setSubway_point(sub_start);
        SubCheck sc_end=new SubCheck();
        sc_end.setSubway_point(sub_end);
        String findpath = FindPathUtil.Findpath(sc_end, sc_start);
        System.out.println(findpath);
        String jsonString = JSON.toJSONString(findpath, SerializerFeature.IgnoreErrorGetter);

        System.out.println("[{\"findpath\":"+jsonString+"}]");
        //3. 写数据
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write("[{\"findpath\":"+jsonString+"}]");
    }
}
复制代码

 

 

 

1.路线查询

 2.线路信息查询

 3.站点查询

 

 

在数据库中存储线路信息,站点信息,以及站点相邻的站点记录信息,在前端查询时,通过代码算法实现快速找到最短路径

posted on   嘎嘎鸭1  阅读(12)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示