我有以下控制器
@Controller
@RequestMapping("/room/{roomId:^(?!main.html$).*}")
public class Rooms {
@RequestMapping
public String index(@PathVariable(value = "roomId") String id) {
// do some stuff...
return "main.html";
}
}
我的资源/静态文件夹中有一个main.html文件。我希望当用户进入/ room / {something}进行处理时,返回我的静态main.html页面。
我尝试的所有内容都会导致页面找不到异常或
javax.servlet.ServletException: Circular view path [main.html]:
would dispatch back to the current handler URL
[/room/main.html] again
我错过了什么才能让它发挥作用?
感谢您的帮助
答案 0 :(得分:0)
如果您正在为视图解析器进行类配置
@Bean
public UrlBasedViewResolver urlBasedViewResolver()
{
UrlBasedViewResolver res = new InternalResourceViewResolver();
res.setViewClass(JstlView.class);
res.setPrefix("/WEB-INF/");
res.setSuffix(".jsp");
return res;
}
如果使用xml
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/jsp/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
还可以通过以下代码更改您的控制器
@RestController
@RequestMapping("/room/")
public class Rooms {
@RequestMapping(method = RequestMethod.GET)
public ModelAndView index(@PathVariable(value = "roomId") String id) {
// do some stuff...
ModelAndView model = new ModelAndView();
model.setViewName("main");
return model;
}
}