一句sql可以直接获取目标表的字段信息,不用在model内一个一个写出来。
select GROUP_CONCAT(COLUMN_NAME SEPARATOR ‘,bwpd.’) from information_schema.columns WHERE table_name = 'adi_business_weight_price_detail’
表:‘adi_business_weight_price_detail’;
中间间隔:,bwpd. 【注意这里如果不指定,则默认是用 ‘,’ 逗号间隔】
如果只是直接需要字段,用逗号隔开则sql为:select GROUP_CONCAT(COLUMN_NAME) from information_schema.columns WHERE table_name = 'adi_business_weight_price_detail’
取出来的样子差不多为 ‘id,name,age…’ 这种样子
如果是链表,表的别名为 ‘abcd’,出来的字段需要加前缀,需要的字段为 ‘abcd.id, abcd.name, abcd.age…’这种,则修改sql为:select GROUP_CONCAT(COLUMN_NAME SEPARATOR ‘,abcd.’) from information_schema.columns WHERE table_name = 'adi_business_weight_price_detail’
这个技巧的作用:当一个表的字段较多的时候,不用每个都去手打出来,一句sql就拿到了,再删除不需要的sql就行了。