* 修改绑定列名逻辑
This commit is contained in:
parent
743f459c18
commit
8d90b658da
|
@ -160,15 +160,22 @@ public class QueryBuilder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取数据表的列名(驼峰转下划线蛇形命名)
|
* 获取数据表的列名(驼峰转下划线蛇形命名)
|
||||||
|
* <br>
|
||||||
|
* 列名取值优先级: @BindQuery.field > @TableField.value > field.name
|
||||||
|
*
|
||||||
* @param field
|
* @param field
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private static String getColumnName(Field field){
|
private static String getColumnName(Field field){
|
||||||
BindQuery annotation = field.getAnnotation(BindQuery.class);
|
String columnName = "";
|
||||||
if (annotation != null && V.notEmpty(annotation.field())){
|
if (field.isAnnotationPresent(BindQuery.class)) {
|
||||||
return annotation.field();
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
apply plugin: 'org.springframework.boot'
|
apply plugin: 'org.springframework.boot'
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
// compile("com.diboot:diboot-shiro:2.0.1")
|
||||||
compile project(":diboot-shiro-wx-mp")
|
compile project(":diboot-shiro-wx-mp")
|
||||||
compile project(":diboot-shiro-wx-cp")
|
compile project(":diboot-shiro-wx-cp")
|
||||||
compile project(":diboot-components-msg")
|
compile project(":diboot-components-msg")
|
||||||
|
|
|
@ -2,7 +2,7 @@ package com.diboot.example.config;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
|
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
|
||||||
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
|
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 com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
|
||||||
import org.mybatis.spring.annotation.MapperScan;
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
|
@ -24,6 +24,11 @@ import org.springframework.web.bind.annotation.*;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据字典类
|
||||||
|
*
|
||||||
|
* @author wee
|
||||||
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/dictionary")
|
@RequestMapping("/dictionary")
|
||||||
@AuthorizationPrefix(name = "数据字典", code = "dictionary", prefix = "dictionary")
|
@AuthorizationPrefix(name = "数据字典", code = "dictionary", prefix = "dictionary")
|
||||||
|
@ -38,18 +43,24 @@ public class DictionaryController extends BaseCrudRestController {
|
||||||
return dictionaryService;
|
return dictionaryService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* 获取列表页数据
|
* 获取列表页数据
|
||||||
* */
|
*
|
||||||
|
* @param dictionary
|
||||||
|
* @param pagination
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
@AuthorizationWrapper(value = @RequiresPermissions("list"), name = "列表")
|
@AuthorizationWrapper(value = @RequiresPermissions("list"), name = "列表")
|
||||||
public JsonResult list(Dictionary dictionary, Pagination pagination, HttpServletRequest request) throws Exception {
|
public JsonResult list(Dictionary dictionary, Pagination pagination, HttpServletRequest request) throws Exception {
|
||||||
//构建查询条件
|
//构建查询条件
|
||||||
QueryWrapper<Dictionary> queryWrapper = super.buildQueryWrapper(dictionary);
|
QueryWrapper<Dictionary> queryWrapper = super.buildQueryWrapper(dictionary);
|
||||||
queryWrapper.lambda().eq(Dictionary::getParentId, 0)
|
queryWrapper.lambda().eq(Dictionary::getParentId, 0)
|
||||||
.orderByAsc(Dictionary::getSortId);
|
.orderByAsc(Dictionary::getSortId);
|
||||||
//获取实体list
|
//获取实体list
|
||||||
List<Dictionary> dictionaryList = dictionaryService.getEntityList(queryWrapper, pagination);
|
List<Dictionary> dictionaryList = dictionaryService.getEntityList(queryWrapper, pagination);
|
||||||
//筛选出在列表页展示的字段
|
//筛选出在列表页展示的字段
|
||||||
List<DictionaryListVO> dicVoList = RelationsBinder.convertAndBind(dictionaryList, DictionaryListVO.class);
|
List<DictionaryListVO> dicVoList = RelationsBinder.convertAndBind(dictionaryList, DictionaryListVO.class);
|
||||||
//返回结果
|
//返回结果
|
||||||
|
@ -61,21 +72,21 @@ public class DictionaryController extends BaseCrudRestController {
|
||||||
* */
|
* */
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
@AuthorizationWrapper(value = @RequiresPermissions("read"), name = "读取")
|
@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);
|
DictionaryVO vo = dictionaryService.getViewObject(id, DictionaryVO.class);
|
||||||
return new JsonResult(vo);
|
return new JsonResult(vo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 新建
|
* 新建
|
||||||
* */
|
* */
|
||||||
@PostMapping("/")
|
@PostMapping("/")
|
||||||
@AuthorizationWrapper(value = @RequiresPermissions("create"), name = "新建")
|
@AuthorizationWrapper(value = @RequiresPermissions("create"), name = "新建")
|
||||||
public JsonResult create(@RequestBody DictionaryVO entityVO, HttpServletRequest request){
|
public JsonResult create(@RequestBody DictionaryVO entityVO, HttpServletRequest request) {
|
||||||
boolean success = dictionaryService.createDictionary(entityVO);
|
boolean success = dictionaryService.createDictionary(entityVO);
|
||||||
if(success){
|
if (success) {
|
||||||
return new JsonResult(Status.OK);
|
return new JsonResult(Status.OK);
|
||||||
}else{
|
} else {
|
||||||
return new JsonResult(Status.FAIL_OPERATION);
|
return new JsonResult(Status.FAIL_OPERATION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,12 +96,12 @@ public class DictionaryController extends BaseCrudRestController {
|
||||||
* */
|
* */
|
||||||
@PutMapping("/{id}")
|
@PutMapping("/{id}")
|
||||||
@AuthorizationWrapper(value = @RequiresPermissions("update"), name = "更新")
|
@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);
|
entityVO.setId(id);
|
||||||
boolean success = dictionaryService.updateDictionary(entityVO);
|
boolean success = dictionaryService.updateDictionary(entityVO);
|
||||||
if(success){
|
if (success) {
|
||||||
return new JsonResult(Status.OK);
|
return new JsonResult(Status.OK);
|
||||||
}else{
|
} else {
|
||||||
return new JsonResult(Status.FAIL_OPERATION);
|
return new JsonResult(Status.FAIL_OPERATION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,12 +111,12 @@ public class DictionaryController extends BaseCrudRestController {
|
||||||
* */
|
* */
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
@AuthorizationWrapper(value = @RequiresPermissions("delete"), name = "删除")
|
@AuthorizationWrapper(value = @RequiresPermissions("delete"), name = "删除")
|
||||||
public JsonResult delete(@PathVariable("id") Long id){
|
public JsonResult delete(@PathVariable("id") Long id) {
|
||||||
boolean success = dictionaryService.deleteDictionary(id);
|
boolean success = dictionaryService.deleteDictionary(id);
|
||||||
if(success){
|
if (success) {
|
||||||
return new JsonResult(Status.OK);
|
return new JsonResult(Status.OK);
|
||||||
}else{
|
} else {
|
||||||
return new JsonResult(Status.FAIL_OPERATION );
|
return new JsonResult(Status.FAIL_OPERATION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,16 +124,16 @@ public class DictionaryController extends BaseCrudRestController {
|
||||||
* 校验类型编码是否重复
|
* 校验类型编码是否重复
|
||||||
* */
|
* */
|
||||||
@GetMapping("/checkTypeRepeat")
|
@GetMapping("/checkTypeRepeat")
|
||||||
public JsonResult checkTypeRepeat(@RequestParam(required = false) Long id,@RequestParam String type, HttpServletRequest request){
|
public JsonResult checkTypeRepeat(@RequestParam(required = false) Long id, @RequestParam String type, HttpServletRequest request) {
|
||||||
if(V.notEmpty(type)){
|
if (V.notEmpty(type)) {
|
||||||
LambdaQueryWrapper<Dictionary> wrapper = new LambdaQueryWrapper();
|
LambdaQueryWrapper<Dictionary> wrapper = new LambdaQueryWrapper();
|
||||||
wrapper.eq(Dictionary::getType, type)
|
wrapper.eq(Dictionary::getType, type)
|
||||||
.eq(Dictionary::getParentId, 0);
|
.eq(Dictionary::getParentId, 0);
|
||||||
if(V.notEmpty(id)){
|
if (V.notEmpty(id)) {
|
||||||
wrapper.ne(Dictionary::getId, id);
|
wrapper.ne(Dictionary::getId, id);
|
||||||
}
|
}
|
||||||
List<Dictionary> dictionaryList = dictionaryService.getEntityList(wrapper);
|
List<Dictionary> dictionaryList = dictionaryService.getEntityList(wrapper);
|
||||||
if(V.isEmpty(dictionaryList)){
|
if (V.isEmpty(dictionaryList)) {
|
||||||
return new JsonResult(Status.OK);
|
return new JsonResult(Status.OK);
|
||||||
}
|
}
|
||||||
return new JsonResult(Status.FAIL_OPERATION, "类型编码已存在");
|
return new JsonResult(Status.FAIL_OPERATION, "类型编码已存在");
|
||||||
|
|
|
@ -22,7 +22,7 @@ import java.util.List;
|
||||||
* @version v2.0
|
* @version v2.0
|
||||||
* @date 2019/7/8
|
* @date 2019/7/8
|
||||||
*/
|
*/
|
||||||
@Service("dictionaryService")
|
@Service("exampleDictionaryService")
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class DictionaryServiceImpl extends BaseServiceImpl<DictionaryMapper, Dictionary> implements DictionaryService {
|
public class DictionaryServiceImpl extends BaseServiceImpl<DictionaryMapper, Dictionary> implements DictionaryService {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(DictionaryServiceImpl.class);
|
private static final Logger logger = LoggerFactory.getLogger(DictionaryServiceImpl.class);
|
||||||
|
|
Loading…
Reference in New Issue