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>

猜你喜欢

转载自www.cnblogs.com/ALuShu/p/12358118.html