Spring MVC 笔记 1

阅读更多
1.新建maven 工程
mvn archetype:generate -DinteractiveMode=false -DarchetypeGroupId=org.codehaus.mojo.archetypes  -DarchetypeArtifactId=webapp-jee5  -Dversion=0.0.1-SNAPSHOT -DgroupId=com.kxmgc  -DartifactId=springmvc

2.修改pom.xml,增加spring mvc 3.0.5的依赖包及jetty plugin

	org.springframework
	spring-webmvc
	3.1.2.RELEASE

	org.mortbay.jetty
	maven-jetty-plugin
	6.1.7
	
		0
	

3.修改web.xml,增加如下配置

	dispatcherContext
	org.springframework.web.servlet.DispatcherServlet
	
		contextConfigLocation
		classpath*:dispatcherContext-servlet.xml
	 
	1


	dispatcherContext
	*.action

4.在src\resources下,新建dispatcherContext-servlet.xml


    
	
    
    	
	
		
		
		
	


5.新建HelloworldController类
package com.kxmgc.action;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping("/helloworld")
public class HelloworldController {
	@RequestMapping(method=RequestMethod.GET) 
	public ModelAndView hello() {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("hello");
		return mv;
	}
}

6.在/WEB-INF/jsp目录下,新建hello.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>


    
        
        JSP Page
    
    
        

Hello World!


7.运行
引用
mvn clean compile jetty:run -Djetty.port=80

你可能感兴趣的:(Spring MVC 笔记 1)