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
mapper:
insert into ${tableName} ${item.cloum} VALUES#{item.val} delete from ${tableName} where id IN #{item} update ${tableName} set where id = #{id} ${item.cloum}=#{item.val}
这里我是使用一个实体类接收字段和字段值进行传参
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; }}
这样就可以了,本人已测试成功!