第一个springmvc应用程序_注解版

来源:互联网 发布:淘宝网全球购是正品吗 编辑:程序博客网 时间:2024/06/05 15:12
/** * 单例 * 控制器(程序员) * @author AdminTC */@Controllerpublic class HelloAction{public HelloAction(){System.out.println("HelloAction()::" + this.hashCode());}/** * 业务方法 * 只要是/hello.action的请求,都交由HelloAction对象中的hello()方法去处理 */@RequestMapping(value="/hello.action")   public String hello(Model model) throws Exception{System.out.println("HelloAction::hello()");model.addAttribute("message","你好");return "success";}/** * 业务方法 * 只要是/bye.action的请求,都交由HelloAction对象中的bye()方法去处理 */@RequestMapping(value="/bye.action")   public String bye(Model model) throws Exception{System.out.println("HelloAction::hello()");model.addAttribute("message","再见");return "success";}}


spring.xml中<context:component-scan base-package="cn.itcast.javaee.springmvc.app14"/><!-- 视图解析器 --><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/jsp/"/><property name="suffix" value=".jsp"/>        </bean>