博主的开发环境是 spring boot +mybatis + layui +thymeleaf
解决方案:
如果你的controller不打算返回模板的话就一定别忘了给它加上@Resopnsebody
注解.
eg:
@RequestMapping(value = "/sys_stuff/edit")
public String edit(String id,Model model) {
if (id == null) {
Stuffs stuff = new Stuffs();
}
Stuffs stuff = qingYunService.findStuffById(Integer.parseInt(id));
System.out.println(stuff.toString());
model.addAttribute("stuff",stuff);
return "modifystuff";
}
// @ResponseBody 要加上
@RequestMapping(value = "/sys_stuff/update")
@ResponseBody
public Result update(@RequestParam("name") String name,@RequestParam("id") String id,@RequestParam("lid") String lid,@RequestParam("mid") String mid) {
Stuffs stuff = qingYunService.findStuffById(Integer.parseInt(id));
stuff.setName(name);
System.out.println("次类型id=====>>>"+lid+"主类型id=====>>>"+mid);
LittleTypes littleType = qingYunService.findLittleTypeById(Integer.parseInt(lid));
System.out.println("初始littetype============>>>>>"+littleType.toString());
littleType.setMainTypes(qingYunService.findMainTypeById(Integer.parseInt(mid)));
stuff.setLittleTypes(littleType);
qingYunService.modifyStuff(stuff);
Result result = Result.success();
return Result.success();
}
报错信息:
"Error resolving template "sys_stuff/update",template might not exist or might not be accessible by any of the configured Template Resolvers"
番外:
这个报错信息最让人蒙蔽的不是我看不懂意思,而是我压根就没有写sys_stuff/update这个模板,还有我从未打算渲染这个模板!!
所以,这就让我摸不着头脑了……….
曾经我以为我Ajax(阿加克斯)有问题!然后把js改来改去也不成功!各位看官可以看看我的ajax么!
<script th:src="@{/lib/layui/layui.js}"></script>
<script type="text/javascript" th:inline="javascript"> layui.config({ base: '/js/layui-modules/' }).use(['form','layer','laypage','tools'],function () { var $ = layui.jquery,form = layui.form(),laypage = layui.laypage,tools = layui.tools; //监听提交 //监听提交 data是什么 发送到后台????? form.on('submit(btnSave)',function(data) { //roleId在这里没多少用 $.ajax({ type: 'POST',url: /*[[@{/sys_stuff/update}]]*/'',dataType:'json',data: data.field,async: true,success: function (result) { console.log(result.code) //妈的 没加@Responsebody注解 if (result.code == 0) { layer.msg('success:保存成功',{icon: 1,time:1000}); setTimeout(function(){ top.layer.closeAll('iframe'); //刷新父亲的页面 parent.refreshIframe(); },800); } else { consol.alert(result.code); layer.msg('eles:保存失败!'+result.msg,{icon: 2,time:1000}); } },error: function (result,type) { layer.msg('error:保存失败!',{ icon: 2,time:1000 }); } }); console.log(data.field) return false; }); }); </script>