提交 fea70551 authored 作者: mry's avatar mry

perf(web): 部分Controller返回值

上级 17fd07f6
package org.matrix.autotest.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* @author mry
*/
@Configuration
public class MyConfiguration {
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOriginPatterns("*")
.allowedMethods("GET", "POST", "DELETE", "PUT", "PATCH")
.exposedHeaders("access-control-allow-headers",
"access-control-allow-methods",
"access-control-allow-origin",
"access-control-max-age",
"X-Frame-Options")
.allowCredentials(true)
.maxAge(3600);
}
};
}
}
...@@ -5,6 +5,8 @@ import io.swagger.annotations.ApiOperation; ...@@ -5,6 +5,8 @@ import io.swagger.annotations.ApiOperation;
import org.matrix.autotest.entity.Action; import org.matrix.autotest.entity.Action;
import org.matrix.autotest.service.ActionService; import org.matrix.autotest.service.ActionService;
import org.matrix.autotest.utils.CommonResult; import org.matrix.autotest.utils.CommonResult;
import org.matrix.autotest.utils.CommonResultObj;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
...@@ -17,6 +19,7 @@ import java.util.List; ...@@ -17,6 +19,7 @@ import java.util.List;
* @author mry * @author mry
* @since 2022-01-07 * @since 2022-01-07
*/ */
@CrossOrigin
@RestController @RestController
@RequestMapping("/actions") @RequestMapping("/actions")
@Api(tags = "对动作表action的基本操作") @Api(tags = "对动作表action的基本操作")
...@@ -35,10 +38,10 @@ public class ActionController { ...@@ -35,10 +38,10 @@ public class ActionController {
*/ */
@ApiOperation(value = "查询所有动作") @ApiOperation(value = "查询所有动作")
@GetMapping @GetMapping
public CommonResult<List<Action>> findAllAction() { public ResponseEntity<CommonResultObj<List<Action>>> findAllAction() {
List<Action> results = actionService.findAllAction(); List<Action> results = actionService.findAllAction();
if (results != null && results.size() != 0) { if (results != null && results.size() != 0) {
return CommonResult.success(results); return CommonResult.success(results,"查询成功");
} else { } else {
return CommonResult.failed("查询失败或无数据"); return CommonResult.failed("查询失败或无数据");
} }
...@@ -52,10 +55,10 @@ public class ActionController { ...@@ -52,10 +55,10 @@ public class ActionController {
*/ */
@ApiOperation(value = "根据id查询动作") @ApiOperation(value = "根据id查询动作")
@GetMapping("/{id}") @GetMapping("/{id}")
public CommonResult<Action> findByIdAction(@PathVariable Integer id) { public ResponseEntity<CommonResultObj<Action>> findByIdAction(@PathVariable Integer id) {
Action result = actionService.findByIdAction(id); Action result = actionService.findByIdAction(id);
if (result != null) { if (result != null) {
return CommonResult.success(result); return CommonResult.success(result,"查询成功");
} else { } else {
return CommonResult.failed("查询失败或无数据"); return CommonResult.failed("查询失败或无数据");
} }
...@@ -69,10 +72,10 @@ public class ActionController { ...@@ -69,10 +72,10 @@ public class ActionController {
*/ */
@ApiOperation(value = "添加动作") @ApiOperation(value = "添加动作")
@PostMapping @PostMapping
public CommonResult<Action> insertAction(@RequestBody Action action) { public ResponseEntity<CommonResultObj<Action>> insertAction(@RequestBody Action action) {
int i = actionService.insertAction(action); int i = actionService.insertAction(action);
if (i != 0) { if (i != 0) {
return CommonResult.success(action); return CommonResult.success(action,"添加成功");
} else { } else {
return CommonResult.failed("添加失败"); return CommonResult.failed("添加失败");
} }
...@@ -86,10 +89,10 @@ public class ActionController { ...@@ -86,10 +89,10 @@ public class ActionController {
*/ */
@ApiOperation(value = "根据id修改动作") @ApiOperation(value = "根据id修改动作")
@PutMapping("/{id}") @PutMapping("/{id}")
public CommonResult<Action> updateAction(@RequestBody Action action) { public ResponseEntity<CommonResultObj<Action>> updateAction(@RequestBody Action action) {
int i = actionService.updateAction(action); int i = actionService.updateAction(action);
if (i != 0) { if (i != 0) {
return CommonResult.success(action); return CommonResult.success(action,"修改成功");
} else { } else {
return CommonResult.failed("修改失败"); return CommonResult.failed("修改失败");
} }
...@@ -103,7 +106,7 @@ public class ActionController { ...@@ -103,7 +106,7 @@ public class ActionController {
*/ */
@ApiOperation(value = "根据id删除动作") @ApiOperation(value = "根据id删除动作")
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
public CommonResult<Action> deleteAction(@PathVariable Integer id) { public ResponseEntity<CommonResultObj<Action>> deleteAction(@PathVariable Integer id) {
int i = actionService.deleteAction(id); int i = actionService.deleteAction(id);
if (i != 0) { if (i != 0) {
return CommonResult.success("删除成功"); return CommonResult.success("删除成功");
...@@ -120,10 +123,10 @@ public class ActionController { ...@@ -120,10 +123,10 @@ public class ActionController {
*/ */
@ApiOperation(value = "根据项目id查询所有") @ApiOperation(value = "根据项目id查询所有")
@GetMapping("/project/{projectId}") @GetMapping("/project/{projectId}")
public CommonResult<List<Action>> findByProjectIdAction(@PathVariable Integer projectId) { public ResponseEntity<CommonResultObj<List<Action>>> findByProjectIdAction(@PathVariable Integer projectId) {
List<Action> results = actionService.findByProjectIdAction(projectId); List<Action> results = actionService.findByProjectIdAction(projectId);
if (results != null && results.size() != 0) { if (results != null && results.size() != 0) {
return CommonResult.success(results); return CommonResult.success(results,"查询成功");
} else { } else {
return CommonResult.failed("查询失败或无数据"); return CommonResult.failed("查询失败或无数据");
} }
...@@ -137,10 +140,10 @@ public class ActionController { ...@@ -137,10 +140,10 @@ public class ActionController {
*/ */
@ApiOperation(value = "根据行为id查询所有") @ApiOperation(value = "根据行为id查询所有")
@GetMapping("/move/{moveId}") @GetMapping("/move/{moveId}")
public CommonResult<List<Action>> findByMoveIdAction(@PathVariable Integer moveId) { public ResponseEntity<CommonResultObj<List<Action>>> findByMoveIdAction(@PathVariable Integer moveId) {
List<Action> results = actionService.findByMoveIdAction(moveId); List<Action> results = actionService.findByMoveIdAction(moveId);
if (results != null && results.size() != 0) { if (results != null && results.size() != 0) {
return CommonResult.success(results); return CommonResult.success(results,"查询成功");
} else { } else {
return CommonResult.failed("查询失败或无数据"); return CommonResult.failed("查询失败或无数据");
} }
......
...@@ -5,6 +5,8 @@ import io.swagger.annotations.ApiOperation; ...@@ -5,6 +5,8 @@ import io.swagger.annotations.ApiOperation;
import org.matrix.autotest.entity.Connect; import org.matrix.autotest.entity.Connect;
import org.matrix.autotest.service.ConnectService; import org.matrix.autotest.service.ConnectService;
import org.matrix.autotest.utils.CommonResult; import org.matrix.autotest.utils.CommonResult;
import org.matrix.autotest.utils.CommonResultObj;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
...@@ -17,6 +19,7 @@ import java.util.List; ...@@ -17,6 +19,7 @@ import java.util.List;
* @author mry * @author mry
* @since 2022-01-07 * @since 2022-01-07
*/ */
@CrossOrigin
@RestController @RestController
@RequestMapping("/connects") @RequestMapping("/connects")
@Api(tags = "对连接池表connect的基本操作") @Api(tags = "对连接池表connect的基本操作")
...@@ -35,10 +38,10 @@ public class ConnectController { ...@@ -35,10 +38,10 @@ public class ConnectController {
*/ */
@ApiOperation(value = "查询所有连接池") @ApiOperation(value = "查询所有连接池")
@GetMapping @GetMapping
public CommonResult<List<Connect>> findAllConnect() { public ResponseEntity<CommonResultObj<List<Connect>>> findAllConnect() {
List<Connect> results = connectService.findAllConnect(); List<Connect> results = connectService.findAllConnect();
if (results != null && results.size() != 0) { if (results != null && results.size() != 0) {
return CommonResult.success(results); return CommonResult.success(results,"查询成功");
} else { } else {
return CommonResult.failed("查询失败或无数据"); return CommonResult.failed("查询失败或无数据");
} }
...@@ -52,10 +55,10 @@ public class ConnectController { ...@@ -52,10 +55,10 @@ public class ConnectController {
*/ */
@ApiOperation(value = "根据id查询连接池") @ApiOperation(value = "根据id查询连接池")
@GetMapping("/{id}") @GetMapping("/{id}")
public CommonResult<Connect> findByIdConnect(@PathVariable Integer id) { public ResponseEntity<CommonResultObj<Connect>> findByIdConnect(@PathVariable Integer id) {
Connect result = connectService.findByIdConnect(id); Connect result = connectService.findByIdConnect(id);
if (result != null) { if (result != null) {
return CommonResult.success(result); return CommonResult.success(result,"查询成功");
} else { } else {
return CommonResult.failed("查询失败或无数据"); return CommonResult.failed("查询失败或无数据");
} }
...@@ -69,10 +72,10 @@ public class ConnectController { ...@@ -69,10 +72,10 @@ public class ConnectController {
*/ */
@ApiOperation(value = "添加连接池") @ApiOperation(value = "添加连接池")
@PostMapping @PostMapping
public CommonResult<Connect> insertConnect(@RequestBody Connect connect) { public ResponseEntity<CommonResultObj<Connect>> insertConnect(@RequestBody Connect connect) {
int i = connectService.insertConnect(connect); int i = connectService.insertConnect(connect);
if (i != 0) { if (i != 0) {
return CommonResult.success(connect); return CommonResult.success(connect,"添加成功");
} else { } else {
return CommonResult.failed("添加失败"); return CommonResult.failed("添加失败");
} }
...@@ -86,10 +89,10 @@ public class ConnectController { ...@@ -86,10 +89,10 @@ public class ConnectController {
*/ */
@ApiOperation(value = "根据id修改连接池") @ApiOperation(value = "根据id修改连接池")
@PutMapping("/{id}") @PutMapping("/{id}")
public CommonResult<Connect> updateConnect(@RequestBody Connect connect) { public ResponseEntity<CommonResultObj<Connect>> updateConnect(@RequestBody Connect connect) {
int i = connectService.updateConnect(connect); int i = connectService.updateConnect(connect);
if (i != 0) { if (i != 0) {
return CommonResult.success(connect); return CommonResult.success(connect,"修改成功");
} else { } else {
return CommonResult.failed("修改失败"); return CommonResult.failed("修改失败");
} }
...@@ -103,7 +106,7 @@ public class ConnectController { ...@@ -103,7 +106,7 @@ public class ConnectController {
*/ */
@ApiOperation(value = "根据id删除连接池") @ApiOperation(value = "根据id删除连接池")
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
public CommonResult<Connect> deleteConnect(@PathVariable Integer id) { public ResponseEntity<CommonResultObj<Connect>> deleteConnect(@PathVariable Integer id) {
int i = connectService.deleteConnect(id); int i = connectService.deleteConnect(id);
if (i != 0) { if (i != 0) {
return CommonResult.success("删除成功"); return CommonResult.success("删除成功");
......
...@@ -5,6 +5,8 @@ import io.swagger.annotations.ApiOperation; ...@@ -5,6 +5,8 @@ import io.swagger.annotations.ApiOperation;
import org.matrix.autotest.entity.DynamicVariable; import org.matrix.autotest.entity.DynamicVariable;
import org.matrix.autotest.service.DynamicVariableService; import org.matrix.autotest.service.DynamicVariableService;
import org.matrix.autotest.utils.CommonResult; import org.matrix.autotest.utils.CommonResult;
import org.matrix.autotest.utils.CommonResultObj;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
...@@ -17,6 +19,7 @@ import java.util.List; ...@@ -17,6 +19,7 @@ import java.util.List;
* @author mry * @author mry
* @since 2022-01-07 * @since 2022-01-07
*/ */
@CrossOrigin
@RestController @RestController
@RequestMapping("/dynamicVariables") @RequestMapping("/dynamicVariables")
@Api(tags = "对动态变量表dynamic_variable的基本操作") @Api(tags = "对动态变量表dynamic_variable的基本操作")
...@@ -35,10 +38,10 @@ public class DynamicVariableController { ...@@ -35,10 +38,10 @@ public class DynamicVariableController {
*/ */
@ApiOperation(value = "查询所有动态变量") @ApiOperation(value = "查询所有动态变量")
@GetMapping @GetMapping
public CommonResult<List<DynamicVariable>> findAllDynamicVariable() { public ResponseEntity<CommonResultObj<List<DynamicVariable>>> findAllDynamicVariable() {
List<DynamicVariable> results = dynamicVariableService.findAllDynamicVariable(); List<DynamicVariable> results = dynamicVariableService.findAllDynamicVariable();
if (results != null && results.size() != 0) { if (results != null && results.size() != 0) {
return CommonResult.success(results); return CommonResult.success(results,"查询成功");
} else { } else {
return CommonResult.failed("查询失败或无数据"); return CommonResult.failed("查询失败或无数据");
} }
...@@ -52,10 +55,10 @@ public class DynamicVariableController { ...@@ -52,10 +55,10 @@ public class DynamicVariableController {
*/ */
@ApiOperation(value = "根据id查询动态变量") @ApiOperation(value = "根据id查询动态变量")
@GetMapping("/{id}") @GetMapping("/{id}")
public CommonResult<DynamicVariable> findByIdDynamicVariable(@PathVariable Integer id) { public ResponseEntity<CommonResultObj<DynamicVariable>> findByIdDynamicVariable(@PathVariable Integer id) {
DynamicVariable result = dynamicVariableService.findByIdDynamicVariable(id); DynamicVariable result = dynamicVariableService.findByIdDynamicVariable(id);
if (result != null) { if (result != null) {
return CommonResult.success(result); return CommonResult.success(result,"查询成功");
} else { } else {
return CommonResult.failed("查询失败或无数据"); return CommonResult.failed("查询失败或无数据");
} }
...@@ -69,10 +72,10 @@ public class DynamicVariableController { ...@@ -69,10 +72,10 @@ public class DynamicVariableController {
*/ */
@ApiOperation(value = "添加动态变量") @ApiOperation(value = "添加动态变量")
@PostMapping @PostMapping
public CommonResult<DynamicVariable> insertDynamicVariable(@RequestBody DynamicVariable dynamicVariable) { public ResponseEntity<CommonResultObj<DynamicVariable>> insertDynamicVariable(@RequestBody DynamicVariable dynamicVariable) {
int i = dynamicVariableService.insertDynamicVariable(dynamicVariable); int i = dynamicVariableService.insertDynamicVariable(dynamicVariable);
if (i != 0) { if (i != 0) {
return CommonResult.success(dynamicVariable); return CommonResult.success(dynamicVariable,"添加成功");
} else { } else {
return CommonResult.failed("添加失败"); return CommonResult.failed("添加失败");
} }
...@@ -86,10 +89,10 @@ public class DynamicVariableController { ...@@ -86,10 +89,10 @@ public class DynamicVariableController {
*/ */
@ApiOperation(value = "根据id修改动态变量") @ApiOperation(value = "根据id修改动态变量")
@PutMapping("/{id}") @PutMapping("/{id}")
public CommonResult<DynamicVariable> updateDynamicVariable(@RequestBody DynamicVariable dynamicVariable) { public ResponseEntity<CommonResultObj<DynamicVariable>> updateDynamicVariable(@RequestBody DynamicVariable dynamicVariable) {
int i = dynamicVariableService.updateDynamicVariable(dynamicVariable); int i = dynamicVariableService.updateDynamicVariable(dynamicVariable);
if (i != 0) { if (i != 0) {
return CommonResult.success(dynamicVariable); return CommonResult.success(dynamicVariable,"修改成功");
} else { } else {
return CommonResult.failed("修改失败"); return CommonResult.failed("修改失败");
} }
...@@ -103,7 +106,7 @@ public class DynamicVariableController { ...@@ -103,7 +106,7 @@ public class DynamicVariableController {
*/ */
@ApiOperation(value = "根据id删除动态变量") @ApiOperation(value = "根据id删除动态变量")
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
public CommonResult<DynamicVariable> deleteDynamicVariable(@PathVariable Integer id) { public ResponseEntity<CommonResultObj<DynamicVariable>> deleteDynamicVariable(@PathVariable Integer id) {
int i = dynamicVariableService.deleteDynamicVariable(id); int i = dynamicVariableService.deleteDynamicVariable(id);
if (i != 0) { if (i != 0) {
return CommonResult.success("删除成功"); return CommonResult.success("删除成功");
...@@ -120,10 +123,10 @@ public class DynamicVariableController { ...@@ -120,10 +123,10 @@ public class DynamicVariableController {
*/ */
@ApiOperation(value = "根据项目id查询所有") @ApiOperation(value = "根据项目id查询所有")
@GetMapping("/project/{projectId}") @GetMapping("/project/{projectId}")
public CommonResult<List<DynamicVariable>> findByProjectIdDynamicVariable(@PathVariable Integer projectId) { public ResponseEntity<CommonResultObj<List<DynamicVariable>>> findByProjectIdDynamicVariable(@PathVariable Integer projectId) {
List<DynamicVariable> results = dynamicVariableService.findByProjectIdDynamicVariable(projectId); List<DynamicVariable> results = dynamicVariableService.findByProjectIdDynamicVariable(projectId);
if (results != null && results.size() != 0) { if (results != null && results.size() != 0) {
return CommonResult.success(results); return CommonResult.success(results,"查询成功");
} else { } else {
return CommonResult.failed("查询失败或无数据"); return CommonResult.failed("查询失败或无数据");
} }
......
...@@ -5,6 +5,8 @@ import io.swagger.annotations.ApiOperation; ...@@ -5,6 +5,8 @@ import io.swagger.annotations.ApiOperation;
import org.matrix.autotest.entity.Environment; import org.matrix.autotest.entity.Environment;
import org.matrix.autotest.service.EnvironmentService; import org.matrix.autotest.service.EnvironmentService;
import org.matrix.autotest.utils.CommonResult; import org.matrix.autotest.utils.CommonResult;
import org.matrix.autotest.utils.CommonResultObj;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
...@@ -17,6 +19,7 @@ import java.util.List; ...@@ -17,6 +19,7 @@ import java.util.List;
* @author mry * @author mry
* @since 2022-01-07 * @since 2022-01-07
*/ */
@CrossOrigin
@RestController @RestController
@RequestMapping("/environments") @RequestMapping("/environments")
@Api(tags = "对实例表environment的基本操作") @Api(tags = "对实例表environment的基本操作")
...@@ -35,10 +38,10 @@ public class EnvironmentController { ...@@ -35,10 +38,10 @@ public class EnvironmentController {
*/ */
@ApiOperation(value = "查询所有实例") @ApiOperation(value = "查询所有实例")
@GetMapping @GetMapping
public CommonResult<List<Environment>> findAllEnvironment() { public ResponseEntity<CommonResultObj<List<Environment>>> findAllEnvironment() {
List<Environment> results = environmentService.findAllEnvironment(); List<Environment> results = environmentService.findAllEnvironment();
if (results != null && results.size() != 0) { if (results != null && results.size() != 0) {
return CommonResult.success(results); return CommonResult.success(results,"查询成功");
} else { } else {
return CommonResult.failed("查询失败或无数据"); return CommonResult.failed("查询失败或无数据");
} }
...@@ -52,10 +55,10 @@ public class EnvironmentController { ...@@ -52,10 +55,10 @@ public class EnvironmentController {
*/ */
@ApiOperation(value = "根据id查询实例") @ApiOperation(value = "根据id查询实例")
@GetMapping("/{id}") @GetMapping("/{id}")
public CommonResult<Environment> findByIdEnvironment(@PathVariable Integer id) { public ResponseEntity<CommonResultObj<Environment>> findByIdEnvironment(@PathVariable Integer id) {
Environment result = environmentService.findByIdEnvironment(id); Environment result = environmentService.findByIdEnvironment(id);
if (result != null) { if (result != null) {
return CommonResult.success(result); return CommonResult.success(result,"查询成功");
} else { } else {
return CommonResult.failed("查询失败或无数据"); return CommonResult.failed("查询失败或无数据");
} }
...@@ -69,10 +72,10 @@ public class EnvironmentController { ...@@ -69,10 +72,10 @@ public class EnvironmentController {
*/ */
@ApiOperation(value = "添加实例") @ApiOperation(value = "添加实例")
@PostMapping @PostMapping
public CommonResult<Environment> insertEnvironment(@RequestBody Environment environment) { public ResponseEntity<CommonResultObj<Environment>> insertEnvironment(@RequestBody Environment environment) {
int i = environmentService.insertEnvironment(environment); int i = environmentService.insertEnvironment(environment);
if (i != 0) { if (i != 0) {
return CommonResult.success(environment); return CommonResult.success(environment,"添加成功");
} else { } else {
return CommonResult.failed("添加失败"); return CommonResult.failed("添加失败");
} }
...@@ -86,10 +89,10 @@ public class EnvironmentController { ...@@ -86,10 +89,10 @@ public class EnvironmentController {
*/ */
@ApiOperation(value = "根据id修改实例") @ApiOperation(value = "根据id修改实例")
@PutMapping("/{id}") @PutMapping("/{id}")
public CommonResult<Environment> updateEnvironment(@RequestBody Environment environment) { public ResponseEntity<CommonResultObj<Environment>> updateEnvironment(@RequestBody Environment environment) {
int i = environmentService.updateEnvironment(environment); int i = environmentService.updateEnvironment(environment);
if (i != 0) { if (i != 0) {
return CommonResult.success(environment); return CommonResult.success(environment,"修改成功");
} else { } else {
return CommonResult.failed("修改失败"); return CommonResult.failed("修改失败");
} }
...@@ -103,7 +106,7 @@ public class EnvironmentController { ...@@ -103,7 +106,7 @@ public class EnvironmentController {
*/ */
@ApiOperation(value = "根据id删除实例") @ApiOperation(value = "根据id删除实例")
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
public CommonResult<Environment> deleteEnvironment(@PathVariable Integer id) { public ResponseEntity<CommonResultObj<Environment>> deleteEnvironment(@PathVariable Integer id) {
int i = environmentService.deleteEnvironment(id); int i = environmentService.deleteEnvironment(id);
if (i != 0) { if (i != 0) {
return CommonResult.success("删除成功"); return CommonResult.success("删除成功");
...@@ -120,10 +123,10 @@ public class EnvironmentController { ...@@ -120,10 +123,10 @@ public class EnvironmentController {
*/ */
@ApiOperation(value = "根据项目id查询所有") @ApiOperation(value = "根据项目id查询所有")
@GetMapping("/project/{projectId}") @GetMapping("/project/{projectId}")
public CommonResult<List<Environment>> findByProjectIdEnvironment(@PathVariable Integer projectId) { public ResponseEntity<CommonResultObj<List<Environment>>> findByProjectIdEnvironment(@PathVariable Integer projectId) {
List<Environment> results = environmentService.findByProjectIdEnvironment(projectId); List<Environment> results = environmentService.findByProjectIdEnvironment(projectId);
if (results != null && results.size() != 0) { if (results != null && results.size() != 0) {
return CommonResult.success(results); return CommonResult.success(results,"查询成功");
} else { } else {
return CommonResult.failed("查询失败或无数据"); return CommonResult.failed("查询失败或无数据");
} }
......
...@@ -5,6 +5,8 @@ import io.swagger.annotations.ApiOperation; ...@@ -5,6 +5,8 @@ import io.swagger.annotations.ApiOperation;
import org.matrix.autotest.entity.Move; import org.matrix.autotest.entity.Move;
import org.matrix.autotest.service.MoveService; import org.matrix.autotest.service.MoveService;
import org.matrix.autotest.utils.CommonResult; import org.matrix.autotest.utils.CommonResult;
import org.matrix.autotest.utils.CommonResultObj;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
...@@ -17,6 +19,7 @@ import java.util.List; ...@@ -17,6 +19,7 @@ import java.util.List;
* @author mry * @author mry
* @since 2022-01-07 * @since 2022-01-07
*/ */
@CrossOrigin
@RestController @RestController
@RequestMapping("/moves") @RequestMapping("/moves")
@Api(tags = "对行为表move的基本操作") @Api(tags = "对行为表move的基本操作")
...@@ -35,10 +38,10 @@ public class MoveController { ...@@ -35,10 +38,10 @@ public class MoveController {
*/ */
@ApiOperation(value = "查询所有行为") @ApiOperation(value = "查询所有行为")
@GetMapping @GetMapping
public CommonResult<List<Move>> findAllMove() { public ResponseEntity<CommonResultObj<List<Move>>> findAllMove() {
List<Move> results = moveService.findAllMove(); List<Move> results = moveService.findAllMove();
if (results != null && results.size() != 0) { if (results != null && results.size() != 0) {
return CommonResult.success(results); return CommonResult.success(results,"查询成功");
} else { } else {
return CommonResult.failed("查询失败或无数据"); return CommonResult.failed("查询失败或无数据");
} }
...@@ -52,10 +55,10 @@ public class MoveController { ...@@ -52,10 +55,10 @@ public class MoveController {
*/ */
@ApiOperation(value = "根据id查询行为") @ApiOperation(value = "根据id查询行为")
@GetMapping("/{id}") @GetMapping("/{id}")
public CommonResult<Move> findByIdMove(@PathVariable Integer id) { public ResponseEntity<CommonResultObj<Move>> findByIdMove(@PathVariable Integer id) {
Move result = moveService.findByIdMove(id); Move result = moveService.findByIdMove(id);
if (result != null) { if (result != null) {
return CommonResult.success(result); return CommonResult.success(result,"查询成功");
} else { } else {
return CommonResult.failed("查询失败或无数据"); return CommonResult.failed("查询失败或无数据");
} }
...@@ -69,10 +72,10 @@ public class MoveController { ...@@ -69,10 +72,10 @@ public class MoveController {
*/ */
@ApiOperation(value = "添加行为") @ApiOperation(value = "添加行为")
@PostMapping @PostMapping
public CommonResult<Move> insertMove(@RequestBody Move move) { public ResponseEntity<CommonResultObj<Move>> insertMove(@RequestBody Move move) {
int i = moveService.insertMove(move); int i = moveService.insertMove(move);
if (i != 0) { if (i != 0) {
return CommonResult.success(move); return CommonResult.success(move,"添加成功");
} else { } else {
return CommonResult.failed("添加失败"); return CommonResult.failed("添加失败");
} }
...@@ -86,10 +89,10 @@ public class MoveController { ...@@ -86,10 +89,10 @@ public class MoveController {
*/ */
@ApiOperation(value = "根据id修改行为") @ApiOperation(value = "根据id修改行为")
@PutMapping("/{id}") @PutMapping("/{id}")
public CommonResult<Move> updateMove(@RequestBody Move move) { public ResponseEntity<CommonResultObj<Move>> updateMove(@RequestBody Move move) {
int i = moveService.updateMove(move); int i = moveService.updateMove(move);
if (i != 0) { if (i != 0) {
return CommonResult.success(move); return CommonResult.success(move,"修改成功");
} else { } else {
return CommonResult.failed("修改失败"); return CommonResult.failed("修改失败");
} }
...@@ -103,7 +106,7 @@ public class MoveController { ...@@ -103,7 +106,7 @@ public class MoveController {
*/ */
@ApiOperation(value = "根据id删除行为") @ApiOperation(value = "根据id删除行为")
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
public CommonResult<Move> deleteMove(@PathVariable Integer id) { public ResponseEntity<CommonResultObj<Move>> deleteMove(@PathVariable Integer id) {
int i = moveService.deleteMove(id); int i = moveService.deleteMove(id);
if (i != 0) { if (i != 0) {
return CommonResult.success("删除成功"); return CommonResult.success("删除成功");
...@@ -120,10 +123,10 @@ public class MoveController { ...@@ -120,10 +123,10 @@ public class MoveController {
*/ */
@ApiOperation(value = "根据项目id查询所有") @ApiOperation(value = "根据项目id查询所有")
@GetMapping("/project/{projectId}") @GetMapping("/project/{projectId}")
public CommonResult<List<Move>> findByProjectIdMove(@PathVariable Integer projectId) { public ResponseEntity<CommonResultObj<List<Move>>> findByProjectIdMove(@PathVariable Integer projectId) {
List<Move> results = moveService.findByProjectIdMove(projectId); List<Move> results = moveService.findByProjectIdMove(projectId);
if (results != null && results.size() != 0) { if (results != null && results.size() != 0) {
return CommonResult.success(results); return CommonResult.success(results,"查询成功");
} else { } else {
return CommonResult.failed("查询失败或无数据"); return CommonResult.failed("查询失败或无数据");
} }
......
...@@ -5,6 +5,8 @@ import io.swagger.annotations.ApiOperation; ...@@ -5,6 +5,8 @@ import io.swagger.annotations.ApiOperation;
import org.matrix.autotest.entity.Project; import org.matrix.autotest.entity.Project;
import org.matrix.autotest.service.ProjectService; import org.matrix.autotest.service.ProjectService;
import org.matrix.autotest.utils.CommonResult; import org.matrix.autotest.utils.CommonResult;
import org.matrix.autotest.utils.CommonResultObj;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
...@@ -17,6 +19,7 @@ import java.util.List; ...@@ -17,6 +19,7 @@ import java.util.List;
* @author mry * @author mry
* @since 2022-01-07 * @since 2022-01-07
*/ */
@CrossOrigin
@RestController @RestController
@RequestMapping("/projects") @RequestMapping("/projects")
@Api(tags = "对项目表project的基本操作") @Api(tags = "对项目表project的基本操作")
...@@ -35,10 +38,10 @@ public class ProjectController { ...@@ -35,10 +38,10 @@ public class ProjectController {
*/ */
@ApiOperation(value = "查询所有项目") @ApiOperation(value = "查询所有项目")
@GetMapping @GetMapping
public CommonResult<List<Project>> findAllProject() { public ResponseEntity<CommonResultObj<List<Project>>> findAllProject() {
List<Project> results = projectService.findAllProject(); List<Project> results = projectService.findAllProject();
if (results != null && results.size() != 0){ if (results != null && results.size() != 0){
return CommonResult.success(results); return CommonResult.success(results,"查询成功");
}else { }else {
return CommonResult.failed("查询失败或无数据"); return CommonResult.failed("查询失败或无数据");
} }
...@@ -52,10 +55,10 @@ public class ProjectController { ...@@ -52,10 +55,10 @@ public class ProjectController {
*/ */
@ApiOperation(value = "根据id查询项目") @ApiOperation(value = "根据id查询项目")
@GetMapping("/{id}") @GetMapping("/{id}")
public CommonResult<Project> findByIdProject(@PathVariable Integer id) { public ResponseEntity<CommonResultObj<Project>> findByIdProject(@PathVariable Integer id) {
Project result = projectService.findByIdProject(id); Project result = projectService.findByIdProject(id);
if (result != null){ if (result != null){
return CommonResult.success(result); return CommonResult.success(result,"查询成功");
}else { }else {
return CommonResult.failed("查询失败或无数据"); return CommonResult.failed("查询失败或无数据");
} }
...@@ -69,10 +72,10 @@ public class ProjectController { ...@@ -69,10 +72,10 @@ public class ProjectController {
*/ */
@ApiOperation(value = "添加项目") @ApiOperation(value = "添加项目")
@PostMapping @PostMapping
public CommonResult<Project> insertProject(@RequestBody Project project) { public ResponseEntity<CommonResultObj<Project>> insertProject(@RequestBody Project project) {
int i = projectService.insertProject(project); int i = projectService.insertProject(project);
if (i != 0){ if (i != 0){
return CommonResult.success(project); return CommonResult.success(project,"添加成功");
}else { }else {
return CommonResult.failed("添加失败"); return CommonResult.failed("添加失败");
} }
...@@ -86,10 +89,10 @@ public class ProjectController { ...@@ -86,10 +89,10 @@ public class ProjectController {
*/ */
@ApiOperation(value = "根据id修改项目") @ApiOperation(value = "根据id修改项目")
@PutMapping("/{id}") @PutMapping("/{id}")
public CommonResult<Project> updateProject(@RequestBody Project project) { public ResponseEntity<CommonResultObj<Project>> updateProject(@RequestBody Project project) {
int i = projectService.updateProject(project); int i = projectService.updateProject(project);
if (i != 0){ if (i != 0){
return CommonResult.success(project); return CommonResult.success(project,"修改成功");
}else { }else {
return CommonResult.failed("修改失败"); return CommonResult.failed("修改失败");
} }
...@@ -103,7 +106,7 @@ public class ProjectController { ...@@ -103,7 +106,7 @@ public class ProjectController {
*/ */
@ApiOperation(value = "根据id删除项目") @ApiOperation(value = "根据id删除项目")
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
public CommonResult<Project> deleteProject(@PathVariable Integer id) { public ResponseEntity<CommonResultObj<Project>> deleteProject(@PathVariable Integer id) {
int i = projectService.deleteProject(id); int i = projectService.deleteProject(id);
if (i != 0){ if (i != 0){
return CommonResult.success("删除成功"); return CommonResult.success("删除成功");
......
...@@ -5,6 +5,8 @@ import io.swagger.annotations.ApiOperation; ...@@ -5,6 +5,8 @@ import io.swagger.annotations.ApiOperation;
import org.matrix.autotest.entity.TestCase; import org.matrix.autotest.entity.TestCase;
import org.matrix.autotest.service.TestCaseService; import org.matrix.autotest.service.TestCaseService;
import org.matrix.autotest.utils.CommonResult; import org.matrix.autotest.utils.CommonResult;
import org.matrix.autotest.utils.CommonResultObj;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
...@@ -17,6 +19,7 @@ import java.util.List; ...@@ -17,6 +19,7 @@ import java.util.List;
* @author mry * @author mry
* @since 2022-01-07 * @since 2022-01-07
*/ */
@CrossOrigin
@RestController @RestController
@RequestMapping("/testCases") @RequestMapping("/testCases")
@Api(tags = "对用例表test_case的基本操作") @Api(tags = "对用例表test_case的基本操作")
...@@ -35,10 +38,10 @@ public class TestCaseController { ...@@ -35,10 +38,10 @@ public class TestCaseController {
*/ */
@ApiOperation(value = "查询所有用例") @ApiOperation(value = "查询所有用例")
@GetMapping @GetMapping
public CommonResult<List<TestCase>> findAllTestCase() { public ResponseEntity<CommonResultObj<List<TestCase>>> findAllTestCase() {
List<TestCase> results = testCaseService.findAllTestCase(); List<TestCase> results = testCaseService.findAllTestCase();
if (results != null && results.size() != 0) { if (results != null && results.size() != 0) {
return CommonResult.success(results); return CommonResult.success(results,"查询成功");
} else { } else {
return CommonResult.failed("查询失败或无数据"); return CommonResult.failed("查询失败或无数据");
} }
...@@ -52,10 +55,10 @@ public class TestCaseController { ...@@ -52,10 +55,10 @@ public class TestCaseController {
*/ */
@ApiOperation(value = "根据id查询用例") @ApiOperation(value = "根据id查询用例")
@GetMapping("/{id}") @GetMapping("/{id}")
public CommonResult<TestCase> findByIdTestCase(@PathVariable Integer id) { public ResponseEntity<CommonResultObj<TestCase>> findByIdTestCase(@PathVariable Integer id) {
TestCase result = testCaseService.findByIdTestCase(id); TestCase result = testCaseService.findByIdTestCase(id);
if (result != null) { if (result != null) {
return CommonResult.success(result); return CommonResult.success(result,"查询成功");
} else { } else {
return CommonResult.failed("查询失败或无数据"); return CommonResult.failed("查询失败或无数据");
} }
...@@ -69,10 +72,10 @@ public class TestCaseController { ...@@ -69,10 +72,10 @@ public class TestCaseController {
*/ */
@ApiOperation(value = "添加用例") @ApiOperation(value = "添加用例")
@PostMapping @PostMapping
public CommonResult<TestCase> insertTestCase(@RequestBody TestCase testCase) { public ResponseEntity<CommonResultObj<TestCase>> insertTestCase(@RequestBody TestCase testCase) {
int i = testCaseService.insertTestCase(testCase); int i = testCaseService.insertTestCase(testCase);
if (i != 0) { if (i != 0) {
return CommonResult.success(testCase); return CommonResult.success(testCase,"添加成功");
} else { } else {
return CommonResult.failed("添加失败"); return CommonResult.failed("添加失败");
} }
...@@ -86,10 +89,10 @@ public class TestCaseController { ...@@ -86,10 +89,10 @@ public class TestCaseController {
*/ */
@ApiOperation(value = "根据id修改用例") @ApiOperation(value = "根据id修改用例")
@PutMapping("/{id}") @PutMapping("/{id}")
public CommonResult<TestCase> updateTestCase(@RequestBody TestCase testCase) { public ResponseEntity<CommonResultObj<TestCase>> updateTestCase(@RequestBody TestCase testCase) {
int i = testCaseService.updateTestCase(testCase); int i = testCaseService.updateTestCase(testCase);
if (i != 0) { if (i != 0) {
return CommonResult.success(testCase); return CommonResult.success(testCase,"修改成功");
} else { } else {
return CommonResult.failed("修改失败"); return CommonResult.failed("修改失败");
} }
...@@ -103,7 +106,7 @@ public class TestCaseController { ...@@ -103,7 +106,7 @@ public class TestCaseController {
*/ */
@ApiOperation(value = "根据id删除用例") @ApiOperation(value = "根据id删除用例")
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
public CommonResult<TestCase> deleteTestCase(@PathVariable Integer id) { public ResponseEntity<CommonResultObj<TestCase>> deleteTestCase(@PathVariable Integer id) {
int i = testCaseService.deleteTestCase(id); int i = testCaseService.deleteTestCase(id);
if (i != 0) { if (i != 0) {
return CommonResult.success("删除成功"); return CommonResult.success("删除成功");
...@@ -120,10 +123,10 @@ public class TestCaseController { ...@@ -120,10 +123,10 @@ public class TestCaseController {
*/ */
@ApiOperation(value = "根据项目id查询所有") @ApiOperation(value = "根据项目id查询所有")
@GetMapping("/project/{projectId}") @GetMapping("/project/{projectId}")
public CommonResult<List<TestCase>> findByProjectIdTestCase(@PathVariable Integer projectId) { public ResponseEntity<CommonResultObj<List<TestCase>>> findByProjectIdTestCase(@PathVariable Integer projectId) {
List<TestCase> results = testCaseService.findByProjectIdTestCase(projectId); List<TestCase> results = testCaseService.findByProjectIdTestCase(projectId);
if (results != null && results.size() != 0) { if (results != null && results.size() != 0) {
return CommonResult.success(results); return CommonResult.success(results,"查询成功");
} else { } else {
return CommonResult.failed("查询失败或无数据"); return CommonResult.failed("查询失败或无数据");
} }
......
package org.matrix.autotest.utils; package org.matrix.autotest.utils;
import lombok.AllArgsConstructor; import org.springframework.http.HttpHeaders;
import lombok.Data; import org.springframework.http.HttpStatus;
import lombok.NoArgsConstructor; import org.springframework.http.ResponseEntity;
/** /**
* @author mry * @author mry
*/ */
@Data public class CommonResult {
@AllArgsConstructor
@NoArgsConstructor
public class CommonResult<T> {
/**
* 状态码
*/
private long code;
/**
* 提示信息
*/
private String message;
/**
* 数据封装
*/
private T data;
/** /**
* 成功返回结果 * 成功返回结果
*
* @param data 获取的数据
*/ */
@SuppressWarnings(value = "all") @SuppressWarnings(value = "all")
public static <T> CommonResult<T> success() { public static <T> ResponseEntity<CommonResultObj<T>> success(T data, HttpHeaders headers) {
return new CommonResult<>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), null); return new ResponseEntity(new CommonResultObj(data), headers, HttpStatus.OK);
} }
/** /**
* 失败返回结果 * 成功返回结果
*
* @param data 获取的数据
* @param message 提示信息
*/ */
@SuppressWarnings(value = "all") @SuppressWarnings(value = "all")
public static <T> CommonResult<T> failed() { public static <T> ResponseEntity<CommonResultObj<T>> success(T data, String message) {
return new CommonResult<>(ResultCode.FAILED.getCode(), ResultCode.FAILED.getMessage(), null); return ResponseEntity.ok(new CommonResultObj<>(data, message));
} }
/** /**
...@@ -49,28 +36,26 @@ public class CommonResult<T> { ...@@ -49,28 +36,26 @@ public class CommonResult<T> {
* @param message 提示信息 * @param message 提示信息
*/ */
@SuppressWarnings(value = "all") @SuppressWarnings(value = "all")
public static <T> CommonResult<T> success(String message) { public static <T> ResponseEntity<CommonResultObj<T>> success(String message) {
return new CommonResult<>(ResultCode.SUCCESS.getCode(), message, null); return ResponseEntity.ok(new CommonResultObj<>(null, message));
} }
/** /**
* 失败返回结果 * 成功返回结果
* *
* @param message 提示信息 * @param data
*/ */
@SuppressWarnings(value = "all") @SuppressWarnings(value = "all")
public static <T> CommonResult<T> failed(String message) { public static <T> ResponseEntity<CommonResultObj<T>> success(T data) {
return new CommonResult<>(ResultCode.FAILED.getCode(), message, null); return ResponseEntity.ok(new CommonResultObj<>(data));
} }
/** /**
* 成功返回结果 * 成功返回结果
*
* @param data 获取的数据
*/ */
@SuppressWarnings(value = "all") @SuppressWarnings(value = "all")
public static <T> CommonResult<T> success(T data) { public static <T> ResponseEntity<CommonResultObj<T>> success() {
return new CommonResult<T>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data); return ResponseEntity.ok(new CommonResultObj<>());
} }
/** /**
...@@ -79,30 +64,47 @@ public class CommonResult<T> { ...@@ -79,30 +64,47 @@ public class CommonResult<T> {
* @param data 获取的数据 * @param data 获取的数据
*/ */
@SuppressWarnings(value = "all") @SuppressWarnings(value = "all")
public static <T> CommonResult<T> failed(T data) { public static <T> ResponseEntity<CommonResultObj<T>> failed(T data, HttpHeaders headers) {
return new CommonResult<T>(ResultCode.FAILED.getCode(), ResultCode.FAILED.getMessage(), data); return new ResponseEntity(new CommonResultObj(data), headers, HttpStatus.INTERNAL_SERVER_ERROR);
} }
/** /**
* 成功返回结果 * 失败返回结果
* *
* @param data 获取的数据 * @param data 获取的数据
* @param message 提示信息 * @param message 提示信息
*/ */
@SuppressWarnings(value = "all") @SuppressWarnings(value = "all")
public static <T> CommonResult<T> success(T data, String message) { public static <T> ResponseEntity<CommonResultObj<T>> failed(T data, String message) {
return new CommonResult<T>(ResultCode.SUCCESS.getCode(), message, data); return ResponseEntity.status(500).body(new CommonResultObj<>(data, message));
} }
/** /**
* 失败返回结果 * 失败返回结果
* *
* @param data 获取的数据
* @param message 提示信息 * @param message 提示信息
*/ */
@SuppressWarnings(value = "all") @SuppressWarnings(value = "all")
public static <T> CommonResult<T> failed(T data, String message) { public static <T> ResponseEntity<CommonResultObj<T>> failed(String message) {
return new CommonResult<T>(ResultCode.FAILED.getCode(), message, data); return ResponseEntity.status(500).body(new CommonResultObj<>(null, message));
}
/**
* 失败返回结果
*
* @param data 获取的数据
*/
@SuppressWarnings(value = "all")
public static <T> ResponseEntity<CommonResultObj<T>> failed(T data) {
return ResponseEntity.status(500).body(new CommonResultObj<>(data));
}
/**
* 失败返回结果
*/
@SuppressWarnings(value = "all")
public static <T> ResponseEntity<CommonResultObj<T>> failed() {
return ResponseEntity.status(500).body(new CommonResultObj<>());
} }
} }
package org.matrix.autotest.utils;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author mry
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonPropertyOrder(value = {"message", "data"})
public class CommonResultObj<T> {
private T data;
private String message;
public CommonResultObj(T data) {
this.data = data;
this.message = "no message";
}
}
package org.matrix.autotest.utils;
/**
* @author mry
*/
public enum ResultCode {
/**
* SUCCESS 操作成功
* FAILED 操作失败
*/
SUCCESS(200, "操作成功"),
FAILED(500, "操作失败");
private final long code;
private final String message;
ResultCode(long code, String message) {
this.code = code;
this.message = message;
}
public long getCode() {
return code;
}
public String getMessage() {
return message;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论