Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b6481e1

Browse files
web
1 parent 7e716bb commit b6481e1

File tree

9 files changed

+38
-94
lines changed

9 files changed

+38
-94
lines changed

‎README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,9 @@ package cn.com.hellowood.dynamicdatasource.controller;
513513

514514
import cn.com.hellowood.dynamicdatasource.common.CommonResponse;
515515
import cn.com.hellowood.dynamicdatasource.common.ResponseUtil;
516-
import cn.com.hellowood.dynamicdatasource.modal.Product;
516+
import cn.com.hellowood.dynamicdatasource.model.Product;
517517
import cn.com.hellowood.dynamicdatasource.service.ProductService;
518-
import cn.com.hellowood.dynamicdatasource.utils.ServiceException;
518+
import cn.com.hellowood.dynamicdatasource.error.ServiceException;
519519
import org.springframework.beans.factory.annotation.Autowired;
520520
import org.springframework.web.bind.annotation.*;
521521

@@ -560,8 +560,8 @@ public class ProductController {
560560
package cn.com.hellowood.dynamicdatasource.service;
561561

562562
import cn.com.hellowood.dynamicdatasource.mapper.ProductDao;
563-
import cn.com.hellowood.dynamicdatasource.modal.Product;
564-
import cn.com.hellowood.dynamicdatasource.utils.ServiceException;
563+
import cn.com.hellowood.dynamicdatasource.model.Product;
564+
import cn.com.hellowood.dynamicdatasource.error.ServiceException;
565565
import org.springframework.beans.factory.annotation.Autowired;
566566
import org.springframework.dao.DataAccessException;
567567
import org.springframework.stereotype.Service;
@@ -622,7 +622,7 @@ public class ProductService {
622622
```java
623623
package cn.com.hellowood.dynamicdatasource.mapper;
624624

625-
import cn.com.hellowood.dynamicdatasource.modal.Product;
625+
import cn.com.hellowood.dynamicdatasource.model.Product;
626626
import org.apache.ibatis.annotations.Mapper;
627627
import org.apache.ibatis.annotations.Param;
628628

‎src/main/java/cn/com/hellowood/dynamicdatasource/common/ResponseUtil.java

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -18,69 +18,6 @@ public class ResponseUtil {
1818

1919
private static final Logger logger = LoggerFactory.getLogger(ResponseUtil.class);
2020

21-
/**
22-
* return response with default success or error message by status
23-
*
24-
* @param resultStatus
25-
* @return
26-
*/
27-
public static CommonResponse generateResponse(boolean resultStatus) {
28-
CommonResponse commonResponse = new CommonResponse();
29-
if (resultStatus) {
30-
commonResponse
31-
.setCode(ResponseCode.SUCCESS)
32-
.setMessage(CommonConstant.DEFAULT_SUCCESS_MESSAGE);
33-
} else {
34-
commonResponse
35-
.setCode(ResponseCode.FAIL)
36-
.setMessage(CommonConstant.DEFAULT_FAIL_MESSAGE);
37-
}
38-
return commonResponse;
39-
}
40-
41-
/**
42-
* return response with custom message by status
43-
*
44-
* @param message
45-
* @param resultStatus
46-
* @return
47-
*/
48-
public static CommonResponse generateResponse(String message, boolean resultStatus) {
49-
CommonResponse commonResponse = new CommonResponse();
50-
if (resultStatus) {
51-
commonResponse
52-
.setCode(ResponseCode.SUCCESS)
53-
.setMessage(message);
54-
} else {
55-
commonResponse
56-
.setCode(ResponseCode.FAIL)
57-
.setMessage(message);
58-
}
59-
return commonResponse;
60-
}
61-
62-
/**
63-
* return response with data,if data is null,return no data message,or return data
64-
*
65-
* @param data
66-
* @return
67-
*/
68-
public static CommonResponse generateResponse(Object data) {
69-
CommonResponse commonResponse = new CommonResponse();
70-
if (data != null) {
71-
commonResponse
72-
.setCode(ResponseCode.SUCCESS)
73-
.setMessage(CommonConstant.DEFAULT_SUCCESS_MESSAGE)
74-
.setData(data);
75-
} else {
76-
commonResponse
77-
.setCode(ResponseCode.SUCCESS)
78-
.setMessage(CommonConstant.NO_RESULT_MESSAGE);
79-
80-
}
81-
return commonResponse;
82-
}
83-
8421
/**
8522
* Handler response information
8623
*

‎src/main/java/cn/com/hellowood/dynamicdatasource/configuration/CustomHandlerExceptionResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import cn.com.hellowood.dynamicdatasource.common.CommonResponse;
55
import cn.com.hellowood.dynamicdatasource.common.ResponseCode;
66
import cn.com.hellowood.dynamicdatasource.common.ResponseUtil;
7-
import cn.com.hellowood.dynamicdatasource.utils.ServiceException;
7+
import cn.com.hellowood.dynamicdatasource.error.ServiceException;
88
import org.slf4j.Logger;
99
import org.slf4j.LoggerFactory;
1010
import org.springframework.dao.DataAccessException;

‎src/main/java/cn/com/hellowood/dynamicdatasource/controller/ProductController.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package cn.com.hellowood.dynamicdatasource.controller;
22

3-
import cn.com.hellowood.dynamicdatasource.common.CommonResponse;
4-
import cn.com.hellowood.dynamicdatasource.common.ResponseUtil;
5-
import cn.com.hellowood.dynamicdatasource.modal.Product;
3+
import cn.com.hellowood.dynamicdatasource.apiutil.annotation.ApiResponseBody;
4+
import cn.com.hellowood.dynamicdatasource.model.Product;
65
import cn.com.hellowood.dynamicdatasource.service.ProductService;
7-
import cn.com.hellowood.dynamicdatasource.utils.ServiceException;
8-
import org.springframework.beans.factory.annotation.Autowired;
6+
import cn.com.hellowood.dynamicdatasource.error.ServiceException;
97
import org.springframework.web.bind.annotation.*;
108

9+
import javax.annotation.Resource;
10+
import java.util.List;
11+
1112
/**
1213
* Product controller
1314
*
@@ -20,7 +21,7 @@
2021
@RequestMapping("/product")
2122
public class ProductController {
2223

23-
@Autowired
24+
@Resource
2425
private ProductService productService;
2526

2627
/**
@@ -31,8 +32,9 @@ public class ProductController {
3132
* @throws ServiceException
3233
*/
3334
@GetMapping("/{id}")
34-
public CommonResponse getProduct(@PathVariable("id") Long productId) throws ServiceException {
35-
return ResponseUtil.generateResponse(productService.select(productId));
35+
@ApiResponseBody
36+
public Product getProduct(@PathVariable("id") Long productId) throws ServiceException {
37+
return productService.select(productId);
3638
}
3739

3840
/**
@@ -42,8 +44,9 @@ public CommonResponse getProduct(@PathVariable("id") Long productId) throws Serv
4244
* @throws ServiceException
4345
*/
4446
@GetMapping
45-
public CommonResponse getAllProduct() {
46-
return ResponseUtil.generateResponse(productService.getAllProduct());
47+
@ApiResponseBody
48+
public List<Product> getAllProduct() {
49+
return productService.getAllProduct();
4750
}
4851

4952
/**
@@ -54,9 +57,11 @@ public CommonResponse getAllProduct() {
5457
* @return
5558
* @throws ServiceException
5659
*/
60+
5761
@PutMapping("/{id}")
58-
public CommonResponse updateProduct(@PathVariable("id") Long productId, @RequestBody Product newProduct) throws ServiceException {
59-
return ResponseUtil.generateResponse(productService.update(productId, newProduct));
62+
@ApiResponseBody
63+
public Product updateProduct(@PathVariable("id") Long productId, @RequestBody Product newProduct) throws ServiceException {
64+
return productService.update(productId, newProduct);
6065
}
6166

6267
/**
@@ -67,8 +72,9 @@ public CommonResponse updateProduct(@PathVariable("id") Long productId, @Request
6772
* @throws ServiceException
6873
*/
6974
@DeleteMapping("/{id}")
70-
public CommonResponse deleteProduct(@PathVariable("id") long productId) throws ServiceException {
71-
return ResponseUtil.generateResponse(productService.delete(productId));
75+
@ApiResponseBody
76+
public boolean deleteProduct(@PathVariable("id") long productId) throws ServiceException {
77+
return productService.delete(productId);
7278
}
7379

7480
/**
@@ -79,7 +85,8 @@ public CommonResponse deleteProduct(@PathVariable("id") long productId) throws S
7985
* @throws ServiceException
8086
*/
8187
@PostMapping
82-
public CommonResponse addProduct(@RequestBody Product newProduct) throws ServiceException {
83-
return ResponseUtil.generateResponse(productService.add(newProduct));
88+
@ApiResponseBody
89+
public boolean addProduct(@RequestBody Product newProduct) throws ServiceException {
90+
return productService.add(newProduct);
8491
}
8592
}

‎src/main/java/cn/com/hellowood/dynamicdatasource/utils/ServiceException.java renamed to ‎src/main/java/cn/com/hellowood/dynamicdatasource/error/ServiceException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package cn.com.hellowood.dynamicdatasource.utils;
1+
package cn.com.hellowood.dynamicdatasource.error;
22

33
import org.springframework.http.HttpStatus;
44
import org.springframework.web.bind.annotation.ResponseStatus;

‎src/main/java/cn/com/hellowood/dynamicdatasource/mapper/ProductDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package cn.com.hellowood.dynamicdatasource.mapper;
22

3-
import cn.com.hellowood.dynamicdatasource.modal.Product;
3+
import cn.com.hellowood.dynamicdatasource.model.Product;
44
import org.apache.ibatis.annotations.Mapper;
55
import org.apache.ibatis.annotations.Param;
66

‎src/main/java/cn/com/hellowood/dynamicdatasource/modal/Product.java renamed to ‎src/main/java/cn/com/hellowood/dynamicdatasource/model/Product.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package cn.com.hellowood.dynamicdatasource.modal;
1+
package cn.com.hellowood.dynamicdatasource.model;
22

33
import java.io.Serializable;
44

‎src/main/java/cn/com/hellowood/dynamicdatasource/service/ProductService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package cn.com.hellowood.dynamicdatasource.service;
22

33
import cn.com.hellowood.dynamicdatasource.mapper.ProductDao;
4-
import cn.com.hellowood.dynamicdatasource.modal.Product;
5-
import cn.com.hellowood.dynamicdatasource.utils.ServiceException;
4+
import cn.com.hellowood.dynamicdatasource.model.Product;
5+
import cn.com.hellowood.dynamicdatasource.error.ServiceException;
66
import org.springframework.beans.factory.annotation.Autowired;
77
import org.springframework.dao.DataAccessException;
88
import org.springframework.stereotype.Service;

‎src/main/resources/mappers/ProductMapper.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
33
<mapper namespace="cn.com.hellowood.dynamicdatasource.mapper.ProductDao">
44

5-
<resultMap id="baseResultMap" type="cn.com.hellowood.dynamicdatasource.modal.Product">
5+
<resultMap id="baseResultMap" type="cn.com.hellowood.dynamicdatasource.model.Product">
66
<id column="id" property="id" javaType="java.lang.Long" jdbcType="INTEGER"></id>
77
<result column="name" property="name" javaType="java.lang.String" jdbcType="VARCHAR"></result>
88
<result column="price" property="price" javaType="java.lang.Long" jdbcType="BIGINT"></result>
99
</resultMap>
1010

11-
<select id="select" resultType="cn.com.hellowood.dynamicdatasource.modal.Product">
11+
<select id="select" resultType="cn.com.hellowood.dynamicdatasource.model.Product">
1212
SELECT *
1313
FROM product
1414
WHERE id = #{id}
@@ -20,7 +20,7 @@
2020
FROM product
2121
</select>
2222

23-
<update id="update" parameterType="cn.com.hellowood.dynamicdatasource.modal.Product" flushCache="true">
23+
<update id="update" parameterType="cn.com.hellowood.dynamicdatasource.model.Product" flushCache="true">
2424
UPDATE product
2525
SET name = #{name}, price = #{price}
2626
WHERE id = #{id}
@@ -33,7 +33,7 @@
3333
LIMIT 1
3434
</delete>
3535

36-
<insert id="insert" parameterType="cn.com.hellowood.dynamicdatasource.modal.Product">
36+
<insert id="insert" parameterType="cn.com.hellowood.dynamicdatasource.model.Product">
3737
INSERT INTO product (name, price) VALUES (#{name}, #{price});
3838
</insert>
3939
</mapper>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /