方式一:实现Controller接口
public class Test01 implements Controller {
@Override
public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
System.out.println("Controller接口 ..............");
return null;
}
}
注意: 方式一是实现org.springframework.web.servlet.mvc.Controller接口
方式二:实现HttpRequestHandler 接口
public class Test02 implements HttpRequestHandler {
@Override
public void handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
System.out.println("HttpRequestHandler.........");
}
}
方式三:使用@Controller注解
@Controller
public class Test03 {
@RequestMapping("/test03")
public void test03(){
System.out.println("Controller注解 ......");
}
}
<context:component-scan base-package="com.luo.web"/>
<bean name="/test01" class="com.luo.web.Test01"/>
<bean id="/test02" class="com.luo.web.Test02"/>
http://localhost:8080/test01
http://localhost:8080/test02
http://localhost:8080/test03
控制台输出