1.新建maven项目打war包
2.搭建springMVC框架
web.xml文件配置
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
SpringMVC
appServlet
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:springmvc.xml
1
appServlet
*.do
pom.xml文件配置
4.0.0
com.cn
upload
0.0.1-SNAPSHOT
war
org.springframework
spring-webmvc
4.0.6.RELEASE
com.fasterxml.jackson.core
jackson-annotations
2.2.3
com.fasterxml.jackson.core
jackson-core
2.2.3
com.fasterxml.jackson.core
jackson-databind
2.2.3
commons-fileupload
commons-fileupload
1.3.1
commons-io
commons-io
2.4
javax.servlet
servlet-api
2.5
provided
javax.servlet.jsp.jstl
jstl-api
1.2
org.glassfish.web
jstl-impl
1.2
taglibs
standard
1.1.2
springmvc.xml核心配置文件
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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
text/html;charset=utf-8
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
class="org.springframework.web.multipart.commons.CommonsMultipartResolver" >
3.新建页面跳转控制类 UserController(在com.zjn.controller包中)
package com.zjn.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import com.zjn.entity.User;
@Controller
public class UserController {
@RequestMapping("/create")
public String Create(Model model) {
return "hello";
}
@RequestMapping("/save")
public String Save(@ModelAttribute("form") User user, Model model) { // user:视图层传给控制层的表单对象;model:控制层返回给视图层的对象
model.addAttribute("user", user);
return "detail";
}
@