* 修改绑定列名逻辑

This commit is contained in:
wuy 2019-10-09 23:38:57 +08:00
parent 743f459c18
commit 8d90b658da
5 changed files with 49 additions and 31 deletions

View File

@ -160,15 +160,22 @@ public class QueryBuilder {
/**
* 获取数据表的列名驼峰转下划线蛇形命名
* <br>
* 列名取值优先级 @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());
}
}

View File

@ -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")

View File

@ -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;

View File

@ -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<Dictionary> queryWrapper = super.buildQueryWrapper(dictionary);
queryWrapper.lambda().eq(Dictionary::getParentId, 0)
.orderByAsc(Dictionary::getSortId);
.orderByAsc(Dictionary::getSortId);
//获取实体list
List<Dictionary> dictionaryList = dictionaryService.getEntityList(queryWrapper, pagination);
List<Dictionary> dictionaryList = dictionaryService.getEntityList(queryWrapper, pagination);
//筛选出在列表页展示的字段
List<DictionaryListVO> 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<Dictionary> 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<Dictionary> dictionaryList = dictionaryService.getEntityList(wrapper);
if(V.isEmpty(dictionaryList)){
if (V.isEmpty(dictionaryList)) {
return new JsonResult(Status.OK);
}
return new JsonResult(Status.FAIL_OPERATION, "类型编码已存在");

View File

@ -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<DictionaryMapper, Dictionary> implements DictionaryService {
private static final Logger logger = LoggerFactory.getLogger(DictionaryServiceImpl.class);