代码如下: public <T> String updatesqlAndParamList(Vector<String> ve,List<String> paramList,T t,String tabl
代码如下:
public <T> String updatesqlAndParamList(Vector<String> ve,List<String> paramList,T t,String table,List<String> list){ String strSql="";//MQ消息SQl String upSql="";//可执行SQL try { //组装SQL语句 strSql = "update "+table+" set "; upSql="update "+table+" set "; for(int i = 0; i < ve.size(); i++){ String str = ""; String upStr=""; String key = ve.get(i); String fileName="get"+key.toUpperCase(); String value=(String)t.getClass().getMethod(fileName).invoke(t); paramList.add(i,value); if(i == ve.size()-1){ str = key+" = ?"; upStr=key+"='"+value+"'"; }else{ str = key+" = ? ,"; upStr=key+"='"+value+"',"; } strSql+=str; upSql += upStr; } strSql +=" where Id = ? "; upSql+=" where id='"+(String) t.getClass().getMethod("getID").invoke(t)+"'"; list.add(upSql); paramList.add(ve.size(),(String) t.getClass().getMethod("getID").invoke(t)); } catch (Exception e) { logger.info("组装UPDATE SQL失败!失败详情---"+e); } return strSql; }
--结束END--
本文标题: java 动态生成SQL的实例讲解
本文链接: https://lsjlt.com/news/224746.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0