Skip to content

Commit 5c9b89a

Browse files
committed
重新整理
1 parent 8288ce1 commit 5c9b89a

File tree

11 files changed

+294
-0
lines changed

11 files changed

+294
-0
lines changed

Chapter1/pom.xml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.didispace</groupId>
7+
<artifactId>Chapter1</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>jar</packaging>
10+
11+
<name>Chapter1</name>
12+
<description>The first Spring Boot project</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.3.2.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<java.version>1.8</java.version>
24+
</properties>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter</artifactId>
30+
</dependency>
31+
32+
<dependency>
33+
<groupId>org.springframework.boot</groupId>
34+
<artifactId>spring-boot-starter-test</artifactId>
35+
<scope>test</scope>
36+
</dependency>
37+
38+
<dependency>
39+
<groupId>org.springframework.boot</groupId>
40+
<artifactId>spring-boot-starter-web</artifactId>
41+
</dependency>
42+
43+
</dependencies>
44+
45+
<build>
46+
<plugins>
47+
<plugin>
48+
<groupId>org.springframework.boot</groupId>
49+
<artifactId>spring-boot-maven-plugin</artifactId>
50+
</plugin>
51+
</plugins>
52+
</build>
53+
54+
55+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.didispace;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class Chapter1Application {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(Chapter1Application.class, args);
11+
}
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.didispace.web;
2+
3+
import org.springframework.web.bind.annotation.RequestMapping;
4+
import org.springframework.web.bind.annotation.RestController;
5+
6+
@RestController
7+
public class HelloController {
8+
9+
@RequestMapping("/hello")
10+
public String index() {
11+
return "Hello World";
12+
}
13+
14+
}

Chapter1/src/main/resources/application.properties

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.didispace;
2+
3+
import com.didispace.web.HelloController;
4+
import org.junit.Before;
5+
import org.junit.Test;
6+
import org.junit.runner.RunWith;
7+
import org.springframework.boot.test.SpringApplicationConfiguration;
8+
import org.springframework.http.MediaType;
9+
import org.springframework.mock.web.MockServletContext;
10+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
11+
import org.springframework.test.context.web.WebAppConfiguration;
12+
import org.springframework.test.web.servlet.MockMvc;
13+
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
14+
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
15+
16+
import static org.hamcrest.Matchers.equalTo;
17+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
18+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
19+
20+
21+
@RunWith(SpringJUnit4ClassRunner.class)
22+
@SpringApplicationConfiguration(classes = MockServletContext.class)
23+
@WebAppConfiguration
24+
public class Chapter1ApplicationTests {
25+
26+
private MockMvc mvc;
27+
28+
@Before
29+
public void setUp() throws Exception {
30+
mvc = MockMvcBuilders.standaloneSetup(new HelloController()).build();
31+
}
32+
33+
@Test
34+
public void getHello() throws Exception {
35+
mvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON))
36+
.andExpect(status().isOk())
37+
.andExpect(content().string(equalTo("Hello World")));
38+
}
39+
40+
}

Chapter3-1-2/pom.xml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.didispace</groupId>
7+
<artifactId>demo</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>jar</packaging>
10+
11+
<name>demo</name>
12+
<description>Spring Boot Web project</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.3.2.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<java.version>1.8</java.version>
24+
</properties>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter</artifactId>
30+
</dependency>
31+
32+
<dependency>
33+
<groupId>org.springframework.boot</groupId>
34+
<artifactId>spring-boot-starter-test</artifactId>
35+
<scope>test</scope>
36+
</dependency>
37+
38+
<dependency>
39+
<groupId>org.springframework.boot</groupId>
40+
<artifactId>spring-boot-starter-web</artifactId>
41+
</dependency>
42+
43+
<dependency>
44+
<groupId>org.springframework.boot</groupId>
45+
<artifactId>spring-boot-starter-thymeleaf</artifactId>
46+
</dependency>
47+
48+
</dependencies>
49+
50+
<build>
51+
<plugins>
52+
<plugin>
53+
<groupId>org.springframework.boot</groupId>
54+
<artifactId>spring-boot-maven-plugin</artifactId>
55+
<configuration>
56+
<fork>true</fork>
57+
</configuration>
58+
</plugin>
59+
</plugins>
60+
</build>
61+
62+
63+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.didispace;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
/**
7+
*
8+
* @author 程序猿DD
9+
* @version 1.0.0
10+
* @blog http://blog.didispace.com
11+
*
12+
*/
13+
@SpringBootApplication
14+
public class Application {
15+
16+
public static void main(String[] args) {
17+
18+
SpringApplication.run(Application.class, args);
19+
20+
}
21+
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.didispace.web;
2+
3+
import org.springframework.stereotype.Controller;
4+
import org.springframework.ui.ModelMap;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
import org.springframework.web.bind.annotation.RestController;
7+
8+
/**
9+
*
10+
* @author 程序猿DD
11+
* @version 1.0.0
12+
* @blog http://blog.didispace.com
13+
*
14+
*/
15+
@Controller
16+
public class HelloController {
17+
18+
@RequestMapping("/hello")
19+
public String hello() {
20+
return "Hello World";
21+
}
22+
23+
@RequestMapping("/")
24+
public String index(ModelMap map) {
25+
map.addAttribute("host", "http://blog.didispace.com");
26+
return "index";
27+
}
28+
29+
}

Chapter3-1-2/src/main/resources/application.properties

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head lang="en">
4+
<meta charset="UTF-8" />
5+
<title></title>
6+
</head>
7+
<body>
8+
<h1 th:text="${host}">Hello World</h1>
9+
</body>
10+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.didispace;
2+
3+
import com.didispace.web.HelloController;
4+
import org.junit.Before;
5+
import org.junit.Test;
6+
import org.junit.runner.RunWith;
7+
import org.springframework.boot.test.SpringApplicationConfiguration;
8+
import org.springframework.http.MediaType;
9+
import org.springframework.mock.web.MockServletContext;
10+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
11+
import org.springframework.test.context.web.WebAppConfiguration;
12+
import org.springframework.test.web.servlet.MockMvc;
13+
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
14+
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
15+
16+
import static org.hamcrest.Matchers.equalTo;
17+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
18+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
19+
20+
21+
/**
22+
*
23+
* @author 程序猿DD
24+
* @version 1.0.0
25+
* @blog http://blog.didispace.com
26+
*
27+
*/
28+
@RunWith(SpringJUnit4ClassRunner.class)
29+
@SpringApplicationConfiguration(classes = MockServletContext.class)
30+
@WebAppConfiguration
31+
public class ApplicationTests {
32+
33+
private MockMvc mvc;
34+
35+
@Before
36+
public void setUp() throws Exception {
37+
mvc = MockMvcBuilders.standaloneSetup(
38+
new HelloController()).build();
39+
}
40+
41+
@Test
42+
public void getHello() throws Exception {
43+
mvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON))
44+
.andExpect(status().isOk())
45+
.andExpect(content().string(equalTo("Hello World")));
46+
}
47+
48+
}

0 commit comments

Comments
 (0)