SpringMVC:ParameterizableViewController

    xiaoxiao2025-09-03  306

    开发中经常遇到一个场景: 项目规定所有的Url都必须为.action结尾,但是我有一个html的页面就是一个普通页面。但是又不能直接暴漏这个资源(xxx.html直接访问).这样的话,通常人们就想到,我写一个Controller类来实现就可以了。然后写一个方法,返回这个页面。 往往就是如此

    @Controller @RequestMapping("/") public class HomeHandler { @Autowired@Qualifier("helloWorldClient") HelloCXF helloCxf; @RequestMapping("home") public String home(HttpServletRequest request,Model model){ return "home.html" } }

    非常正确,可行方案。 但是今天我们用SpringMVC的一个方案: ParameterizableViewController org.springframework.web.servlet.mvc.ParameterizableViewController 产生同样的效果,但是我们只需要在配置文件中去配置就可以了。

    xml配置如下

    <bean name="/index.action" class="org.springframework.web.servlet.mvc.ParameterizableViewController"> <property name="viewName" value="/index.jsp"/> </bean>
    转载请注明原文地址: https://ju.6miu.com/read-1302263.html
    最新回复(0)