目录编程客栈
- 解读@SelectProvider的使用
- @Select @SelectP编程rovider中使用foreach时不生效问题
- 问题
- 解决办法
- 总结
解读@SelectProvider的使用
首先在mapper里面写个方法
@SelectProvider(type = SalesOrderProvider.class, method = "selectSalesInformation") List<SalesInformation> selectSalesInformation(@Param("createDateStart") String createDateStart, @Param("编程createDateEnd") String createDateEnd);
然后再在SalesOrderProvider.class这个类里面写方法
public String selectSalesInformation(@Param("createDateStart") String createDateStart, @Param("createDateEnd") String createDateEnd){ StringBuffer sql = new StringBuffer(); sql.append(" SELECT ORDER_STATUS,b.number,b.unit_price,a.CREATE_DATE FROM hl4pl_sales_order a join hl4pl_sales_order_goods b "); sql.append(" where a.ID=b.ID and a.CREATE_DATE BETWEEN #{createDateStart} and #{createDateEnd} "); sql.append(" HAVING ORDER_STATUS =8 or ORDER_STATUS =6 "); return sql.toString(); }
最后就在实现类里面直接调用就好了。
public SalesInformaitonVo getSalesInformation(String createDateStart, String createDateEnd){ List<SalesInformation> salesInformations = salesOrderMapper.selectSalesInformation(createDateStart,createDateEnd); BigDecimal salesVolume = BigDecimal.ZERO;//销售额 BigDecimal totalOrders = BigDecimal.ZERO;//订单总量 int totalSales = salesInformations.size();//销售总量 for (SalesInformation salesInformation : salesInformations) { if (salesInformation.getNumber()!=null&&salesInformation.getUnitPrice()!=null&&salesInformation.getNumber()!=BigDecimal.ZERO&&salesInformation.getUnitPrice()!=BigDecimal.ZERO){ salesVolume =js salesVolume.add(salesInformation.getNumber().multiply(salesInformation.getUnitPrice())); totalOrders = totalOrders.add(salesInformation.getNumber()); } } SalesInformaitonVo salesInformaitonVo = new SalesInformaitonVo(); salesVolume=salesVolume.divide(BigDecimal.valueOf(10000)); BigDecimal bigDecimal = salesVolume.setScale(2, BigDecimal.ROUND_UP);//四舍五入两位小数 salesInformaitonVo.setSalesVolume(bigDecimal); salesInformaitonVo.setTotalOrders(totalOrders); salesInformaitonVo.setTotalSales(totalSales); return salesInformaitonVo; }
@Select @SelectProvider中使用foreach时不生效问题
问题
@Select @SelectProvider中使用<foreach>时不生效。
解决办法
<foreach>、<when>等标签属于XML语法,必须配合<script>标签使用。
@Select({"<script>", "SELECT * FROM tbl_order", "WHERE 1=1", "<when test='title!=null'>", "AND mydate = #{mydate}", "</when>", "</script&gjavascriptt;"}) List<ExpendVo> queryExpend(ExpendDto dto);
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程客栈(www.devze.com)。
精彩评论