医药公司网站建设方案,仿韩国网站源码,网站建设讯美,电商网站制作价格mybatis-sql实战总结 动态条件查询怎么List遍历集合进行拼接#xff1f; 动态条件查询 动态条件查询总结 注意点#xff1a; 1.可以用where 11 也可以用 防止出现后面没有条件的情况 2.模糊查询用concat拼接 A.SSTRING10 like concat(#{adAccEntrie.sstring10},‘%’) 3. 对于… mybatis-sql实战总结 动态条件查询怎么List遍历集合进行拼接 动态条件查询 动态条件查询总结 注意点 1.可以用where 11 也可以用 防止出现后面没有条件的情况 2.模糊查询用concat拼接 A.SSTRING10 like concat(#{adAccEntrie.sstring10},‘%’) 3. 对于前端传来的日期参数使用STR_TO_DATE来转为统一的格式 STR_TO_DATE( #{adAccEntrie.date01}, ‘%Y-%m-%d’) 4.对于String类型的字段不但要判断是不是null还要判断是不是空字符串””. 对于集合类型的字段如List不但要判断是不是null还需要判断是不是空的集合用size判断就行。 对于Date类型的字段只需要判断是不是null就行了。 //String类型怎么判断拼接
if testadAccEntrie.sstring08 ! null and adAccEntrie.sstring08 ! AND A.SSTRING08 #{adAccEntrie.sstring08}!--来源系统--
/if
//集合类型字段判断怎么拼接
if testids ! null and ids.size() 0AND ID INforeach collectionids itemid open( close) separator,#{id}/foreach
/if
//Date类型字段判断怎么拼接
if testadAccEntrie.date01 ! null and adAccEntrie.date02 ! nullAND A.DATE01 BETWEEN STR_TO_DATE( #{adAccEntrie.date01}, %Y-%m-%d) AND STR_TO_DATE( #{adAccEntrie.date02}, %Y-%m-%d )!--记账日期--/if5.如果只查一个表 select *就足够了但是如果有多个表select A.*就能查出指定表的所有字段了。 !-- 账户明细查询--select idgetAccEntrieListByParam resultMapAdAccEntrieMapSELECT A.*FROM Ad_Acc_Entrie Awhereif testadAccEntrie.sstring08 ! null and adAccEntrie.sstring08 ! AND A.SSTRING08 #{adAccEntrie.sstring08}!--来源系统--/ifif testadAccEntrie.date01 ! null and adAccEntrie.date02 ! nullAND A.DATE01 BETWEEN STR_TO_DATE( #{adAccEntrie.date01}, %Y-%m-%d) AND STR_TO_DATE( #{adAccEntrie.date02}, %Y-%m-%d )!--记账日期--/ifif testadAccEntrie.sstring01 ! null and adAccEntrie.sstring01 ! AND A.SSTRING01 #{adAccEntrie.sstring01}!--借贷标识--/ifif testadAccEntrie.mstring11 ! null and adAccEntrie.mstring11 ! AND A.MSTRING11 #{adAccEntrie.mstring11}!--管理机构--/ifif testadAccEntrie.sstring10 ! null and adAccEntrie.sstring10 !AND A.SSTRING10 like concat(#{adAccEntrie.sstring10},%)!--业务项目类型--/ifif testadAccEntrie.lstring01 ! null and adAccEntrie.lstring01 !AND A.LSTRING01 like concat(#{adAccEntrie.lstring01},%)!--凭证类别--/ifif testadAccEntrie.mstring07 ! null and adAccEntrie.mstring07 ! AND A.MSTRING07 #{adAccEntrie.mstring07}!--业务号码--/ifif testadAccEntrie.sstring17 ! null and adAccEntrie.sstring17 ! AND A.SSTRING17 #{adAccEntrie.sstring17}!--业务场景编码--/ifif testadAccEntrie.mstring02 ! null and adAccEntrie.mstring02 ! AND A.MSTRING02 #{adAccEntrie.mstring02}!--科目代码--/if/wherelimit #{ph.page},#{ph.rows}/select怎么List遍历集合进行拼接
最终会拼接成 (元素1元素2元素3元素4元素5…,元素n)
if testids ! null and ids.size() 0AND ID INforeach collectionids itemid open( close) separator,#{id}/foreach
/if