Spring boot+Thymeleaf傳參跳轉


$.ajax():

$.ajax({
                    type: "get",
                    url:"/public/inform",
                    async: true,
                    data: detailJson,
                    success:function (data) {
                        window.location.href = '/public/informDetail/'+data.id;
                    }
                });

controller:

/**
     * 下面兩個方法服務於ajax跳轉
     */
    @RequestMapping(value = "/inform", method = RequestMethod.GET)
    @ResponseBody
    public Map inform(Inform detailJson){
        HashMap<String,Object> resMap = new HashMap<>();
        resMap.put("code",1);
        resMap.put("id",detailJson.getId());
        return resMap;
    }
    @RequestMapping(value = "/informDetail/{id}",method = RequestMethod.GET)
    public String informDetail(Model model, @PathVariable("id") Integer id){
        Inform inform = informService.selectInform(id);
        model.addAttribute("detail", inform);
        return "/informDetail";
    }

新頁面:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>通知詳情頁</title>
    <!-- 我其他頁面都是../layui的,因為這個這個控制器類我寫了@RequestMapping("/public"),方法寫了@RequestMapping("//informDetail/{id}"),會導致資源不是訪問http://localhost:8088/layui,而是訪問成http://localhost:8088/public/layui -->
    <link rel="stylesheet" href="../../layui/css/layui.css" type="text/css">
</head>
<body>

<input th:value="${detail.getId()}"/>

</body>
</html>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM