NHMicro 1.2.9 發布,支持 Service 層的 SQL 替換

←手機掃碼閱讀     admin @ 2019-05-15 , reply:0

NHMicro 1.2.9 發布,此版本支持在service層做sql模板替換后的增刪改查操作

MicroServiceTemplateSupport類中添加方法

public Map getInfoList4PageServiceByRep(String countSql,String sql, Map paramMap, Map pageMap)

public Integer updateInfoServiceByRep(String sql,Map paramMap)

public List getInfoListAllServiceByReq(String sql,Map paramMap)

public Map getSingleInfoServiceByRep(String sql,Map requestParamMap)

這些方法執行sql支持參數替換

替換的語法是使用velocity語法

例如:

判斷是否為null #if(${param.p1})

判斷是否為"" #if(${param.p1}!='')

判斷不為null且不為"" #if($!{param.p1}!='')

#sqlreplace是MicroServiceTemplate中的特殊標記,用來做?佔位符替換,類似mybatis中的#替換符。使用#sqlreplace時會在返回的placeList中追加參數值。

例如以下的代碼:

Map paramMap=new HashMap();

        paramMap.put("p1", "1");

        paramMap.put("p2", "2");

        paramMap.put("p3", "3");

        paramMap.put("p4", "4");

        paramMap.put("p5", "5");

        String sql=

            "select * from aaa where 1=1"+

                "#if(\${param.p1})"+

                    " and c1='\${param.p2}'   "+

                "#end"+

                "#if(\${param.p2})"+

                    " and c2= #sqlreplace(\${param.p2}) "+

                "#end"+

                "#if(\${param.p3})"+

                    " and c3 like '%\${param.p3}%' "+

                "#end"

                ;

getInfoListAllServiceByReq(sql, paramMap);

返回如下的sql替換結果

實際getInfoListAllServiceByReq方法內部執行的sql是:

select * from aaa where 1=1and c1=1  and c2=?  and c3 like '%3%'
 





[admin ]

來源:OsChina
連結:https://www.oschina.net/news/106684/nhmicro-1-2-9-released
NHMicro 1.2.9 發布,支持 Service 層的 SQL 替換已經有36次圍觀

http://coctec.com/news/all/show-post-205347.html