Skip to content

Commit

Permalink
update archetype
Browse files Browse the repository at this point in the history
  • Loading branch information
calvin1978 committed Feb 20, 2014
1 parent ed7d078 commit c51036c
Show file tree
Hide file tree
Showing 7 changed files with 437 additions and 455 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,23 @@
<properties>
<!-- 主要依赖库的版本定义 -->
<springside.version>4.3.0-SNAPSHOT</springside.version>
<spring.version>4.0.0.RELEASE</spring.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 All @@ -37,28 +38,28 @@
<jdbc.driver.groupId>com.h2database</jdbc.driver.groupId>
<jdbc.driver.artifactId>h2</jdbc.driver.artifactId>
<jdbc.driver.version>${h2.version}</jdbc.driver.version>
<!--
<jdbc.driver.groupId>mysql</jdbc.driver.groupId>
<jdbc.driver.artifactId>mysql-connector-java</jdbc.driver.artifactId>
<jdbc.driver.version>5.1.22</jdbc.driver.version>
<!--
<jdbc.driver.groupId>mysql</jdbc.driver.groupId>
<jdbc.driver.artifactId>mysql-connector-java</jdbc.driver.artifactId>
<jdbc.driver.version>5.1.22</jdbc.driver.version>
-->
</properties>

<prerequisites>
<maven>3.0.0</maven>
</prerequisites>

<!-- 设定插件仓库, 如有Nexus私服, 取消注释并指向正确的服务器地址.
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>Team Nexus Repository</name>
<url>http://localhost:8081/nexus/content/groups/public</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<!-- 设定插件仓库, 如有Nexus私服, 取消注释并指向正确的服务器地址.
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>Team Nexus Repository</name>
<url>http://localhost:8081/nexus/content/groups/public</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
-->

<!-- 依赖项定义 -->
Expand All @@ -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 @@ -320,12 +315,12 @@
</exclusions>
</dependency>

<!-- h2 如果生产数据库不是H2,解开下面的注释
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
</dependency>
<!-- h2 如果生产数据库不是H2,解开下面的注释
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
</dependency>
-->

<!-- jetty -->
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 c51036c

Please sign in to comment.