Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Calvin committed Mar 17, 2014
2 parents 722a79d + a11fc4c commit 7930e23
Show file tree
Hide file tree
Showing 18 changed files with 430 additions and 448 deletions.
2 changes: 1 addition & 1 deletion examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springside</groupId>
<artifactId>springside-parent</artifactId>
<version>4.3.0-SNAPSHOT</version>
<version>4.2.2.GA</version>
<relativePath>../modules/parent/</relativePath>
</parent>
<groupId>org.springside.examples</groupId>
Expand Down
4 changes: 2 additions & 2 deletions examples/quickstart/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.springside.examples</groupId>
<artifactId>quickstart</artifactId>
<version>4.3.0-SNAPSHOT</version>
<version>4.2.2.GA</version>
<packaging>war</packaging>
<name>Springside :: Example :: QuickStart</name>

<properties>
<!-- 主要依赖库的版本定义 -->
<springside.version>4.3.0-SNAPSHOT</springside.version>
<springside.version>4.2.2.GA</springside.version>
<spring.version>4.0.2.RELEASE</spring.version>
<hibernate.version>4.3.4.Final</hibernate.version>
<spring-data-jpa.version>1.5.1.RELEASE</spring-data-jpa.version>
Expand Down
2 changes: 1 addition & 1 deletion examples/showcase/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springside</groupId>
<artifactId>springside-parent</artifactId>
<version>4.3.0-SNAPSHOT</version>
<version>4.2.2.GA</version>
<relativePath>../../modules/parent/</relativePath>
</parent>
<groupId>org.springside.examples</groupId>
Expand Down
2 changes: 1 addition & 1 deletion modules/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springside</groupId>
<artifactId>springside-parent</artifactId>
<version>4.3.0-SNAPSHOT</version>
<version>4.2.2.GA</version>
<relativePath>../parent/</relativePath>
</parent>
<artifactId>springside-core</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion modules/extension/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springside</groupId>
<artifactId>springside-parent</artifactId>
<version>4.3.0-SNAPSHOT</version>
<version>4.2.2.GA</version>
<relativePath>../parent/</relativePath>
</parent>
<artifactId>springside-extension</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion modules/metrics/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springside</groupId>
<artifactId>springside-parent</artifactId>
<version>4.3.0-SNAPSHOT</version>
<version>4.2.2.GA</version>
<relativePath>../parent/</relativePath>
</parent>
<artifactId>springside-metrics</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions modules/parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.springside</groupId>
<artifactId>springside-parent</artifactId>
<version>4.3.0-SNAPSHOT</version>
<version>4.2.2.GA</version>
<name>Springside :: Module :: Parent</name>
<packaging>pom</packaging>

<properties>
<!-- 主要依赖库的版本定义 -->
<springside.version>4.3.0-SNAPSHOT</springside.version>
<springside.version>4.2.2.GA</springside.version>
<spring.version>4.0.2.RELEASE</spring.version>
<hibernate.version>4.3.4.Final</hibernate.version>
<mybatis.version>3.2.5</mybatis.version>
Expand Down
2 changes: 1 addition & 1 deletion modules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springside</groupId>
<artifactId>springside-parent</artifactId>
<version>4.3.0-SNAPSHOT</version>
<version>4.2.2.GA</version>
<relativePath>../modules/parent/</relativePath>
</parent>
<artifactId>springside-modules</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.springside</groupId>
<artifactId>springside-project</artifactId>
<version>4.3.0-SNAPSHOT</version>
<version>4.2.2.GA</version>
<name>Springside :: Project</name>
<packaging>pom</packaging>

Expand Down
2 changes: 1 addition & 1 deletion support/h2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springside</groupId>
<artifactId>springside-parent</artifactId>
<version>4.3.0-SNAPSHOT</version>
<version>4.2.2.GA</version>
<relativePath>../../modules/parent/</relativePath>
</parent>
<groupId>org.springside</groupId>
Expand Down
2 changes: 1 addition & 1 deletion support/maven-archetype/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.springside.examples</groupId>
<artifactId>quickstart-archetype</artifactId>
<version>4.3.0-SNAPSHOT</version>
<version>4.2.2.GA</version>
<packaging>maven-archetype</packaging>

<name>SpringSide :: Archetype :: QuickStart</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,24 @@

<properties>
<!-- 主要依赖库的版本定义 -->
<springside.version>4.3.0-SNAPSHOT</springside.version>
<spring.version>4.0.0.RELEASE</spring.version>
<springside.version>4.2.2.GA</springside.version>
<spring.version>4.0.2.RELEASE</spring.version>
<hibernate.version>4.3.1.Final</hibernate.version>
<spring-data-jpa.version>1.4.2.RELEASE</spring-data-jpa.version>
<tomcat-jdbc.version>7.0.50</tomcat-jdbc.version>
<spring-data-jpa.version>1.4.4.RELEASE</spring-data-jpa.version>
<tomcat-jdbc.version>7.0.52</tomcat-jdbc.version>
<sitemesh.version>2.4.2</sitemesh.version>
<shiro.version>1.2.2</shiro.version>
<hibernate-validator.version>5.0.2.Final</hibernate-validator.version>
<hibernate-validator.version>5.0.3.Final</hibernate-validator.version>
<jackson.version>2.3.1</jackson.version>
<slf4j.version>1.7.5</slf4j.version>
<logback.version>1.0.13</logback.version>
<aspectj.version>1.7.4</aspectj.version>
<slf4j.version>1.7.6</slf4j.version>
<logback.version>1.1.1</logback.version>
<commons-lang3.version>3.2.1</commons-lang3.version>
<guava.version>16.0</guava.version>
<guava.version>16.0.1</guava.version>
<junit.version>4.11</junit.version>
<assertj.version>1.5.0</assertj.version>
<mockito.version>1.9.5</mockito.version>
<selenium.version>2.39.0</selenium.version>
<selenium.version>2.40.0</selenium.version>
<jetty.version>7.6.14.v20131031</jetty.version>
<h2.version>1.3.175</h2.version>

