forked from dyc87112/SpringBoot-Learning
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
419 changed files
with
16,730 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.didispace</groupId> | ||
<artifactId>Chapter1</artifactId> | ||
<version>1.0.0</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>Chapter1</name> | ||
<description>The first Spring Boot project</description> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>1.3.2.RELEASE</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
13 changes: 13 additions & 0 deletions
13
1.x/Chapter1/src/main/java/com/didispace/Chapter1Application.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.didispace; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class Chapter1Application { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(Chapter1Application.class, args); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
1.x/Chapter1/src/main/java/com/didispace/web/HelloController.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.didispace.web; | ||
|
||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class HelloController { | ||
|
||
@RequestMapping("/hello") | ||
public String index() { | ||
return "Hello World"; | ||
} | ||
|
||
} |
Empty file.
40 changes: 40 additions & 0 deletions
40
1.x/Chapter1/src/test/java/com/didispace/Chapter1ApplicationTests.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.didispace; | ||
|
||
import com.didispace.web.HelloController; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.boot.test.SpringApplicationConfiguration; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.mock.web.MockServletContext; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
import org.springframework.test.context.web.WebAppConfiguration; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
|
||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@SpringApplicationConfiguration(classes = MockServletContext.class) | ||
@WebAppConfiguration | ||
public class Chapter1ApplicationTests { | ||
|
||
private MockMvc mvc; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
mvc = MockMvcBuilders.standaloneSetup(new HelloController()).build(); | ||
} | ||
|
||
@Test | ||
public void getHello() throws Exception { | ||
mvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().string(equalTo("Hello World"))); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.didispace</groupId> | ||
<artifactId>Chapter2-1-1</artifactId> | ||
<version>1.0.0</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>Chapter2-1-1</name> | ||
<description></description> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>1.3.2.RELEASE</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
22 changes: 22 additions & 0 deletions
22
1.x/Chapter2-1-1/src/main/java/com/didispace/Application.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.didispace; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
/** | ||
* | ||
* @author 程序猿DD | ||
* @version 1.0.0 | ||
* @blog http://blog.didispace.com | ||
* | ||
*/ | ||
@SpringBootApplication | ||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
|
||
SpringApplication.run(Application.class, args); | ||
|
||
} | ||
|
||
} |
96 changes: 96 additions & 0 deletions
96
1.x/Chapter2-1-1/src/main/java/com/didispace/service/BlogProperties.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package com.didispace.service; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* @author 程序猿DD | ||
* @version 1.0.0 | ||
* @date 16/5/5 下午12:16. | ||
* @blog http://blog.didispace.com | ||
*/ | ||
@Component | ||
public class BlogProperties { | ||
|
||
@Value("${com.didispace.blog.name}") | ||
private String name; | ||
@Value("${com.didispace.blog.title}") | ||
private String title; | ||
@Value("${com.didispace.blog.desc}") | ||
private String desc; | ||
|
||
@Value("${com.didispace.blog.value}") | ||
private String value; | ||
@Value("${com.didispace.blog.number}") | ||
private Integer number; | ||
@Value("${com.didispace.blog.bignumber}") | ||
private Long bignumber; | ||
@Value("${com.didispace.blog.test1}") | ||
private Integer test1; | ||
@Value("${com.didispace.blog.test2}") | ||
private Integer test2; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
|
||
public String getDesc() { | ||
return desc; | ||
} | ||
|
||
public void setDesc(String desc) { | ||
this.desc = desc; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public void setValue(String value) { | ||
this.value = value; | ||
} | ||
|
||
public Integer getNumber() { | ||
return number; | ||
} | ||
|
||
public void setNumber(Integer number) { | ||
this.number = number; | ||
} | ||
|
||
public Long getBignumber() { | ||
return bignumber; | ||
} | ||
|
||
public void setBignumber(Long bignumber) { | ||
this.bignumber = bignumber; | ||
} | ||
|
||
public Integer getTest1() { | ||
return test1; | ||
} | ||
|
||
public void setTest1(Integer test1) { | ||
this.test1 = test1; | ||
} | ||
|
||
public Integer getTest2() { | ||
return test2; | ||
} | ||
|
||
public void setTest2(Integer test2) { | ||
this.test2 = test2; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
1.x/Chapter2-1-1/src/main/java/com/didispace/web/HelloController.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.didispace.web; | ||
|
||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** | ||
* | ||
* @author 程序猿DD | ||
* @version 1.0.0 | ||
* @blog http://blog.didispace.com | ||
* | ||
*/ | ||
@RestController | ||
public class HelloController { | ||
|
||
@RequestMapping("/hello") | ||
public String index() { | ||
return "Hello World"; | ||
} | ||
|
||
} |
2 changes: 2 additions & 0 deletions
2
1.x/Chapter2-1-1/src/main/resources/application-dev.properties
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# 服务端口 | ||
server.port=1111 |
2 changes: 2 additions & 0 deletions
2
1.x/Chapter2-1-1/src/main/resources/application-prod.properties
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# 服务端口 | ||
server.port=3333 |
2 changes: 2 additions & 0 deletions
2
1.x/Chapter2-1-1/src/main/resources/application-test.properties
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# 服务端口 | ||
server.port=2222 |
17 changes: 17 additions & 0 deletions
17
1.x/Chapter2-1-1/src/main/resources/application.properties
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
com.didispace.blog.name=程序猿DD | ||
com.didispace.blog.title=Spring Boot教程 | ||
com.didispace.blog.desc=${com.didispace.blog.name}正在努力写《${com.didispace.blog.title}》 | ||
|
||
# 随机字符串 | ||
com.didispace.blog.value=${random.value} | ||
# 随机int | ||
com.didispace.blog.number=${random.int} | ||
# 随机long | ||
com.didispace.blog.bignumber=${random.long} | ||
# 10以内的随机数 | ||
com.didispace.blog.test1=${random.int(10)} | ||
# 10-20的随机数 | ||
com.didispace.blog.test2=${random.int[10,20]} | ||
|
||
# 多环境配置文件激活属性 | ||
spring.profiles.active=dev |
Oops, something went wrong.