写了一个简略的主页,直接 forward 实现
@EnableWebMvc
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("forward:/项目名 /static/xxx.html");
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
super.addViewControllers(registry);
}
}
这么写完之后页面能正常访问,但是页面静态资源访问不了了(/resources/templates/static/img/xxx.jpg ) 而且原本正常的增删改查也不行了,所以请教一下各位这里可以怎么写? (去掉 forward 同理)
项目结构:
|——代码
|—— resources
|———— static
|—————— img
|—————— js
|———— templates
|—————— static
|———————— xxx.ftl
目前解决方法是加了个 controller mvc 跳转做了个 home.ftl ,可以正常访问 home,然后通过 home 跳转,但是我想知道这种方式和上面 springboot 默认启动有什么区别?为什么上面的会出现 CRUD 不正常的问题?想要正常 forward 话应该如何使用?
@Controller
public class MainPageController {
@RequestMapping("/")
public ModelAndView home() {
ModelAndView res = new ModelAndView("home");
return res;
}
}