代码生成器-数据表获取
This commit is contained in:
parent
e252235655
commit
bad1ebf54c
|
|
@ -0,0 +1,30 @@
|
|||
package com.hxkj.admin.controller;
|
||||
|
||||
import com.hxkj.admin.service.IGenerateService;
|
||||
import com.hxkj.admin.validate.PageParam;
|
||||
import com.hxkj.common.core.AjaxResult;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("api/generate")
|
||||
public class GenerateController {
|
||||
|
||||
@Resource
|
||||
IGenerateService iGenerateService;
|
||||
|
||||
@GetMapping("/db")
|
||||
public Object db(@Validated PageParam pageParam,
|
||||
@RequestParam Map<String, String> params) {
|
||||
List<Map<String, String>> list = iGenerateService.db(pageParam, params);
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.hxkj.admin.service;
|
||||
|
||||
import com.hxkj.admin.validate.PageParam;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 代码生成接口服务类
|
||||
*/
|
||||
public interface IGenerateService {
|
||||
|
||||
List<Map<String, String>> db(PageParam pageParam, Map<String, String> params);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package com.hxkj.admin.service.impl;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.hxkj.admin.service.IGenerateService;
|
||||
import com.hxkj.admin.validate.PageParam;
|
||||
import com.hxkj.common.core.PageResult;
|
||||
import com.hxkj.common.mapper.generate.GenTableMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
public class GenerateServiceImpl implements IGenerateService {
|
||||
|
||||
@Resource
|
||||
GenTableMapper genTableMapper;
|
||||
|
||||
@Override
|
||||
public List<Map<String, String>> db(PageParam pageParam, Map<String, String> params) {
|
||||
Integer page = pageParam.getPageNo();
|
||||
Integer limit = pageParam.getPageSize();
|
||||
|
||||
PageHelper.startPage(page, limit);
|
||||
List<Map<String, String>> tables = genTableMapper.selectDbTableList();
|
||||
|
||||
List<Map<String, String>> list = new LinkedList<>();
|
||||
for (Map<String, String> item : tables) {
|
||||
Map<String, String> map = new LinkedHashMap<>();
|
||||
map.put("tableName", item.get("table_name"));
|
||||
map.put("tableComment", item.get("table_comment"));
|
||||
map.put("createTime", item.get("create_time"));
|
||||
map.put("updateTime", item.getOrDefault("update_time", ""));
|
||||
list.add(map);
|
||||
}
|
||||
System.out.println(PageResult.pageHelper(tables));
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|||
import com.github.pagehelper.PageInfo;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
|
|
@ -24,7 +23,7 @@ public class PageResult<T> {
|
|||
* @return PageList
|
||||
*/
|
||||
public static <T> PageResult<T> pageHelper(List<T> list) {
|
||||
PageResult<T> pageResult = new PageResult<T>();
|
||||
PageResult<T> pageResult = new PageResult<>();
|
||||
PageInfo<T> pageInfo = new PageInfo<>(list);
|
||||
pageResult.setCount(pageInfo.getTotal());
|
||||
pageResult.setPageNo(pageInfo.getPageNum());
|
||||
|
|
@ -41,7 +40,7 @@ public class PageResult<T> {
|
|||
* @return PageList
|
||||
*/
|
||||
public static <T> PageResult<T> iPageHandle(IPage<T> iPage) {
|
||||
PageResult<T> pageResult = new PageResult<T>();
|
||||
PageResult<T> pageResult = new PageResult<>();
|
||||
pageResult.setCount(iPage.getTotal());
|
||||
pageResult.setPageNo((int) iPage.getCurrent());
|
||||
pageResult.setPageSize((int) iPage.getSize());
|
||||
|
|
@ -57,7 +56,7 @@ public class PageResult<T> {
|
|||
* @return PageList
|
||||
*/
|
||||
public static <T> PageResult<T> iPageHandle(Long total, Long pageNo, Long size, List<T> lists) {
|
||||
PageResult<T> pageResult = new PageResult<T>();
|
||||
PageResult<T> pageResult = new PageResult<>();
|
||||
pageResult.setCount(total);
|
||||
pageResult.setPageNo(Math.toIntExact(pageNo));
|
||||
pageResult.setPageSize(Math.toIntExact(size));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
package com.hxkj.common.entity.generate;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 代码生成业务实体
|
||||
*/
|
||||
@Data
|
||||
public class GenTable implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value="id", type= IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package com.hxkj.common.mapper.generate;
|
||||
|
||||
import com.hxkj.common.core.basics.IBaseMapper;
|
||||
import com.hxkj.common.entity.generate.GenTable;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface GenTableMapper extends IBaseMapper<GenTable> {
|
||||
|
||||
@Select(
|
||||
"SELECT table_name, table_comment, create_time, update_time " +
|
||||
"FROM information_schema.tables " +
|
||||
"WHERE table_schema = (SELECT database()) " +
|
||||
"AND table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'gen_%' " +
|
||||
"AND table_name NOT IN (select table_name from ls_gen_table)"
|
||||
)
|
||||
List<Map<String, String>> selectDbTableList();
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue