From 4b306d453b36826ecb8acb29dca60bd2f54975ef Mon Sep 17 00:00:00 2001 From: sxyx2008 Date: Tue, 1 Jul 2014 16:26:32 +0800 Subject: [PATCH] commit --- .gitignore | 4 +- pom.xml | 1 + spring-boot-example/.gitignore | 3 + spring-boot-example/README.md | 14 +++ spring-boot-example/pom.xml | 105 ++++++++++++++++++ .../springboot/example/Application.java | 16 +++ .../aimeizi/springboot/example/Greeting.java | 20 ++++ .../example/GreetingController.java | 50 +++++++++ .../springboot/example/SampleController.java | 19 ++++ .../springboot/example/SimpleSpringBoot.java | 19 ++++ .../src/main/resources/logback.xml | 23 ++++ spring3-helloworld-example/.gitignore | 1 + spring3-javaconfig-example/.gitignore | 1 + spring3-javaconfig-import-example/.gitignore | 1 + spring3-jmx-example/.gitignore | 1 + spring3-mvc-simple/.gitignore | 1 + spring3-rmi-example/.gitignore | 1 + spring3-rmi-httpinvoker-example/.gitignore | 1 + 18 files changed, 280 insertions(+), 1 deletion(-) create mode 100644 spring-boot-example/.gitignore create mode 100644 spring-boot-example/README.md create mode 100644 spring-boot-example/pom.xml create mode 100644 spring-boot-example/src/main/java/net/aimeizi/springboot/example/Application.java create mode 100644 spring-boot-example/src/main/java/net/aimeizi/springboot/example/Greeting.java create mode 100644 spring-boot-example/src/main/java/net/aimeizi/springboot/example/GreetingController.java create mode 100644 spring-boot-example/src/main/java/net/aimeizi/springboot/example/SampleController.java create mode 100644 spring-boot-example/src/main/java/net/aimeizi/springboot/example/SimpleSpringBoot.java create mode 100644 spring-boot-example/src/main/resources/logback.xml diff --git a/.gitignore b/.gitignore index 59b2c02..7f577e8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /.project /.settings -/src \ No newline at end of file +/src +/.idea +/*.iml diff --git a/pom.xml b/pom.xml index fc96993..5a8b212 100644 --- a/pom.xml +++ b/pom.xml @@ -12,5 +12,6 @@ spring3-jmx-example spring3-rmi-example spring3-rmi-httpinvoker-example + spring-boot-example \ No newline at end of file diff --git a/spring-boot-example/.gitignore b/spring-boot-example/.gitignore new file mode 100644 index 0000000..16096af --- /dev/null +++ b/spring-boot-example/.gitignore @@ -0,0 +1,3 @@ +/spring-boot-example.iml +/target +/*.iml diff --git a/spring-boot-example/README.md b/spring-boot-example/README.md new file mode 100644 index 0000000..f9a8819 --- /dev/null +++ b/spring-boot-example/README.md @@ -0,0 +1,14 @@ +spring-boot-example +======================= + +使用```spring boot```和```spring hateoas```发布基于```REST```风格的接口 + +运行```Application```中的```main```方法。然后浏览器访问 + +* [http://localhost:8080/](http://localhost:8080/) http://localhost:8080/ SampleController中的home() + +* [http://localhost:8080/greeting](http://localhost:8080/greeting) http://localhost:8080/greeting GreetingController中的greeting()方法 + +* [http://localhost:8080/print/zhangsan](http://localhost:8080/print/zhangsan) http://localhost:8080/print/{name} GreetingController中的print()方法 + +* [http://localhost:8080/hello/zhangsan/18](http://localhost:8080/hello/zhangsan/18) http://localhost:8080/hello/{name}/{age} SimpleSpringBoot中的hello()方法 \ No newline at end of file diff --git a/spring-boot-example/pom.xml b/spring-boot-example/pom.xml new file mode 100644 index 0000000..41b18b2 --- /dev/null +++ b/spring-boot-example/pom.xml @@ -0,0 +1,105 @@ + + + + + + + org.springframework.boot + spring-boot-starter-parent + 1.1.3.RELEASE + + + 4.0.0 + spring-boot-example + + + + joda-time + joda-time + 2.2 + + + + junit + junit + 4.0 + + + + + org.springframework.boot + spring-boot-starter-web + + + + com.fasterxml.jackson.core + jackson-databind + + + + + org.springframework.hateoas + spring-hateoas + 0.12.0.RELEASE + + + + + + net.aimeizi.Application + + + + + + spring-milestones + Spring Milestones + http://repo.spring.io/milestone + + false + + + + + + + + spring-milestones + Spring Milestones + http://repo.spring.io/milestone + + false + + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.0.2 + + 1.5 + 1.5 + + + + + + \ No newline at end of file diff --git a/spring-boot-example/src/main/java/net/aimeizi/springboot/example/Application.java b/spring-boot-example/src/main/java/net/aimeizi/springboot/example/Application.java new file mode 100644 index 0000000..da9705b --- /dev/null +++ b/spring-boot-example/src/main/java/net/aimeizi/springboot/example/Application.java @@ -0,0 +1,16 @@ +package net.aimeizi.springboot.example; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; + +/** + * Created by 冯靖 on 14-3-7. + */ +@ComponentScan +@EnableAutoConfiguration +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} \ No newline at end of file diff --git a/spring-boot-example/src/main/java/net/aimeizi/springboot/example/Greeting.java b/spring-boot-example/src/main/java/net/aimeizi/springboot/example/Greeting.java new file mode 100644 index 0000000..39f384c --- /dev/null +++ b/spring-boot-example/src/main/java/net/aimeizi/springboot/example/Greeting.java @@ -0,0 +1,20 @@ +package net.aimeizi.springboot.example; + +import org.springframework.hateoas.ResourceSupport; + +/** + * 编写实体类继承org.springframework.hateoas.ResourceSupport + * Created by 冯靖 on 14-3-7. + */ +public class Greeting extends ResourceSupport{ + private final String content; + + public Greeting(String content) { + this.content = content; + } + + + public String getContent() { + return content; + } +} diff --git a/spring-boot-example/src/main/java/net/aimeizi/springboot/example/GreetingController.java b/spring-boot-example/src/main/java/net/aimeizi/springboot/example/GreetingController.java new file mode 100644 index 0000000..75665ba --- /dev/null +++ b/spring-boot-example/src/main/java/net/aimeizi/springboot/example/GreetingController.java @@ -0,0 +1,50 @@ +package net.aimeizi.springboot.example; + +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; +import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn; + +/** + * 使用spring-hateoas创建RESTful Web Service + * 1.编写实体类继承org.springframework.hateoas.ResourceSupport + * 2.编写一个返回类型为HttpEntity的方法 + * 3.使用org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo方法 + * Created by 冯靖 on 14-3-7. + */ +@Controller +public class GreetingController { + + private static final String template = "Hello, %s!"; + //private final AtomicLong counter = new AtomicLong(); + + @RequestMapping(value = "/greeting",method = {RequestMethod.GET}) + @ResponseBody + public HttpEntity greeting( + @RequestParam(value="name", required=false, defaultValue="World") String name) { + Greeting greeting = new Greeting(String.format(template, name)); + greeting.add(linkTo(methodOn(GreetingController.class).greeting(name)).withSelfRel()); + return new ResponseEntity(greeting, HttpStatus.OK); + } + + + + + @RequestMapping(value = "/print/{name}",method = {RequestMethod.GET}) + @ResponseBody + public HttpEntity print(@PathVariable(value = "name")String name){ + + Greeting greeting=new Greeting(String.format("%s,i will be back!",name)); + greeting.add(linkTo(methodOn(GreetingController.class).print(name)).withSelfRel()); + + return new ResponseEntity(greeting,HttpStatus.OK); + } + + + + +} diff --git a/spring-boot-example/src/main/java/net/aimeizi/springboot/example/SampleController.java b/spring-boot-example/src/main/java/net/aimeizi/springboot/example/SampleController.java new file mode 100644 index 0000000..bd9db8b --- /dev/null +++ b/spring-boot-example/src/main/java/net/aimeizi/springboot/example/SampleController.java @@ -0,0 +1,19 @@ +package net.aimeizi.springboot.example; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * Created by 冯靖 on 14-3-7. + */ +@Controller +public class SampleController { + + @RequestMapping("/") + @ResponseBody + String home() { + return "Hello World!"; + } + +} \ No newline at end of file diff --git a/spring-boot-example/src/main/java/net/aimeizi/springboot/example/SimpleSpringBoot.java b/spring-boot-example/src/main/java/net/aimeizi/springboot/example/SimpleSpringBoot.java new file mode 100644 index 0000000..f83a0e2 --- /dev/null +++ b/spring-boot-example/src/main/java/net/aimeizi/springboot/example/SimpleSpringBoot.java @@ -0,0 +1,19 @@ +package net.aimeizi.springboot.example; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * Created by 冯靖 on 14-3-7. + */ +@Controller +public class SimpleSpringBoot { + + @RequestMapping("/hello/{name}/{age}") + @ResponseBody + String hello(@PathVariable String name,@PathVariable("age") int age) { + return "Hello, "+name+"! You Are "+age+" years old!"; + } +} diff --git a/spring-boot-example/src/main/resources/logback.xml b/spring-boot-example/src/main/resources/logback.xml new file mode 100644 index 0000000..bc514df --- /dev/null +++ b/spring-boot-example/src/main/resources/logback.xml @@ -0,0 +1,23 @@ + + + + + + + + %d %5p %40.40c:%4L - %m%n + + + + + + + + + + + \ No newline at end of file diff --git a/spring3-helloworld-example/.gitignore b/spring3-helloworld-example/.gitignore index 9dff9cc..aab63f4 100644 --- a/spring3-helloworld-example/.gitignore +++ b/spring3-helloworld-example/.gitignore @@ -2,3 +2,4 @@ /.settings /target /.classpath +/*.iml diff --git a/spring3-javaconfig-example/.gitignore b/spring3-javaconfig-example/.gitignore index 9dff9cc..aab63f4 100644 --- a/spring3-javaconfig-example/.gitignore +++ b/spring3-javaconfig-example/.gitignore @@ -2,3 +2,4 @@ /.settings /target /.classpath +/*.iml diff --git a/spring3-javaconfig-import-example/.gitignore b/spring3-javaconfig-import-example/.gitignore index 9dff9cc..aab63f4 100644 --- a/spring3-javaconfig-import-example/.gitignore +++ b/spring3-javaconfig-import-example/.gitignore @@ -2,3 +2,4 @@ /.settings /target /.classpath +/*.iml diff --git a/spring3-jmx-example/.gitignore b/spring3-jmx-example/.gitignore index 7075a2f..9cc88fe 100644 --- a/spring3-jmx-example/.gitignore +++ b/spring3-jmx-example/.gitignore @@ -2,3 +2,4 @@ /.classpath /.project /.settings +/*.iml diff --git a/spring3-mvc-simple/.gitignore b/spring3-mvc-simple/.gitignore index dcf31b9..82e4348 100644 --- a/spring3-mvc-simple/.gitignore +++ b/spring3-mvc-simple/.gitignore @@ -4,3 +4,4 @@ /.gradle /.settings /build +/*.iml diff --git a/spring3-rmi-example/.gitignore b/spring3-rmi-example/.gitignore index 9dff9cc..aab63f4 100644 --- a/spring3-rmi-example/.gitignore +++ b/spring3-rmi-example/.gitignore @@ -2,3 +2,4 @@ /.settings /target /.classpath +/*.iml diff --git a/spring3-rmi-httpinvoker-example/.gitignore b/spring3-rmi-httpinvoker-example/.gitignore index ca618a0..338b6a8 100644 --- a/spring3-rmi-httpinvoker-example/.gitignore +++ b/spring3-rmi-httpinvoker-example/.gitignore @@ -3,3 +3,4 @@ /.settings /.classpath /.project +/*.iml