Error resolving template [], template might not exist or might not be accessible by any

时间:2025-03-18 07:57:09

错误提示:

2022-01-25 23:10:56.182 ERROR 2716 — [nio-8080-exec-8] .[.[.[/].[dispatcherServlet] : () for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is : Error resolving template [back/treedata], template might not exist or might not be accessible by any of the configured Template Resolvers] with root cause

: Error resolving template [back/treedata], template might not exist or might not be accessible by any of the configured Template Resolvers
at (:869) ~[thymeleaf-3.0.:3.0.]
at (:607) ~[thymeleaf-3.0.:3.0.]
at (:1098) ~[thymeleaf-3.0.:3.0.]
at (:1072) ~[thymeleaf-3.0.:3.0.]
at .(:366) ~[thymeleaf-spring5-3.0.:3.0.]
at .(:190) ~[thymeleaf-spring5-3.0.:3.0.]
at (:1393) ~[spring-webmvc-5.3.:5.3.3]
at (:1138) ~[spring-webmvc-5.3.:5.3.3]
at (:1077) ~[spring-webmvc-5.3.:5.3.3]
at (:962) ~[spring-webmvc-5.3.:5.3.3]
at (:1006) ~[spring-webmvc-5.3.:5.3.3]
at (:898) ~[spring-webmvc-5.3.:5.3.3]
at (:626) ~[tomcat-embed-core-9.0.:4.]
at (:883) ~[spring-webmvc-5.3.:5.3.3]
at (:733) ~[tomcat-embed-core-9.0.:4.]
at (:231) ~[tomcat-embed-core-9.0.:9.0.41]
at (:166) ~[tomcat-embed-core-9.0.:9.0.41]
at (:53) ~[tomcat-embed-websocket-9.0.:9.0.41]
at (:193) ~[tomcat-embed-core-9.0.:9.0.41]
at (:166) ~[tomcat-embed-core-9.0.:9.0.41]
at (:100) ~[spring-web-5.3.:5.3.3]
at (:119) ~[spring-web-5.3.:5.3.3]
at (:193) ~[tomcat-embed-core-9.0.:9.0.41]
at (:166) ~[tomcat-embed-core-9.0.:9.0.41]
at (:93) ~[spring-web-5.3.:5.3.3]
at (:119) ~[spring-web-5.3.:5.3.3]
at (:193) ~[tomcat-embed-core-9.0.:9.0.41]
at (:166) ~[tomcat-embed-core-9.0.:9.0.41]
at (:201) ~[spring-web-5.3.:5.3.3]
at (:119) ~[spring-web-5.3.:5.3.3]
at (:193) ~[tomcat-embed-core-9.0.:9.0.41]
at (:166) ~[tomcat-embed-core-9.0.:9.0.41]
at (:202) ~[tomcat-embed-core-9.0.:9.0.41]
at (:97) [tomcat-embed-core-9.0.:9.0.41]
at (:542) [tomcat-embed-core-9.0.:9.0.41]
at (:143) [tomcat-embed-core-9.0.:9.0.41]
at (:92) [tomcat-embed-core-9.0.:9.0.41]
at (:78) [tomcat-embed-core-9.0.:9.0.41]
at (:343) [tomcat-embed-core-9.0.:9.0.41]
at .http11.(:374) [tomcat-embed-core-9.0.:9.0.41]
at (:65) [tomcat-embed-core-9.0.:9.0.41]
at C o n n e c t i o n H a n d l e r . p r o c e s s ( A b s t r a c t P r o t o c o l . j a v a : 888 ) [ t o m c a t − e m b e d − c o r e − 9.0.41. j a r : 9.0.41 ] a t o r g . a p a c h e . t o m c a t . u t i l . n e t . N i o E n d p o i n t (:888) [tomcat-embed-core-9.0.:9.0.41] at ConnectionHandler.process(AbstractProtocol.java:888)[tomcatembedcore9.0.41.jar:9.0.41]atorg.apache.tomcat.util.net.NioEndpoint(:1597) [tomcat-embed-core-9.0.:9.0.41]
at (:49) [tomcat-embed-core-9.0.:9.0.41]
at (:1149) [na:1.8.0_201]
at W o r k e r . r u n ( T h r e a d P o o l E x e c u t o r . j a v a : 624 ) [ n a : 1.8. 0 2 01 ] a t o r g . a p a c h e . t o m c a t . u t i l . t h r e a d s . T a s k T h r e a d (:624) [na:1.8.0_201] at Worker.run(ThreadPoolExecutor.java:624)[na:1.8.0201]atorg.apache.tomcat.util.threads.TaskThread(:61) [tomcat-embed-core-9.0.:9.0.41]
at (:748) [na:1.8.0_201]

错误原因

我是在一个layui的弹窗上面发起的ajax请求,因此返回给了当前的页面地址导致了跨页面(异步请求嘛返回了不同页面导致找不到页面的错误

 @RequestMapping(/treedata")
    public String cateManagetree(Model model){
        QueryWrapper<Category> wrapper = new QueryWrapper<>();
        wrapper.eq("parent_id",0);
        List<Category> list = cateService.findByParent(wrapper);
        model.addAttribute("cates",list);
        return "/back/cate-manage_2";
}

解决办法

最终修改为

@RequestMapping("/treedata")
@ResponseBody
public List<Category> cateManagetree(){
    QueryWrapper<Category> wrapper = new QueryWrapper<>();
    wrapper.eq("parent_id",0);
    List<Category> list = cateService.findByParent(wrapper);
    return list;
}

附前端代码

<form class="layui-form" id="test" style="display: none">


    <div class="layui-form-item">
        <label class="layui-form-label">父ID</label>
        <div class="layui-input-block">
            <select name="parentId" lay-search id="parent">
                <option value="0">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">关键字</label>
        <div class="layui-input-block">
            <input type="text" name="cname" required  lay-verify="required" placeholder="请输入关键字" autocomplete="on" class="layui-input" id="username" style="width:100px">
        </div>
    </div>

</form>
layui.use(['jquery', 'excel','form','layer','laydate'], function(){
    var form = layui.form,
        $ = layui.jquery

    $.post("/back/treedata", function (data) {
        $.each(data, function (index, item) {
            jQuery("<option></option>").val(item.cid).text(item.cname).appendTo("#parent");
        })
        form.render("select");
    })
 })

function x_admin_show(){
    layui.use(['jquery', 'excel','form','layer','laydate'], function() {
        layer.open({
            type: 1,
            area: ['500px', '300px'],
            title: '添加种类',
            content: $('#test'),
            shade: 0,
            btn: ['提交']
            , btn1: function (index, layero) {
                $.post({
                    url: "/back/cateadd",
                    data: $("#test").serialize(),
                    success: function (data) {
                        if (data.code == 200)
                            alert("成功")
                    }
                })
            },

            cancel: function (layero, index) {
                layer.closeAll();
            }
        })
    })
}