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
70 changed files
with
1,579 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,52 @@ | ||
<?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.roncoo.education</groupId> | ||
<artifactId>spring-boot-demo-02-1</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>spring-boot-demo-02-1</name> | ||
<description>Demo project for Spring Boot</description> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>1.4.0.RELEASE</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</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-devtools</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
12 changes: 12 additions & 0 deletions
12
spring-boot-demo-02-1/src/main/java/com/roncoo/education/SpringBootDemo21Application.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,12 @@ | ||
package com.roncoo.education; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class SpringBootDemo21Application { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(SpringBootDemo21Application.class, args); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
spring-boot-demo-02-1/src/main/java/com/roncoo/education/bean/User.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,41 @@ | ||
/** | ||
* 2015-2016 龙果学院 (www.roncoo.com) | ||
*/ | ||
package com.roncoo.education.bean; | ||
|
||
import java.util.Date; | ||
|
||
/** | ||
* 实体类 | ||
* | ||
* @author wujing | ||
*/ | ||
public class User { | ||
private int id; | ||
private String name; | ||
private Date date; | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public Date getDate() { | ||
return date; | ||
} | ||
|
||
public void setDate(Date date) { | ||
this.date = date; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
spring-boot-demo-02-1/src/main/java/com/roncoo/education/controller/IndexController.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,49 @@ | ||
/** | ||
* 2015-2016 龙果学院 (www.roncoo.com) | ||
*/ | ||
package com.roncoo.education.controller; | ||
|
||
import java.util.Date; | ||
import java.util.HashMap; | ||
|
||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.roncoo.education.bean.User; | ||
|
||
/** | ||
* spring-boot-demo-2-1 | ||
* | ||
* @author wujing | ||
*/ | ||
@RestController | ||
@RequestMapping(value = "/index") | ||
public class IndexController { | ||
|
||
@RequestMapping | ||
public String index() { | ||
return "hello world"; | ||
} | ||
|
||
// @RequestParam 简单类型的绑定,可以出来get和post | ||
@RequestMapping(value = "/get") | ||
public HashMap<String, Object> get(@RequestParam String name) { | ||
HashMap<String, Object> map = new HashMap<String, Object>(); | ||
map.put("title", "hello world"); | ||
map.put("name", name); | ||
return map; | ||
} | ||
|
||
// @PathVariable 获得请求url中的动态参数 | ||
@RequestMapping(value = "/get/{id}/{name}") | ||
public User getUser(@PathVariable int id, @PathVariable String name) { | ||
User user = new User(); | ||
user.setId(id); | ||
user.setName(name); | ||
user.setDate(new Date()); | ||
return user; | ||
} | ||
|
||
} |
Empty file.
38 changes: 38 additions & 0 deletions
38
...g-boot-demo-02-1/src/test/java/com/roncoo/education/SpringBootDemo21ApplicationTests.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,38 @@ | ||
package com.roncoo.education; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.RequestBuilder; | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | ||
|
||
import com.roncoo.education.controller.IndexController; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest | ||
public class SpringBootDemo21ApplicationTests { | ||
|
||
private MockMvc mvc; | ||
|
||
@Before | ||
public void setup() { | ||
this.mvc = MockMvcBuilders.standaloneSetup(new IndexController()).build(); | ||
} | ||
|
||
@Test | ||
public void contextLoads() throws Exception { | ||
RequestBuilder request = get("/index"); | ||
mvc.perform(request).andExpect(status().isOk()).andExpect(content().string("hello world")); | ||
|
||
request = get("/index/get").param("name", "无境"); | ||
mvc.perform(request).andExpect(status().isOk()).andExpect(content().string("{\"name\":\"无境\",\"title\":\"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,51 @@ | ||
<?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.roncoo.education</groupId> | ||
<artifactId>spring-boot-demo-03-1</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>spring-boot-demo-03-1</name> | ||
<description>Demo project for Spring Boot</description> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>1.4.0.RELEASE</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</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-devtools</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
12 changes: 12 additions & 0 deletions
12
spring-boot-demo-03-1/src/main/java/com/roncoo/education/SpringBootDemo31Application.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,12 @@ | ||
package com.roncoo.education; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class SpringBootDemo31Application { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(SpringBootDemo31Application.class, args); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
spring-boot-demo-03-1/src/main/java/com/roncoo/education/bean/User.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,41 @@ | ||
/** | ||
* 2015-2016 龙果学院 (www.roncoo.com) | ||
*/ | ||
package com.roncoo.education.bean; | ||
|
||
import java.util.Date; | ||
|
||
/** | ||
* 实体类 | ||
* | ||
* @author wujing | ||
*/ | ||
public class User { | ||
private int id; | ||
private String name; | ||
private Date date; | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public Date getDate() { | ||
return date; | ||
} | ||
|
||
public void setDate(Date date) { | ||
this.date = date; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
spring-boot-demo-03-1/src/main/java/com/roncoo/education/controller/IndexController.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,62 @@ | ||
/** | ||
* 2015-2016 龙果学院 (www.roncoo.com) | ||
*/ | ||
package com.roncoo.education.controller; | ||
|
||
import java.util.Date; | ||
import java.util.HashMap; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.roncoo.education.bean.User; | ||
|
||
/** | ||
* spring-boot-demo-3-1 | ||
* | ||
* @author wujing | ||
*/ | ||
@RestController | ||
@RequestMapping(value = "/index") | ||
public class IndexController { | ||
|
||
@Value(value = "${roncoo.secret}") | ||
private String secret; | ||
|
||
@Value(value = "${roncoo.number}") | ||
private int id; | ||
|
||
@Value(value = "${roncoo.desc}") | ||
private String desc; | ||
|
||
@RequestMapping | ||
public String index() { | ||
return "hello world"; | ||
} | ||
|
||
// @RequestParam 简单类型的绑定,可以出来get和post | ||
@RequestMapping(value = "/get") | ||
public HashMap<String, Object> get(@RequestParam String name) { | ||
HashMap<String, Object> map = new HashMap<String, Object>(); | ||
map.put("title", "hello world"); | ||
map.put("name", name); | ||
map.put("secret", secret); | ||
map.put("id", id); | ||
map.put("desc", desc); | ||
return map; | ||
} | ||
|
||
// @PathVariable 获得请求url中的动态参数 | ||
@RequestMapping(value = "/get/{id}/{name}") | ||
public User getUser(@PathVariable int id, @PathVariable String name) { | ||
User user = new User(); | ||
user.setId(id); | ||
user.setName(name); | ||
user.setDate(new Date()); | ||
return user; | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
...-boot-demo-03-1/src/main/resources/META-INF/additional-spring-configuration-metadata.json
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 @@ | ||
{"properties": [ | ||
{ | ||
"name": "roncoo.secret", | ||
"type": "java.lang.String", | ||
"description": "A description for 'roncoo.secret'" | ||
}, | ||
{ | ||
"name": "roncoo.number", | ||
"type": "java.lang.String", | ||
"description": "A description for 'roncoo.number'" | ||
}, | ||
{ | ||
"name": "roncoo.name", | ||
"type": "java.lang.String", | ||
"description": "A description for 'roncoo.name'" | ||
}, | ||
{ | ||
"name": "roncoo.desc", | ||
"type": "java.lang.String", | ||
"description": "A description for 'roncoo.desc'" | ||
} | ||
]} |
Oops, something went wrong.