From bd2607506356189d2f6fae88b602bd1291faa415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=AA=E5=B1=B1=E9=A3=9E=E9=B9=84?= Date: Sat, 12 Jul 2014 19:41:50 +0800 Subject: [PATCH] commit --- spring-boot-helloworld/pom.xml | 62 +++++++++++++++++ .../main/java/com/sishuok/Application.java | 20 ++++++ .../sishuok/controller/UserController.java | 31 +++++++++ .../main/java/com/sishuok/entity/User.java | 29 ++++++++ springmvc-rest-helloworld/README | 1 + springmvc-rest-helloworld/pom.xml | 67 +++++++++++++++++++ .../src/main/java/com/sishuok/AppConfig.java | 16 +++++ .../main/java/com/sishuok/AppInitializer.java | 31 +++++++++ .../sishuok/controller/UserController.java | 25 +++++++ .../main/java/com/sishuok/entity/User.java | 46 +++++++++++++ 10 files changed, 328 insertions(+) create mode 100644 spring-boot-helloworld/pom.xml create mode 100644 spring-boot-helloworld/src/main/java/com/sishuok/Application.java create mode 100644 spring-boot-helloworld/src/main/java/com/sishuok/controller/UserController.java create mode 100644 spring-boot-helloworld/src/main/java/com/sishuok/entity/User.java create mode 100644 springmvc-rest-helloworld/README create mode 100644 springmvc-rest-helloworld/pom.xml create mode 100644 springmvc-rest-helloworld/src/main/java/com/sishuok/AppConfig.java create mode 100644 springmvc-rest-helloworld/src/main/java/com/sishuok/AppInitializer.java create mode 100644 springmvc-rest-helloworld/src/main/java/com/sishuok/controller/UserController.java create mode 100644 springmvc-rest-helloworld/src/main/java/com/sishuok/entity/User.java diff --git a/spring-boot-helloworld/pom.xml b/spring-boot-helloworld/pom.xml new file mode 100644 index 0000000..bed6fdb --- /dev/null +++ b/spring-boot-helloworld/pom.xml @@ -0,0 +1,62 @@ + + + 4.0.0 + + spring-boot-helloworld + spring-boot-helloworld + 1.0-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter-parent + 0.5.0.BUILD-SNAPSHOT + + + + + + org.springframework.boot + spring-boot-starter-web + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + + + + spring-snapshots + http://repo.spring.io/snapshot + true + + + spring-milestones + http://repo.spring.io/milestone + true + + + + + spring-snapshots + http://repo.spring.io/snapshot + + + spring-milestones + http://repo.spring.io/milestone + + + + \ No newline at end of file diff --git a/spring-boot-helloworld/src/main/java/com/sishuok/Application.java b/spring-boot-helloworld/src/main/java/com/sishuok/Application.java new file mode 100644 index 0000000..69be765 --- /dev/null +++ b/spring-boot-helloworld/src/main/java/com/sishuok/Application.java @@ -0,0 +1,20 @@ +package com.sishuok; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +/** + *

User: Zhang Kaitao + *

Date: 13-12-22 + *

Version: 1.0 + */ +@EnableAutoConfiguration +@Configuration +@ComponentScan +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class); + } +} diff --git a/spring-boot-helloworld/src/main/java/com/sishuok/controller/UserController.java b/spring-boot-helloworld/src/main/java/com/sishuok/controller/UserController.java new file mode 100644 index 0000000..d93299e --- /dev/null +++ b/spring-boot-helloworld/src/main/java/com/sishuok/controller/UserController.java @@ -0,0 +1,31 @@ +package com.sishuok.controller; + +import com.sishuok.entity.User; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + *

User: Zhang Kaitao + *

Date: 13-12-22 + *

