Skip to content

Commit

Permalink
更新
Browse files Browse the repository at this point in the history
  • Loading branch information
fengyws committed Sep 17, 2017
1 parent 54b4b57 commit a8f314e
Show file tree
Hide file tree
Showing 70 changed files with 1,579 additions and 0 deletions.
52 changes: 52 additions & 0 deletions spring-boot-demo-02-1/pom.xml
@@ -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>
@@ -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);
}
}
@@ -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;
}
}
@@ -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.
@@ -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\"}"));
}

}
51 changes: 51 additions & 0 deletions spring-boot-demo-03-1/pom.xml
@@ -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>
@@ -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);
}
}
@@ -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;
}
}
@@ -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;
}

}
@@ -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'"
}
]}

0 comments on commit a8f314e

Please sign in to comment.