Created
August 2, 2013 03:36
-
-
Save wz5891/6137326 to your computer and use it in GitHub Desktop.
test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.springapp</groupId> | |
<artifactId>springmvc-one</artifactId> | |
<packaging>war</packaging> | |
<version>1.0-SNAPSHOT</version> | |
<name>springmvc-one</name> | |
<properties> | |
<spring.version>3.2.0.RELEASE</spring.version> | |
</properties> | |
<dependencies> | |
<dependency> | |
<groupId>org.springframework</groupId> | |
<artifactId>spring-core</artifactId> | |
<version>${spring.version}</version> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework</groupId> | |
<artifactId>spring-web</artifactId> | |
<version>${spring.version}</version> | |
</dependency> | |
<dependency> | |
<groupId>javax.servlet</groupId> | |
<artifactId>servlet-api</artifactId> | |
<version>2.5</version> | |
</dependency> | |
<dependency> | |
<groupId>javax.servlet.jsp</groupId> | |
<artifactId>jsp-api</artifactId> | |
<version>2.1</version> | |
<scope>provided</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework</groupId> | |
<artifactId>spring-webmvc</artifactId> | |
<version>${spring.version}</version> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework</groupId> | |
<artifactId>spring-test</artifactId> | |
<version>${spring.version}</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>junit</groupId> | |
<artifactId>junit</artifactId> | |
<version>4.8.2</version> | |
<scope>test</scope> | |
</dependency> | |
</dependencies> | |
<build> | |
<finalName>springmvc-one</finalName> | |
<plugins> | |
<plugin> | |
<artifactId>maven-compiler-plugin</artifactId> | |
<configuration> | |
<source>1.6</source> | |
<target>1.6</target> | |
</configuration> | |
</plugin> | |
<plugin> | |
<artifactId>maven-surefire-plugin</artifactId> | |
<configuration> | |
<includes> | |
<include>**/*Tests.java</include> | |
</includes> | |
</configuration> | |
</plugin> | |
</plugins> | |
</build> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> | |
<component name="FacetManager"> | |
<facet type="web" name="Web"> | |
<configuration> | |
<descriptors> | |
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/src/main/webapp/WEB-INF/web.xml" /> | |
</descriptors> | |
<webroots> | |
<root url="file://$MODULE_DIR$/src/main/webapp" relative="/" /> | |
</webroots> | |
<sourceRoots> | |
<root url="file://$MODULE_DIR$/src/main/resources" /> | |
<root url="file://$MODULE_DIR$/src/main/java" /> | |
</sourceRoots> | |
</configuration> | |
</facet> | |
<facet type="Spring" name="Spring"> | |
<configuration /> | |
</facet> | |
</component> | |
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false"> | |
<output url="file://$MODULE_DIR$/target/classes" /> | |
<output-test url="file://$MODULE_DIR$/target/test-classes" /> | |
<content url="file://$MODULE_DIR$"> | |
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" isTestSource="true" /> | |
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" isTestSource="false" /> | |
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> | |
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> | |
<excludeFolder url="file://$MODULE_DIR$/target" /> | |
</content> | |
<orderEntry type="inheritedJdk" /> | |
<orderEntry type="sourceFolder" forTests="false" /> | |
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-test-mvc:1.0.0.M2" level="project" /> | |
<orderEntry type="library" scope="PROVIDED" name="Tomcat 6.0.35" level="application_server_libraries" /> | |
<orderEntry type="library" name="Maven: org.springframework:spring-core:3.2.0.RELEASE" level="project" /> | |
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.1.1" level="project" /> | |
<orderEntry type="library" name="Maven: org.springframework:spring-web:3.2.0.RELEASE" level="project" /> | |
<orderEntry type="library" name="Maven: org.springframework:spring-context:3.2.0.RELEASE" level="project" /> | |
<orderEntry type="library" name="Maven: org.springframework:spring-aop:3.2.0.RELEASE" level="project" /> | |
<orderEntry type="library" name="Maven: aopalliance:aopalliance:1.0" level="project" /> | |
<orderEntry type="library" name="Maven: org.springframework:spring-beans:3.2.0.RELEASE" level="project" /> | |
<orderEntry type="library" name="Maven: org.springframework:spring-expression:3.2.0.RELEASE" level="project" /> | |
<orderEntry type="library" name="Maven: javax.servlet:servlet-api:2.5" level="project" /> | |
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.servlet.jsp:jsp-api:2.1" level="project" /> | |
<orderEntry type="library" name="Maven: org.springframework:spring-webmvc:3.2.0.RELEASE" level="project" /> | |
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-test:3.2.0.RELEASE" level="project" /> | |
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.8.2" level="project" /> | |
</component> | |
</module> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.springapp.mvc; | |
import org.springframework.stereotype.Controller; | |
import org.springframework.ui.ModelMap; | |
import org.springframework.web.bind.annotation.RequestMapping; | |
import org.springframework.web.bind.annotation.RequestMethod; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: ex_liwei | |
* Date: 13-8-2 | |
* Time: 上午11:23 | |
* To change this template use File | Settings | File Templates. | |
*/ | |
@Controller | |
public class FirstController { | |
@RequestMapping(method = RequestMethod.GET,value = "/first") | |
public String firstOne(ModelMap model){ | |
model.addAttribute("msg","firstOne"); | |
return "first"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.springapp.mvc; | |
import org.springframework.stereotype.Controller; | |
import org.springframework.ui.ModelMap; | |
import org.springframework.web.bind.annotation.RequestMapping; | |
import org.springframework.web.bind.annotation.RequestMethod; | |
@Controller | |
@RequestMapping("/") | |
public class HelloController { | |
@RequestMapping(method = RequestMethod.GET) | |
public String printWelcome(ModelMap model) { | |
model.addAttribute("message", "Hello world!"); | |
return "hello"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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" | |
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"> | |
<context:component-scan base-package="com.springapp.mvc"/> | |
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> | |
<property name="prefix" value="/WEB-INF/pages/"/> | |
<property name="suffix" value=".jsp"/> | |
</bean> | |
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%-- | |
Created by IntelliJ IDEA. | |
User: ex_liwei | |
Date: 13-8-2 | |
Time: 上午11:30 | |
To change this template use File | Settings | File Templates. | |
--%> | |
<%@ page contentType="text/html;charset=UTF-8" language="java" %> | |
<html> | |
<head> | |
<title>${msg}</title> | |
</head> | |
<body> | |
${msg} | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<h1>${message}</h1> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<web-app version="2.4" | |
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee | |
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> | |
<display-name>Spring MVC Application</display-name> | |
<servlet> | |
<servlet-name>mvc-dispatcher</servlet-name> | |
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> | |
<load-on-startup>1</load-on-startup> | |
</servlet> | |
<servlet-mapping> | |
<servlet-name>mvc-dispatcher</servlet-name> | |
<url-pattern>/</url-pattern> | |
</servlet-mapping> | |
</web-app> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.springapp.mvc; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.test.context.ContextConfiguration; | |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | |
import org.springframework.test.context.web.WebAppConfiguration; | |
import org.springframework.test.web.servlet.MockMvc; | |
import org.springframework.web.context.WebApplicationContext; | |
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; | |
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup; | |
@RunWith(SpringJUnit4ClassRunner.class) | |
@WebAppConfiguration | |
@ContextConfiguration("file:src/main/webapp/WEB-INF/mvc-dispatcher-servlet.xml") | |
public class AppTests { | |
private MockMvc mockMvc; | |
@SuppressWarnings("SpringJavaAutowiringInspection") | |
@Autowired | |
protected WebApplicationContext wac; | |
@Before | |
public void setup() { | |
this.mockMvc = webAppContextSetup(this.wac).build(); | |
} | |
@Test | |
public void simple() throws Exception { | |
mockMvc.perform(get("/")) | |
.andExpect(status().isOk()) | |
.andExpect(view().name("hello")); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
漱壕 2 ' | |