Version: 1.0 + */ +@EnableAutoConfiguration +@RestController +@RequestMapping("/user") +public class UserController { + + @RequestMapping("/{id}") + private User view(@PathVariable("id") Long id) { + User user = new User(); + user.setId(id); + user.setName("zhang"); + return user; + } + + public static void main(String[] args) { + SpringApplication.run(UserController.class); + } +} diff --git a/spring-boot-helloworld/src/main/java/com/sishuok/entity/User.java b/spring-boot-helloworld/src/main/java/com/sishuok/entity/User.java new file mode 100644 index 0000000..54c2073 --- /dev/null +++ b/spring-boot-helloworld/src/main/java/com/sishuok/entity/User.java @@ -0,0 +1,29 @@ +package com.sishuok.entity; + +import java.io.Serializable; + +/** + *

User: Zhang Kaitao + *

Date: 13-12-22 + *

Version: 1.0 + */ +public class User implements Serializable { + private Long id; + private String name; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/springmvc-rest-helloworld/README b/springmvc-rest-helloworld/README new file mode 100644 index 0000000..7ea0b38 --- /dev/null +++ b/springmvc-rest-helloworld/README @@ -0,0 +1 @@ + 5分钟构建spring web mvc Rest风格HelloWorld \ No newline at end of file diff --git a/springmvc-rest-helloworld/pom.xml b/springmvc-rest-helloworld/pom.xml new file mode 100644 index 0000000..8b1c2ae --- /dev/null +++ b/springmvc-rest-helloworld/pom.xml @@ -0,0 +1,67 @@ + + + 4.0.0 + + springmvc-rest-helloworld + springmvc-rest-helloworld + 1.0-SNAPSHOT + + + + + javax.servlet + javax.servlet-api + 3.0.1 + + + + + org.springframework + spring-context-support + 4.0.0.RELEASE + + + + + org.springframework + spring-webmvc + 4.0.0.RELEASE + + + + + com.fasterxml.jackson.core + jackson-databind + 2.2.3 + + + + + + + + springmvc + + + org.mortbay.jetty + jetty-maven-plugin + 8.1.8.v20121106 + + manual + + /${project.build.finalName} + + + + 9080 + + + + + + + + + \ No newline at end of file diff --git a/springmvc-rest-helloworld/src/main/java/com/sishuok/AppConfig.java b/springmvc-rest-helloworld/src/main/java/com/sishuok/AppConfig.java new file mode 100644 index 0000000..6879e67 --- /dev/null +++ b/springmvc-rest-helloworld/src/main/java/com/sishuok/AppConfig.java @@ -0,0 +1,16 @@ +package com.sishuok; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; + +/** + *

User: Zhang Kaitao + *

Date: 13-12-19 + *

Version: 1.0 + */ +@Configuration +@EnableWebMvc +@ComponentScan +public class AppConfig { +} diff --git a/springmvc-rest-helloworld/src/main/java/com/sishuok/AppInitializer.java b/springmvc-rest-helloworld/src/main/java/com/sishuok/AppInitializer.java new file mode 100644 index 0000000..cc26004 --- /dev/null +++ b/springmvc-rest-helloworld/src/main/java/com/sishuok/AppInitializer.java @@ -0,0 +1,31 @@ +package com.sishuok; + +import org.springframework.web.WebApplicationInitializer; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; +import org.springframework.web.servlet.DispatcherServlet; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRegistration; + +/** + *

User: Zhang Kaitao + *

Date: 13-12-19 + *

Version: 1.0 + */ +public class AppInitializer implements WebApplicationInitializer { + + @Override + public void onStartup(ServletContext servletContext) throws ServletException { + AnnotationConfigWebApplicationContext webApplicationContext = + new AnnotationConfigWebApplicationContext(); + webApplicationContext.register(AppConfig.class); + + + DispatcherServlet dispatcherServlet = new DispatcherServlet(webApplicationContext); + ServletRegistration.Dynamic dynamic = servletContext.addServlet("dispatcherServlet", dispatcherServlet); + dynamic.addMapping("/"); + + } +} diff --git a/springmvc-rest-helloworld/src/main/java/com/sishuok/controller/UserController.java b/springmvc-rest-helloworld/src/main/java/com/sishuok/controller/UserController.java new file mode 100644 index 0000000..3ae1d49 --- /dev/null +++ b/springmvc-rest-helloworld/src/main/java/com/sishuok/controller/UserController.java @@ -0,0 +1,25 @@ +package com.sishuok.controller; + +import com.sishuok.entity.User; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +/** + *

User: Zhang Kaitao + *

Date: 13-12-19 + *

Version: 1.0 + */ +@RestController +@RequestMapping("/user") +public class UserController { + + @RequestMapping(value = "/{id}", method = RequestMethod.GET) + public User view(@PathVariable("id") Long id) { + User user = new User(); + user.setId(id); + user.setName("zhang"); + return user; + } +} diff --git a/springmvc-rest-helloworld/src/main/java/com/sishuok/entity/User.java b/springmvc-rest-helloworld/src/main/java/com/sishuok/entity/User.java new file mode 100644 index 0000000..d46cb19 --- /dev/null +++ b/springmvc-rest-helloworld/src/main/java/com/sishuok/entity/User.java @@ -0,0 +1,46 @@ +package com.sishuok.entity; + +import java.io.Serializable; + +/** + *

User: Zhang Kaitao + *

Date: 13-12-19 + *

Version: 1.0 + */ +public class User implements Serializable { + private Long id; + private String name; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + User user = (User) o; + + if (id != null ? !id.equals(user.id) : user.id != null) return false; + + return true; + } + + @Override + public int hashCode() { + return id != null ? id.hashCode() : 0; + } +}