Ibatis问题总结

1、有关parameterMap的使用

例子

sqlmap.xml中的配置(此处用的参数是HashMap类型)如下:

 

xml 代码

 

  1. <select id="selectBySexExceptSelf" parameterMap="forSexParam" resultMap="productResult">  
  2.       
  3.         select    
  4.         id,   
  5.         proname,   
  6.         pronum,   
  7.         proclick,   
  8.         probul,   
  9.         profee,   
  10.         prosex,   
  11.         procontent,   
  12.         procolor,   
  13.         prochic,   
  14.         prochicsm,   
  15.         promot,   
  16.         propic,   
  17.         prochange,   
  18.         proback,   
  19.         prouptime,   
  20.         proispush,   
  21.         proisnew,   
  22.         proison,   
  23.         prophoto,   
  24.         protoptime,   
  25.         proisremove,   
  26.         proremovetime,   
  27.         promodifytime,   
  28.         proisdis,   
  29.         prodisfee,   
  30.         proType   
  31.         from product   
  32.         <dynamic prepend="WHERE">  
  33.             <isParameterPresent prepend="and">  
  34.                 id != #id#   
  35.             isParameterPresent>  
  36.             <isParameterPresent prepend="and">  
  37.                 prosex = #prosex#   
  38.             isParameterPresent>  
  39.         dynamic>  
  40. select>  

         
 

 

 

java调用代码:

java 代码
  1. public List  getProductListBySexExceptSelf(Integer id,String sex) {   
  2.     HashMap hmParam = new HashMap();   
  3.     hmParam.put("id", id);   
  4.     hmParam.put("prosex", sex);   
  5.     return getSqlMapClientTemplate().queryForList(Product.class.getName() + ".selectBySexExceptSelf", hmParam);   
  6. }  

请不要被很多网页中的问号的形式误导,这种写法将直接报错:The error occurred while applying a parameter map. 

  1. <dynamic prepend="WHERE">  
  2.     <isParameterPresent prepend="and">  
  3.         id != ?   
  4.     isParameterPresent>  
  5.     <isParameterPresent prepend="and">  
  6.         prosex = ?   
  7.     isParameterPresent>  
  8. dynamic>  
xml 代码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值