From 8d90b658da3c9ec878ccfb0e326a3bd0f427c1ef Mon Sep 17 00:00:00 2001
From: wuy <1311695042@qq.com>
Date: Wed, 9 Oct 2019 23:38:57 +0800
Subject: [PATCH] =?UTF-8?q?*=20=E4=BF=AE=E6=94=B9=E7=BB=91=E5=AE=9A?=
=?UTF-8?q?=E5=88=97=E5=90=8D=E9=80=BB=E8=BE=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../com/diboot/core/binding/QueryBuilder.java | 15 +++--
diboot-example/build.gradle | 2 +-
.../example/config/MybatisPlusConfig.java | 2 +-
.../controller/DictionaryController.java | 59 +++++++++++--------
.../service/impl/DictionaryServiceImpl.java | 2 +-
5 files changed, 49 insertions(+), 31 deletions(-)
diff --git a/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java b/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java
index 502e35d..202215e 100644
--- a/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java
+++ b/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java
@@ -160,15 +160,22 @@ public class QueryBuilder {
/**
* 获取数据表的列名(驼峰转下划线蛇形命名)
+ *
+ * 列名取值优先级: @BindQuery.field > @TableField.value > field.name
+ *
* @param field
* @return
*/
private static String getColumnName(Field field){
- BindQuery annotation = field.getAnnotation(BindQuery.class);
- if (annotation != null && V.notEmpty(annotation.field())){
- return annotation.field();
+ String columnName = "";
+ if (field.isAnnotationPresent(BindQuery.class)) {
+ columnName = field.getAnnotation(BindQuery.class).field();
}
- return S.toSnakeCase(field.getName());
+ if (field.isAnnotationPresent(TableField.class)) {
+ columnName = field.getAnnotation(TableField.class).value();
+ }
+ return V.notEmpty(columnName) ? columnName : S.toSnakeCase(field.getName());
}
+
}
\ No newline at end of file
diff --git a/diboot-example/build.gradle b/diboot-example/build.gradle
index ad1fd18..8fc2abc 100644
--- a/diboot-example/build.gradle
+++ b/diboot-example/build.gradle
@@ -1,7 +1,7 @@
apply plugin: 'org.springframework.boot'
dependencies {
-
+// compile("com.diboot:diboot-shiro:2.0.1")
compile project(":diboot-shiro-wx-mp")
compile project(":diboot-shiro-wx-cp")
compile project(":diboot-components-msg")
diff --git a/diboot-example/src/main/java/com/diboot/example/config/MybatisPlusConfig.java b/diboot-example/src/main/java/com/diboot/example/config/MybatisPlusConfig.java
index 8a13383..221f284 100644
--- a/diboot-example/src/main/java/com/diboot/example/config/MybatisPlusConfig.java
+++ b/diboot-example/src/main/java/com/diboot/example/config/MybatisPlusConfig.java
@@ -2,7 +2,7 @@ package com.diboot.example.config;
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
-import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector;
+//import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
diff --git a/diboot-example/src/main/java/com/diboot/example/controller/DictionaryController.java b/diboot-example/src/main/java/com/diboot/example/controller/DictionaryController.java
index 540f351..8ef5b20 100644
--- a/diboot-example/src/main/java/com/diboot/example/controller/DictionaryController.java
+++ b/diboot-example/src/main/java/com/diboot/example/controller/DictionaryController.java
@@ -24,6 +24,11 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
+/**
+ * 数据字典类
+ *
+ * @author wee
+ */
@RestController
@RequestMapping("/dictionary")
@AuthorizationPrefix(name = "数据字典", code = "dictionary", prefix = "dictionary")
@@ -38,18 +43,24 @@ public class DictionaryController extends BaseCrudRestController {
return dictionaryService;
}
- /*
- * 获取列表页数据
- * */
+ /**
+ * 获取列表页数据
+ *
+ * @param dictionary
+ * @param pagination
+ * @param request
+ * @return
+ * @throws Exception
+ */
@GetMapping("/list")
@AuthorizationWrapper(value = @RequiresPermissions("list"), name = "列表")
public JsonResult list(Dictionary dictionary, Pagination pagination, HttpServletRequest request) throws Exception {
//构建查询条件
QueryWrapper queryWrapper = super.buildQueryWrapper(dictionary);
queryWrapper.lambda().eq(Dictionary::getParentId, 0)
- .orderByAsc(Dictionary::getSortId);
+ .orderByAsc(Dictionary::getSortId);
//获取实体list
- List dictionaryList = dictionaryService.getEntityList(queryWrapper, pagination);
+ List dictionaryList = dictionaryService.getEntityList(queryWrapper, pagination);
//筛选出在列表页展示的字段
List dicVoList = RelationsBinder.convertAndBind(dictionaryList, DictionaryListVO.class);
//返回结果
@@ -61,21 +72,21 @@ public class DictionaryController extends BaseCrudRestController {
* */
@GetMapping("/{id}")
@AuthorizationWrapper(value = @RequiresPermissions("read"), name = "读取")
- public JsonResult getEntity(@PathVariable("id") Long id, HttpServletRequest request){
+ public JsonResult getEntity(@PathVariable("id") Long id, HttpServletRequest request) {
DictionaryVO vo = dictionaryService.getViewObject(id, DictionaryVO.class);
return new JsonResult(vo);
}
/*
- * 新建
- * */
+ * 新建
+ * */
@PostMapping("/")
@AuthorizationWrapper(value = @RequiresPermissions("create"), name = "新建")
- public JsonResult create(@RequestBody DictionaryVO entityVO, HttpServletRequest request){
- boolean success = dictionaryService.createDictionary(entityVO);
- if(success){
+ public JsonResult create(@RequestBody DictionaryVO entityVO, HttpServletRequest request) {
+ boolean success = dictionaryService.createDictionary(entityVO);
+ if (success) {
return new JsonResult(Status.OK);
- }else{
+ } else {
return new JsonResult(Status.FAIL_OPERATION);
}
}
@@ -85,12 +96,12 @@ public class DictionaryController extends BaseCrudRestController {
* */
@PutMapping("/{id}")
@AuthorizationWrapper(value = @RequiresPermissions("update"), name = "更新")
- public JsonResult update(@PathVariable("id")Long id, @RequestBody DictionaryVO entityVO, HttpServletRequest request){
+ public JsonResult update(@PathVariable("id") Long id, @RequestBody DictionaryVO entityVO, HttpServletRequest request) {
entityVO.setId(id);
boolean success = dictionaryService.updateDictionary(entityVO);
- if(success){
+ if (success) {
return new JsonResult(Status.OK);
- }else{
+ } else {
return new JsonResult(Status.FAIL_OPERATION);
}
}
@@ -100,12 +111,12 @@ public class DictionaryController extends BaseCrudRestController {
* */
@DeleteMapping("/{id}")
@AuthorizationWrapper(value = @RequiresPermissions("delete"), name = "删除")
- public JsonResult delete(@PathVariable("id") Long id){
+ public JsonResult delete(@PathVariable("id") Long id) {
boolean success = dictionaryService.deleteDictionary(id);
- if(success){
+ if (success) {
return new JsonResult(Status.OK);
- }else{
- return new JsonResult(Status.FAIL_OPERATION );
+ } else {
+ return new JsonResult(Status.FAIL_OPERATION);
}
}
@@ -113,16 +124,16 @@ public class DictionaryController extends BaseCrudRestController {
* 校验类型编码是否重复
* */
@GetMapping("/checkTypeRepeat")
- public JsonResult checkTypeRepeat(@RequestParam(required = false) Long id,@RequestParam String type, HttpServletRequest request){
- if(V.notEmpty(type)){
+ public JsonResult checkTypeRepeat(@RequestParam(required = false) Long id, @RequestParam String type, HttpServletRequest request) {
+ if (V.notEmpty(type)) {
LambdaQueryWrapper wrapper = new LambdaQueryWrapper();
wrapper.eq(Dictionary::getType, type)
- .eq(Dictionary::getParentId, 0);
- if(V.notEmpty(id)){
+ .eq(Dictionary::getParentId, 0);
+ if (V.notEmpty(id)) {
wrapper.ne(Dictionary::getId, id);
}
List dictionaryList = dictionaryService.getEntityList(wrapper);
- if(V.isEmpty(dictionaryList)){
+ if (V.isEmpty(dictionaryList)) {
return new JsonResult(Status.OK);
}
return new JsonResult(Status.FAIL_OPERATION, "类型编码已存在");
diff --git a/diboot-example/src/main/java/com/diboot/example/service/impl/DictionaryServiceImpl.java b/diboot-example/src/main/java/com/diboot/example/service/impl/DictionaryServiceImpl.java
index 572f9a0..f2f33d2 100644
--- a/diboot-example/src/main/java/com/diboot/example/service/impl/DictionaryServiceImpl.java
+++ b/diboot-example/src/main/java/com/diboot/example/service/impl/DictionaryServiceImpl.java
@@ -22,7 +22,7 @@ import java.util.List;
* @version v2.0
* @date 2019/7/8
*/
-@Service("dictionaryService")
+@Service("exampleDictionaryService")
@Slf4j
public class DictionaryServiceImpl extends BaseServiceImpl implements DictionaryService {
private static final Logger logger = LoggerFactory.getLogger(DictionaryServiceImpl.class);