SpringMVC annotation注解版helloworld
来源:互联网 发布:林俊杰 睡粉 知乎 编辑:程序博客网 时间:2024/06/07 23:00
这里结合我的上一篇文章,讲的是xml的helloworld.
web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name></display-name> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 可以设置Dispatcher的初始化参数来设置spring配置文件的地址 classpath就是 /src地址 --> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:mvc.xml</param-value> </init-param> <!-- Servlet配置信息要写在load-ons-startup前面 --> <load-on-startup>1</load-on-startup> </servlet> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>*.html</url-pattern> </servlet-mapping></web-app>
mvc.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:p="http://www.springframework.org/schema/p" 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="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean> <!-- 注解扫描器 --> <context:component-scan base-package="cn.han.controller"/></beans>HelloController.java
package cn.han.controller;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.servlet.ModelAndView;@Controllerpublic class HelloController {@RequestMapping("/hello")public ModelAndView hello(HttpServletRequest req,HttpServletResponse rep){ModelAndView mv=new ModelAndView();mv.addObject("msg", "hello spring mvc annotation!!");mv.setViewName("hello");return mv;}}
0 0
- SpringMVC annotation注解版helloworld
- springmvc 注解版helloworld
- spring和springMVC整合注解版helloworld
- 基于SpringMVC Annotation配置的HelloWorld
- SpringMVC学习笔记(2) 框架配置+HelloWorld(注解版)
- SpringMVC学习笔记(3) 框架配置+HelloWorld(非注解版)
- HelloWorld版的SpringMVC使用注解驱动的依赖注入
- HelloWorld版的SpringMVC使用注解驱动的依赖注入
- SpringMVC的四个基本注解annotation
- SpringMVC注解-org.springframework.web.bind.annotation
- SpringMVC的四个基本注解annotation
- 基于注解实现springmvc的入门helloworld
- SpringMVC Helloworld注解和404问题
- 第一个annotation版的HelloWorld
- springMVC基于注解(annotation)的Hello world
- SpringMVC 用注解Annotation驱动的IoC功能@Autowired @Component
- SpringMVC 用注解Annotation驱动的IoC功能@Autowired @Component
- SpringMVC用注解Annotation 驱动的IOC功能@Autowired @Component
- angularjs-表单验证
- JS大总结(带实例)
- 消息中间件及WebSphere MQ入门
- hdoj-1789-Doing Homework again
- 键盘按钮keyCode大全
- SpringMVC annotation注解版helloworld
- 北京市工作居住证官方网站js报错不能使用解决办法
- HDU 5680 zxa and set
- Oracle 查询每天执行慢的SQL
- c++引用
- Windows Xp和openSUSE 11.2双系统硬盘安装指南 (参考)
- Spring中@Transactional用法
- java验证码中的数字、字母、汉字如何随机生成
- C++走向远洋——48(项目一1、复数类中的运算符重载、类的成员函数)