通过试图解析器 以下是代码请供参考!
@RequestMapping("h_handelList")public ModelAndView h_handelList () throws Exception {
ModelAndView mv = new ModelAndView()
mv.setViewName("/WEB-INF/jsp/h_handelList.html")
return mv
}
也可以在springMVC.xml里配置试图解析器的前缀和后缀
<!-- 配置springmvc的视图解析器 --><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".html"/>
</bean>
配置了前缀后缀后可以这样写:
@RequestMapping("h_handelList")public ModelAndView h_handelList () throws Exception {
ModelAndView mv = new ModelAndView()
mv.setViewName("h_handelList")
return mv
}
试图解析器是必须要配置的 可以不配置前缀后缀!
publicModelAndViewlogin(StringuserName){system.out.println(userName)}少量参数可以这么使用,如果参数较多,请使用对象。如定义个User对象,包含userName,password等的getset方法。publicclassUser{privateStringuserNameprivateStringpassWordpublicStringgetUserName(){returnuserName}publicvoidsetUserName(StringuserName){this.userName=userName}publicStringgetPassWord(){returnpassWord}publicvoidsetPassWord(StringpassWord){this.passWord=passWord}}publicModelAndViewlogin(Useruser){system.out.println(user.getUserName())}页面参数传递仍然是userName等。springmvc会自动绑定到对象。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)