博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Mybatis 动态传sql可以查询表名,任意表名,不固定字段的个数返回未定义的类型以及增删改...
阅读量:4307 次
发布时间:2019-06-06

本文共 2049 字,大约阅读时间需要 6 分钟。

mysql查询表名:

SELECT table_name FROM information_schema.tables WHERE table_schema='sell' AND table_type='base table';

查询表中的字段:

SELECT column_name FROM information_schema.columns WHERE table_schema='sell' AND table_name='seller_info'

SpringBoot 中mybatis 使用map的接收返回类型的时候为空的字段 不反回在配置文件中

mybatis.configuration.call-setters-on-nulls=true

今天做项目,遇到的问题就是需求修改数据表的记录,而且字段名都不是固定的,也就是说是需要通过参数传入的,

mybatis动态传表名和字段不规定个数进行条件查询使用map返回

也可以进行动态的表名字段 进行增删改

注意:表名要用${}以为表名不需要预编译

dao层:

List
> getTableInfo(@Param("tableName") String tableName, @Param("cloums") List
cloums); int addTableInfo(@Param("tableName") String tableName, @Param("cloums") List
cloums); int updateTableINfo(@Param("tableName") String tableName, @Param("cloums") List
cloums, @Param("id") String id); int delTableInfo(@Param("tableName") String tableName, @Param("ids") List
id);

 

 mapper:

    
insert into ${tableName}
${item.cloum}
VALUES
#{item.val}
delete from ${tableName} where id IN
#{item}
update ${tableName} set
${item.cloum}=#{item.val}
where id = #{id}

 

  这里我是使用一个实体类接收字段和字段值进行传参

Cloum实体类:
public class Cloum {    private String cloum;    private String val;    public String getCloum() {        return cloum;    }    public void setCloum(String cloum) {        this.cloum = cloum;    }    public String getVal() {        return val;    }    public void setVal(String val) {        this.val = val;    }}

  

 

 这样就可以了,本人已测试成功!

转载于:https://www.cnblogs.com/blackCatFish/p/10957884.html

你可能感兴趣的文章
常浏览的博客和网站
查看>>
Xcode 工程文件打开不出来, cannot be opened because the project file cannot be parsed.
查看>>
iOS在Xcode6中怎么创建OC category文件
查看>>
5、JavaWeb学习之基础篇—标签(自定义&JSTL)
查看>>
8、JavaWEB学习之基础篇—文件上传&下载
查看>>
reRender属性的使用
查看>>
href="javascript:void(0)"
查看>>
h:panelGrid、h:panelGroup标签学习
查看>>
f:facet标签 的用法
查看>>
<h:panelgroup>相当于span元素
查看>>
java中append()的方法
查看>>
必学高级SQL语句
查看>>
经典SQL语句大全
查看>>
log日志记录是什么
查看>>
<rich:modelPanel>标签的使用
查看>>
<h:commandLink>和<h:inputLink>的区别
查看>>
<a4j:keeyAlive>的英文介绍
查看>>
关于list对象的转化问题
查看>>
VOPO对象介绍
查看>>
suse创建的虚拟机,修改ip地址
查看>>