我是百里香的新人,百万美元模板引擎真的很好,但我面临一些关键问题,这对我来说很难理解。我的流程如下:
首先调用add user controller并在数据库中添加新用户。保存新用户后,重定向到用户列表页面。当用户列表页面打开时,我的新用户不会显示在用户列表中。刷新页面后,我的新用户可见。当我调试代码并检查用户列表控制器。用户列表控制器获取新的用户详细信息,但我的百万美元没有显示新的更改。我的百万美元缓存也是假的。我正在使用如下的百里香布局方言:
https://github.com/ultraq/thymeleaf-layout-dialect
我的控制器代码:
@RequestMapping(value="/add-user", method=RequestMethod.POST)
public String addEditCategory(User user, RedirectAttributes attributes) {
userService.saveNewUser(user);
return "redirect:/user/userlist";
}
@RequestMapping(value="/userlist", method=RequestMethod.GET)
public String productCategory(Model model, Pageable pageable) {
Page<User> page = productCategoryService.findAllUsers(pageable);
List<User> users= page.getContent();
PageWrapper<ProductCategory> pageWrapper = new PageWrapper<User>(page, "/user/userlist");
model.addAttribute("page", pageWrapper);
model.addAttribute("users", categories);
return "admin/user/view-users";
}
我的Thymeleaf配置:
/* Thymeleaf configuration */
private ServletContextTemplateResolver templateResolver() {
ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver();
templateResolver.setPrefix("/WEB-INF/views/");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode("HTML5");
templateResolver.setCacheable(false);
return templateResolver;
}
private SpringTemplateEngine templateEngine() {
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.addDialect(new LayoutDialect());
templateEngine.setTemplateResolver(templateResolver());
return templateEngine;
}
private ThymeleafViewResolver thymeleafViewResolver() {
ThymeleafViewResolver thymeleafViewResolver = new ThymeleafViewResolver();
thymeleafViewResolver.setCharacterEncoding("UTF-8");
thymeleafViewResolver.setViewClass(ThymeleafView.class);
thymeleafViewResolver.setViewNames(new String[]{"user/**"});
thymeleafViewResolver.setTemplateEngine(templateEngine());
return thymeleafViewResolver;
}
我正在使用ContentNegotiatingViewResolver
作为注册视图解析器。问题,就像缓存问题。但我怎么解决这个问题?
更新
添加用户: - 点击按钮,将出现fancybox。在花哨的盒子里,我使用表格并在/add-user
网址上提交表单。
更新
ContentNegotiatingViewResolver代码:
@Bean
public ViewResolver setupViewResolver(ContentNegotiationManager manager) {
List<ViewResolver> resolvers = new ArrayList<ViewResolver>();
resolvers.add(tilesViewResolver());
resolvers.add(thymeleafViewResolver());
resolvers.add(jspViewResolver());
ContentNegotiatingViewResolver viewResolver = new ContentNegotiatingViewResolver();
viewResolver.setViewResolvers(resolvers);
viewResolver.setContentNegotiationManager(manager);
return viewResolver;
}
答案 0 :(得分:0)
禁用缓存添加 -
thymeleafViewResolver.setCache(false);