Expand Down Expand Up @@ -83,24 +84,18 @@
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>${spring-data-jpa.version}</version>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit-dep</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- spring aop -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.7.3</version>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.7.3</version>
<version>${aspectj.version}</version>
<scope>runtime</scope>
</dependency>

Expand Down Expand Up @@ -356,12 +351,7 @@
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>2.6.6</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
<version>2.6.8</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,100 +1,100 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
/*******************************************************************************
* Copyright (c) 2005, 2014 springside.github.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
*******************************************************************************/
package ${package}.rest;

import java.net.URI;
import java.util.List;

import javax.validation.Validator;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.util.UriComponentsBuilder;
import ${package}.entity.Task;
import ${package}.service.task.TaskService;
import org.springside.modules.beanvalidator.BeanValidators;
import org.springside.modules.web.MediaTypes;

/**
* Task的Restful API的Controller.
*
* @author calvin
*/
@RestController
@RequestMapping(value = "/api/v1/task")
public class TaskRestController {

private static Logger logger = LoggerFactory.getLogger(TaskRestController.class);

@Autowired
private TaskService taskService;

@Autowired
private Validator validator;

@RequestMapping(method = RequestMethod.GET, produces = MediaTypes.JSON_UTF_8)
public List<Task> list() {
return taskService.getAllTask();
}

@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = MediaTypes.JSON_UTF_8)
public Task get(@PathVariable("id") Long id) {
Task task = taskService.getTask(id);
if (task == null) {
String message = "任务不存在(id:" + id + ")";
logger.warn(message);
throw new RestException(HttpStatus.NOT_FOUND, message);
}
return task;
}

@RequestMapping(method = RequestMethod.POST, consumes = MediaTypes.JSON)
public ResponseEntity<?> create(@RequestBody Task task, UriComponentsBuilder uriBuilder) {
// 调用JSR303 Bean Validator进行校验, 异常将由RestExceptionHandler统一处理.
BeanValidators.validateWithException(validator, task);

// 保存任务
taskService.saveTask(task);

// 按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
Long id = task.getId();
URI uri = uriBuilder.path("/api/v1/task/" + id).build().toUri();
HttpHeaders headers = new HttpHeaders();
headers.setLocation(uri);

return new ResponseEntity(headers, HttpStatus.CREATED);
}

@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaTypes.JSON)
public ResponseEntity<?> update(@RequestBody Task task) {
// 调用JSR303 Bean Validator进行校验, 异常将由RestExceptionHandler统一处理.
BeanValidators.validateWithException(validator, task);
// 保存
taskService.saveTask(task);

// 按Restful约定,返回204状态码, 无内容. 也可以返回200状态码.
return new ResponseEntity(HttpStatus.NO_CONTENT);
}

@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void delete(@PathVariable("id") Long id) {
taskService.deleteTask(id);
}
}
/*******************************************************************************
* Copyright (c) 2005, 2014 springside.github.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
*******************************************************************************/
package ${package}.rest;

import java.net.URI;
import java.util.List;

import javax.validation.Validator;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.util.UriComponentsBuilder;
import ${package}.entity.Task;
import ${package}.service.task.TaskService;
import org.springside.modules.beanvalidator.BeanValidators;
import org.springside.modules.web.MediaTypes;

/**
* Task的Restful API的Controller.
*
* @author calvin
*/
@RestController
@RequestMapping(value = "/api/v1/task")
public class TaskRestController {

private static Logger logger = LoggerFactory.getLogger(TaskRestController.class);

@Autowired
private TaskService taskService;

@Autowired
private Validator validator;

@RequestMapping(method = RequestMethod.GET, produces = MediaTypes.JSON_UTF_8)
public List<Task> list() {
return taskService.getAllTask();
}

@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = MediaTypes.JSON_UTF_8)
public Task get(@PathVariable("id") Long id) {
Task task = taskService.getTask(id);
if (task == null) {
String message = "任务不存在(id:" + id + ")";
logger.warn(message);
throw new RestException(HttpStatus.NOT_FOUND, message);
}
return task;
}

@RequestMapping(method = RequestMethod.POST, consumes = MediaTypes.JSON)
public ResponseEntity<?> create(@RequestBody Task task, UriComponentsBuilder uriBuilder) {
// 调用JSR303 Bean Validator进行校验, 异常将由RestExceptionHandler统一处理.
BeanValidators.validateWithException(validator, task);

// 保存任务
taskService.saveTask(task);

// 按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
Long id = task.getId();
URI uri = uriBuilder.path("/api/v1/task/" + id).build().toUri();
HttpHeaders headers = new HttpHeaders();
headers.setLocation(uri);

return new ResponseEntity(headers, HttpStatus.CREATED);
}

@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaTypes.JSON)
// 按Restful风格约定,返回204状态码, 无内容. 也可以返回200状态码.
@ResponseStatus(HttpStatus.NO_CONTENT)
public void update(@RequestBody Task task) {
// 调用JSR303 Bean Validator进行校验, 异常将由RestExceptionHandler统一处理.
BeanValidators.validateWithException(validator, task);

// 保存任务
taskService.saveTask(task);
}

@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void delete(@PathVariable("id") Long id) {
taskService.deleteTask(id);
}
}
Loading

0 comments on commit 7930e23

Please sign in to comment.