Spring3 MVC 中如果使用如下代码:查询navigations之后,put到model中,
@Override
@RequestMapping(value = "/frontpage", method = RequestMethod.GET)
public ModelAndView index() {
List<Navigation> navigations = navigationManager.queryAll(new LinkedHashMap<String, String>());
HashMap<String, Object> model = new HashMap<String, Object>();
model.put("currentDate", getCurrentDate());
model.put("basePath", getBasePath());
model.put("navigations", navigations);
return new ModelAndView("product/frontpage/productlist",model);
}
在页面采用如下形式访问:
<c:forEach items="${navigations}" var="navigation"> <LI id="ProducType${navigation.id}Home"> <a href="${basePath}/${navigation.navigationURL}" target="${navigation.target}"><span>${navigation.navigationName }</span> </a> </LI> </c:forEach>
是正常的,但是要是你手动的更改了数据库中记录,比如删掉了一条数据之后,Spring会认为你这个视图将不存在了!这是为什么呢?原因是Sping的缓存机制,我们在配置viewResolvers 的时候使用了如下的属性:
<bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"> <property name="cache" value="true" /> <property name="prefix" value="" /> <property name="suffix" value=".ftl" /> <property name="exposeSpringMacroHelpers" value="true" /> <property name="exposeRequestAttributes" value="true" /> <property name="exposeSessionAttributes" value="true" /> <property name="contentType" value="text/html;charset=UTF-8" /> </bean>将其<property name="cache" value="true" />更改为:<property name="cache" value="false" /> 之后将不会有这种事情发生了