基于懒,花了点时间研究了一下 SpringBoot,个人觉得也就是一个懒人版的 SS 框架
我的 demo git 地址:http://git.oschina.net/zgdhd/my-springboot 希望里面的注释能帮助初学的师弟
问题:
打包成 jar 在终端运行启动后访问页面提示找不到 thymeleaf 模版!!
Exception:
14:13:58.749 logback [http-nio-8080-exec-1] INFO org.thymeleaf.TemplateEngine - [THYMELEAF] TEMPLATE ENGINE INITIALIZED
14:13:58.840 logback [http-nio-8080-exec-1] ERROR org.thymeleaf.TemplateEngine - [THYMELEAF][http-nio-8080-exec-1] Exception processing template "/bug": Error resolving template "/bug", template might not exist or might not be accessible by any of the configured Template Resolvers
14:13:58.847 logback [http-nio-8080-exec-1] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/bug", template might not exist or might not be accessible by any of the configured Template Resolvers] with root cause
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/bug", template might not exist or might not be accessible by any of the configured Template Resolvers
at org.thymeleaf.TemplateRepository.getTemplate(TemplateRepository.java:246)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1104)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1060)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1011)
at org.thymeleaf.spring4.view.ThymeleafView.renderFragment(ThymeleafView.java:335)
at org.thymeleaf.spring4.view.ThymeleafView.render(ThymeleafView.java:190)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1286)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1041)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:984)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
thymeleaf 配置:
Controller:
@Resource
private UserDao userDao;
@RequestMapping("/q")
public ModelAndView index() {
// String sql = "select name, age from user";
// ModelAndView modelAndView = new ModelAndView("/bug");
// modelAndView.addObject("data",jdbcTemplate.queryForList(sql));
ModelAndView modelAndView = new ModelAndView("/bug");
PageHelper.startPage(1,2);
modelAndView.addObject("data",userDao.query());
return modelAndView;
}
在 Idea 里面完美运行!狗日的打包成 jar 后就报 bug!!
解决:
把 Controller -> ModelAndView 里面的地址中的斜杠“/”去掉!(“/bug” --> “bug”)
我去,这坑定的....习惯....习惯在SS里面跳转地址的时候都要加一个斜杠~~