SpringMVC_HelloWorld_02, springmvchelloworld
Implement a simple HelloWorld through annotation.
1. Create a project
Same as SpringMVC_HelloWorld_01
Ii. Configuration File 1. Configure web. xml
Same as SpringMVC_HelloWorld_01
2. Configure springmvc-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" xmlns: mvc = "http://www.springframework.org/schema/mvc" xsi: schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context h Ttp: // www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd "> <! -- Configure a custom scan package --> <context: component-scan base-package = "com. zhy. controllers"> </context: component-scan> <! -- Configure the view parser --> <bean class = "org. springframework. web. servlet. view. InternalResourceViewResolver"> <! -- Configure prefix --> <property name = "prefix" value = "/WEB-INF/views/"> </property> <! -- Configure the suffix --> <property name = "suffix" value = ". jsp"> </property> </bean> </beans>
3. Compile the Controller
Package com. zhy. controllers; import org. springframework. stereotype. controller; import org. springframework. web. bind. annotation. requestMapping; @ Controllerpublic class HelloWorldController {/** get the actual physical view through ViewResolver * parsing rules of the view Parser: prefix + returnvalue + suffix * combined with this instance, the physical view parsed by the view parser is:/WEB-INF/views/helloworld. jsp **/@ RequestMapping ("/mvc") public String hello () {System. out. println ("call controller"); return "helloworld ";}}4. Create a jsp page
Same as SpringMVC_HelloWorld_01
Iv. Run
Same as SpringMVC_HelloWorld_01