Mapper.java
IPage
Mapper.xml
select ${columns}from ${tableName} dy
使用场景:
我们必须知道查询的表名,可以通过表名查询字段及注释,然后把表名和字段传进mapper
如果知道具体查询哪些表,可以把这些表及表对应的字段配置进一张表和字段对应的表中,通过表名查询该表取出对应的字段及注释,此处的字段注释可以自己写相对比较灵活。
DROP TABLE IF EXISTS `table_colume_mapping`;CREATE TABLE `table_colume_mapping` ( `table_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '表名', `column_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '字段名', `column_comment` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '字段汉语名', `table_comment` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '表名注释', `sort` int(10) NULL DEFAULT NULL COMMENT '字段排序', `show_column` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '是' COMMENT '是否展示在列', `del_flag` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '0' COMMENT '0存在1删除') ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '表字段注释映射' ROW_FORMAT = Dynamic;SET FOREIGN_KEY_CHECKS = 1;
调用
LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>();wrapper.eq(TableColumeMapping::getTableName, "查询的表名");List list = SpringContextHolder.getBean(TableColumeMapping.class).list(wrapper);Map tableColumeMap = list.stream().collect(Collectors.toMap(TableColumMapperPerson::getColumnName, account -> account));String columnNames = list.stream().map(item -> "dy."+item.getColumnName()).collect(Collectors.joining(","));IPage
来源地址:https://blog.csdn.net/qq_37931185/article/details/130066498