更多ruoyi-nbcio功能请看演示系统
gitee源代码地址
前后端代码: https://gitee.com/nbacheng/ruoyi-nbcio
演示地址:RuoYi-Nbcio后台管理系统
更多nbcio-boot功能请看演示系统
gitee源代码地址
后端代码: https://gitee.com/nbacheng/nbcio-boot
前端代码:https://gitee.com/nbacheng/nbcio-vue.git
在线演示(包括H5) : http://122.227.135.243:9888
为了实现在线表单关联数据库的实现与模拟,先进行一些基本的表单测试。
1、后端使用gen模块里的表与表列方法获取相应信息
列出可以选择的表
java
/**
* 查询代码生成列表
*/
@SaCheckPermission("tool:gen:list")
@GetMapping("/list")
public TableDataInfo<GenTable> genList(GenTable genTable, PageQuery pageQuery) {
return genTableService.selectPageGenTableList(genTable, pageQuery);
}
@Override
public TableDataInfo<GenTable> selectPageGenTableList(GenTable genTable, PageQuery pageQuery) {
Page<GenTable> page = baseMapper.selectPage(pageQuery.build(), this.buildGenTableQueryWrapper(genTable));
return TableDataInfo.build(page);
}
private QueryWrapper<GenTable> buildGenTableQueryWrapper(GenTable genTable) {
Map<String, Object> params = genTable.getParams();
QueryWrapper<GenTable> wrapper = Wrappers.query();
wrapper.like(StringUtils.isNotBlank(genTable.getTableName()), "lower(table_name)", StringUtils.lowerCase(genTable.getTableName()))
.like(StringUtils.isNotBlank(genTable.getTableComment()), "lower(table_comment)", StringUtils.lowerCase(genTable.getTableComment()))
.between(params.get("beginTime") != null && params.get("endTime") != null,
"create_time", params.get("beginTime"), params.get("endTime"));
return wrapper;
}
列出可以选择的列名
java
/**
* 查询数据表字段列表
*
* @param tableName 表名
*/
@SaCheckPermission("tool:gen:list")
@GetMapping(value = "/columnByName/{tableName}")
public TableDataInfo<GenTableColumn> columnListByTableName(@PathVariable(value = "tableName") String tableName) {
TableDataInfo<GenTableColumn> dataInfo = new TableDataInfo<>();
List<GenTableColumn> list = genTableService.selectGenTableColumnListByTableName(tableName);
dataInfo.setRows(list);
dataInfo.setTotal(list.size());
return dataInfo;
}
@Override
public List<GenTableColumn> selectGenTableColumnListByTableName(String tableName) {
GenTable table = baseMapper.selectGenTableByName(tableName);
if(ObjectUtils.isNotEmpty(table) ) {
long tableId = table.getTableId();
return genTableColumnMapper.selectList(new LambdaQueryWrapper<GenTableColumn>()
.eq(GenTableColumn::getTableId, tableId)
.orderByAsc(GenTableColumn::getSort));
}
return null;
}
根据表名动态获取数据
java
/**
* 根据主表名动态获取表数据
* @param tableName 主表名称
*/
@SaCheckPermission("workflow:form:query")
@GetMapping(value = "/getData/{tableName}")
public R<List<Map>> getData(@NotNull(message = "表名不能为空") @PathVariable("tableName") String tableName) {
return R.ok(formService.getDataByTableName(tableName));
}
@Override
public List<Map> getDataByTableName(@NotNull(message = "表名不能为空") String tableName) {
return baseMapper.getDataByTableName(tableName);
}
public interface WfFormMapper extends BaseMapperPlus<WfFormMapper, WfForm, WfFormVo> {
List<WfFormVo> selectFormVoList(@Param(Constants.WRAPPER) Wrapper<WfForm> queryWrapper);
@Select("SELECT * FROM ${tableName}")
List<Map> getDataByTableName(@Param("tableName") String tableName);
}