**
SpringMvc注解实现
1.编辑HelloController
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller//必需要手输从idea引用的选
public class HelloController {
@RequestMapping("/hello")//表示路径 /hello 会映射到该方法上
public ModelAndView handleRequest(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse) throws Exception {
ModelAndView mav = new ModelAndView("index.jsp");
mav.addObject("message", "Hello Spring MVC666");
return mav;
}
}
2.修改dispatcher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- <bean id="simpleUrlHandlerMapping"-->
<!-- class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">-->
<!-- <property name="mappings">-->
<!-- <props>-->
<!-- <!– /hello 路径的请求交给 id 为 helloController 的控制器处理–>-->
<!-- <prop key="/hello">helloController</prop>-->
<!-- </props>-->
<!-- </property>-->
<!-- </bean>-->
<!-- <bean id="helloController" class="controller.HelloController"></bean>-->
//扫描controller下组件
<context:component-scan base-package="controller"/>
</beans>
3.运行结果
**