ibatIS调用存储过程_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > ibatIS调用存储过程

ibatIS调用存储过程

 2012/2/1 9:27:31  bd2007  程序员俱乐部  我要评论(0)
  • 摘要:<p>一、ibatIS调用存储过程(调用存储过程,统一使用StoredProcedure.xml)<br><br>1.SaleManagerAction代码:<br>/**<br>?*导入单边<br>?*@return<br>?*@author?Invalid<br>?*@throwsException<br>?*@date2011-11-9上午09:46:51<br>
  • 标签:过程 存储过程

    <p>一、ibatIS调用存储过程(调用存储过程,统一使用StoredProcedure.xml)<br><br>
1.SaleManagerAction代码:<br>
/**<br>
?* 导入单边<br>
?* @return<br>
?* @author? Invalid<br>
?* @throws Exception <br>
?* @date 2011-11-9 上午09:46:51<br>
?*/<br>
public String importUnilateralSaleUpload() throws Exception{<br>
??? Map&lt;String,Object&gt; result = new HashMap&lt;String,Object&gt;();<br>
??? String uid = getUserId();<br>
??? if(StringUtils.isEmpty(uid) || qqfile == null){<br>
??? ??? result.put("success", false);<br>
??? ??? result.put("message", "3014");<br>
??? ??? outPrint(JSON.toJSONString(result));<br>
??? ??? return null;<br>
??? }<br>
??? try{<br>
??? ??? Workbook workBook = getWorkbook(new FileInputStream(qqfile));<br>
??? ??? if(workBook!=null){<br>
??? ??? ??? Sheet sheet = workBook.getSheetAt(0);<br>
??? ??? ??? Iterator&lt;Row&gt; it = sheet.iterator();<br>
??? ??? ??? importTotalNum = (sheet.getLastRowNum()+1);<br>
??? ??? ??? List&lt;Map&lt;String,Object&gt;&gt; importList = new ArrayList&lt;Map&lt;String,Object&gt;&gt;();<br>
??? ??? ??? Row row = null;<br>
??? ??? ??? Map&lt;String,Object&gt; temp = null;<br>
??? ??? ??? String date = null;<br>
??? ??? ??? try{<br>
??? ??? ??? ??? while(it.hasNext()){<br>
??? ??? ??? ??? ??? row = it.next();<br>
??? ??? ??? ??? ??? temp = new HashMap&lt;String,Object&gt;();<br>
??? ??? ??? ??? ??? temp.put("employeeId", uid);<br>
??? ??? ??? ??? ??? temp.put("phone", String.format("%.0f", row.getCell(0).getNumericCellValue()));<br>
??? ??? ??? ??? ??? temp.put("money", row.getCell(1).getNumericCellValue());<br>
??? ??? ??? ??? ??? date = row.getCell(2).getStringCellValue();<br>
??? ??? ??? ??? ??? temp.put("refundDate", DateUtils.parseDate(date, DATEFORMAT));<br>
??? ??? ??? ??? ??? importList.add(temp);<br>
??? ??? ??? ??? }<br>
??? ??? ??? }catch(Exception e){<br>
??? ??? ??? ??? result.put("message", "3013");<br>
??? ??? ??? ??? result.put("success", false);<br>
??? ??? ??? ??? log.error("SaleManagerAction importUnilateralSaleUpload:"+uid+","+qqfile.getName(), e);<br>
??? ??? ??? ??? outPrint(JSON.toJSONString(result));<br>
??? ??? ??? ??? return null;<br>
??? ??? ??? }<br>
??? ??? ??? <br>
??? ??? ??? List&lt;Map&lt;String,Object&gt;&gt; importErrorList = new ArrayList&lt;Map&lt;String,Object&gt;&gt;();<br>
??? ??? ??? Map&lt;String,Object&gt; presult = null;<br>
??? ??? ??? String code = null;<br>
??? ??? ??? for( Map&lt;String,Object&gt; saleImport : importList )<br>
??? ??? ??? {<br>
??? ??? ??? ??? presult = saleManager<br>
??? ??? ??? ??? ??? .updateSaleUnilateralStateLoad(<br>
??? ??? ??? ??? ??? ??? ??? (String)saleImport.get("employeeId"), <br>
??? ??? ??? ??? ??? ??? ??? (String)saleImport.get("phone"),<br>
??? ??? ??? ??? ??? ??? ??? (Double)saleImport.get("money"),<br>
??? ??? ??? ??? ??? ??? ??? (Date)saleImport.get("refundDate"));<br>
??? ??? ??? ??? code = (String) presult.get("p_err_code");<br>
??? ??? ??? ??? if( "0".equals(code))//退款成功<br>
??? ??? ??? ??? ??? importSuccess++;<br>
??? ??? ??? ??? if("-11".equals(code))//退款重复<br>
??? ??? ??? ??? ??? importRepeat++;<br>
??? ??? ??? ??? if("-21".equals(code)){//退款失败<br>
??? ??? ??? ??? ??? importError++;<br>
??? ??? ??? ??? ??? importErrorList.add(saleImport);<br>
??? ??? ??? ??? }<br>
??? ??? ??? }<br>
??? ??? ??? result.put("importTotalNum", importTotalNum);<br>
??? ??? ??? result.put("importSuccess", importSuccess);<br>
??? ??? ??? result.put("importRepeat", importRepeat);<br>
??? ??? ??? result.put("importError", importError);<br>
??? ??? ??? result.put("importErrorList", importErrorList);<br>
??? ??? ??? result.put("success", true);<br>
??? ??? }else{<br>
??? ??? ??? result.put("message", "3015");<br>
??? ??? ??? result.put("success", false);<br>
??? ??? }<br>
??? ??? log.info(uid+" Upload UnilateralSale Excel File:"+qqfile.getName()+",State:"+result.get("success"));<br>
??? }catch(Exception e){<br>
??? ??? result.put("success", false);<br>
??? ??? log.error("SaleManagerAction importUnilateralSaleUpload:"+uid+","+qqfile.getName(), e);<br>
??? }<br>
??? outPrint(JSON.toJSONString(result));<br>
??? return null;<br>
}<br>
===============================================================================================================================<br><br>
2.SaleManagerServiceImpl:<br>
@Override<br>
public Map&lt;String, Object&gt; updateSaleUnilateralStateLoad(String employeeId,<br>
??? ??? String phone, Double money, Date refundDate) {<br>
??? Map&lt;String, Object&gt; model = new HashMap&lt;String, Object&gt;();<br>
??? model.put("p_employee_id", employeeId);<br>
??? model.put("p_phone", phone);<br>
??? model.put("p_money", money);<br>
??? model.put("p_refund_date", refundDate);<br>
??? phoneSaleDao.updateSaleUnilateralStateLoad(model);<br>
??? return model;<br>
}<br><br>
3.PhoneSaleDAOImpl:<br>
@Override<br>
public void updateSaleUnilateralStateLoad(Map&lt;String, Object&gt; model) {<br>
??? getSqlMapClientTemplate().queryForObject("StoredProcedure.updateSaleUnilateralStateLoad",model);<br>
}<br><br>
4.StoredProcedure.xml(sqlMap文件):<br>
&lt;?xml version="1.0" encoding="UTF-8" ?&gt;<br>
&lt;!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" &gt;<br><br>
&lt;sqlMap namespace="StoredProcedure"&gt;<br>
??? &lt;!-- updateSaleUnilateralStateMap 更新业务退款状态 --&gt;<br>
??? &lt;parameterMap class="map" id="updateSaleUnilateralStateLoadMap"&gt;<br>
??? ? ??? &lt;parameter property="p_employee_id"??? jdbcType="VARCHAR" ??? javaType="java.lang.String" mode="IN" /&gt;<br>
??? ? ??? &lt;parameter property="p_phone"??? ??? jdbcType="VARCHAR"??? javaType="java.lang.String" mode="IN" /&gt;<br>
??? ? ??? &lt;parameter property="p_money"??? ??? jdbcType="DOUBLE"??? javaType="java.lang.Double" mode="IN" /&gt;<br>
??? ? ??? &lt;parameter property="p_refund_date"??? jdbcType="DATE"??? ??? javaType="java.util.Date" ??? mode="IN" /&gt;<br>
??? ? ??? &lt;parameter property="p_err_code"??? jdbcType="VARCHAR"??? javaType="java.lang.String" mode="OUT" /&gt;<br>
??? ? ??? &lt;parameter property="p_err_info"??? jdbcType="VARCHAR"??? javaType="java.lang.String" mode="OUT" /&gt;<br>
??? &lt;/parameterMap&gt;<br>
??? &lt;procedure id="updateSaleUnilateralStateLoad" parameterMap="updateSaleUnilateralStateLoadMap"&gt;? <br>
??? ??? {CALL SP_PHONE_REFUND_LOAD(?,?,?,?,?,?)}<br>
??? &lt;/procedure&gt;<br>
&lt;/sqlMap&gt;</p>
<p>?</p>
<p>?</p>
<p>?</p>
 
   
     
        <ul>
          <li><a href="http://dl.iteye.com/topics/download/6e4f916d-14b6-33d8-a7a4-1809fbe0388c">ibatIS调用存储过程.zip</a> (13.1 KB)</li>
         
          <li>下载次数: 0</li>
        </ul>
     
   
   
 
发表评论
用户名: 匿名