0
这里我不想写@requestMapping所以除了那个什么东西都会写在spring.xml文件里。 我想知道这两种情况,如果我不使用@requestmapping类级别和方法级别,我必须写什么?除了@requestMapping我们可以在春天写什么?
这里我不想写@requestMapping所以除了那个什么东西都会写在spring.xml文件里。 我想知道这两种情况,如果我不使用@requestmapping类级别和方法级别,我必须写什么?除了@requestMapping我们可以在春天写什么?
要配置用SpringMVC有两种方式XML配置和注释配置:
spring-mvc-config.xml:这里我们将/hello
映射到helloWorldController
<beans ...>
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/hello">helloWorldController</prop>
</props>
</property>
</bean>
<bean id="helloWorldController" class="xx.yy.zz.HelloWorldController" />
</beans>
HelloWorldController
应该从AbstractController
延伸并实现handleRequestInternal()
:
公共类HelloWorldController延伸一个AbstractController {
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
ModelAndView model = new ModelAndView("hello");
model.addObject("message", "HelloWorld!");
return model; //will go to hello.jsp
}
}
@Controller
public class HelloWorldController
{
@RequestMapping("/hello")
protected ModelAndView hello() throws Exception {
ModelAndView model = new ModelAndView("hello");
model.addObject("message", "HelloWorld!");
return model; //will go to hello.jsp
}
}
我们在哪写这个xml文件在hybris的意思是哪个扩展名? –
storefront \ web \ webroot \ WEB-INF \ config \ spring-mvc-config.xml –
感谢提供的信息 –