一、后台数据库操作方法(private端):
1.以下为后台查询方法
BaseDAO dao = new BaseDAO();//只能在private端使用
String querySql="select * from demo_quotation where dr = 0";//完整正确的sql语句
Object result1 = dao.executeQuery("select vbillcode from demo_quotation where pk_salequotation='某个主键'", new ColumnProcessor());//查询语句只能返回一行一列结果
List<Object[]> result2 = (List<Object[]>) dao.executeQuery(querySql, new ArrayListProcessor());//查询语句可以返回多行多列
//for(Object[] obj : result2){ obj[0]...obj[n]}
Map<String, Object> result3 = (Map<String, Object>) dao.executeQuery("select * from demo_quotation where pk_salequotation='某个主键'", new MapProcessor());//查询语句只返回一行结果
List<Map<String,String>> result4 = (List<Map<String, String>>) dao.executeQuery(querySql, new MapListProcessor());//查询语句可以返回多行结果
//for(Map<String,String> map : result4){map.get("字段名")}
QuotationHVO result5 = (QuotationHVO) dao.executeQuery("select * from
demo_quotation where pk_salequotation='某个主键'", new BeanProcessor(QuotationHVO.class));//查询语句只返回一个VO
List<QuotationHVO> result6 = (List<QuotationHVO>) dao.executeQuery(querySql,new BeanListProcessor(QuotationHVO.class));//查询语句返回多个VO
Set<String> result =
(Set<String>) dao.executeQuery(sql, new BaseProcessor() {
private static final long serialVersionUID = 1L;
@Override
public Object processResultSet(ResultSet rs) throws SQLException {
Set<String> result = new HashSet<String>();
String cproductid = null;
while (rs.next()) {
cproductid = rs.getString("cproductid");
result.add(cproductid);
}
return result;
}
});
return result;
}
2.以下为新增更新删除方法(手写sql)
dao.executeUpdate("sql");
二、前台数据库操作方法(client端):
IUAPQueryBS bs = NCLocator.getInstance().lookup(IUAPQueryBS.class);
bs.executeQuery(sql, processor);//processor跟第一点的basedao用法一致
三、
//后台通过主表主键查询aggvo
BillQuery<AggPromoPolicyVO> query = new BillQuery<>(AggPromoPolicyVO.class);
query .query(keys);
//前台通过主表主键查询aggvo
HYPubBO_Client.queryBillVOByPrimaryKey(class, hids)
//或者前后台都能用
IBillQueryService billQuery = NCLocator.getInstance().lookup(IBillQueryService.class);
以下例子可以防SQL注入(前后台都有个SQLParameter 参数能使用)
StringBuilder sql = new StringBuilder();
sql.append("select * from esoc_dispatchrecgoods ")
.append(" where dispatchnoteid=?").append(" and dr=?");
SQLParameter param = new SQLParameter();
param.addParam(pk_dispatchnoteid);
param.addParam(0);
List<DispatchRecGoodsVO> drgvoList = (List<DispatchRecGoodsVO>) dao
.executeQuery(sql.toString(), param, new BeanListProcessor(
DispatchRecGoodsVO.class))
前台提供两个主要接口进行CURD操作:
IVOPersistence 该接口只支持前台增删改操作
IUAPQueryBS 该接口主要支持前台的查询操作
有了这两个接口,就省去了写后台接口的步骤,但是具体的操作还是要视情况而定。