CSS和图像不会出现在Spring上

时间:2013-09-20 19:03:07

标签: spring-mvc

我在spring mvc上写了一些东西,我在配置文件中得到了这个

 @RequestMapping(value={"/userPage"},method = RequestMethod.GET)
    public String userPageController (Model model, Principal principal) {
        username = principal.getName();
        Set<Mesurements> mesurements = java.util.Collections.EMPTY_SET;
        mesurements =  measurementsDAO.findUserMesur(username);

        model.addAttribute("user", username);
        model.addAttribute("mesurements", mesurements);
        return "userPage";      
  } 

   @RequestMapping(value={"/userPage/addProject"}, method = RequestMethod.GET)
        public String addProjectController (Model model, Principal principal) {
        model.addAttribute("user", username);
        return "addProject";      
  }    `

所以当我移动到8084 / Grad / userPage.htm时,会出现所有内容(css,images), 但是当我移动到8084 / Grad / userPage / addProject.htm时,无法显示css或图像

有人可以帮忙吗? thenx

1 个答案:

答案 0 :(得分:0)

您需要添加注册表资源处理程序,如下所示

/**
 * @param registry Resource handler registry
 * @see WebMvcConfigurationSupport#addResourceHandlers(ResourceHandlerRegistry)
 */
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    logger.info("Adding resources handlers");
    final String[] RESOURCES = { "/resources/**" };

    registry.addResourceHandler(RESOURCES).addResourceLocations(RESOURCES).setCachePeriod(86400);
}