最近开发基于SpringBoot + Thyemleaf 项目的时候,一直出现模板找不到的错误,看网上有好多说是路径配置可能多了 “/” 的问题,也有说是template路径下的文件夹或者命名有错误,而对于我来说都不是,最后找到错误,哎,还是不够信息的原因。
解决方案:
@RequiresPermissions("act:model:add")
@PostMapping("/create")
public AjaxResult create(@RequestParam("name") String name ,
@RequestParam("category") String category,
@RequestParam("description") String description ,
@RequestParam("scope") String scope,
@RequestParam("deptId") String deptId){
try {
actModelService.create(name ,category,description,scope,deptId);
return success("模型创建成功!");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
logger.error("创建模型失败",e);
return error("模型创建失败!");
}
}
因为返回结果的时候忘记加上 @ResponseBody 注解,让SpringMVC一直以为我返回的页面,最终出现上述错误,引以为戒。