1.Map作为parameterClass
映射文件:
- <!–use
Map type as parameterClass–> -
< select id = “getProduct-Map” parameterClass = “java.util.Map” resultMap = “get-product-result” > -
<![CDATA[ -
select * from t_product -
where prd_id=#id# and prd_description=#description# -
]]> -
</ select >
- <!–use
Map type as parameterClass–> -
<select id=“getProduct-Map” parameterClass=“java.util.Map” resultMap=“get-product-result”> -
<![CDATA[ -
select * from t_product -
where prd_id=#id# and prd_description=#description# -
]]> -
</select>
<!--use Map type as parameterClass--> <select id="getProduct-Map" parameterClass="java.util.Map" resultMap="get-product-result"> <![CDATA[ select * from t_product where prd_id=#id# and prd_description=#description# ]]> </select>
-
-
public Product getProductMap(Map map) throws SQLException { -
init(); -
Product product = (Product)sqlMapClient.queryForObject( “getProduct-Map” , map); -
return product; -
}
-
-
public Product getProductMap(Map map) throws SQLException { -
init(); -
Product product = (Product)sqlMapClient.queryForObject(“getProduct-Map”, map); -
return product; -
}
public Product getProductMap(Map map) throws SQLException { init(); Product product = (Product)sqlMapClient.queryForObject("getProduct-Map", map); return product; }
- public
void getProductMap() throws SQLException{ -
Map map = new HashMap(); -
map.put( “id” , new Integer( 1 )); -
map.put( “description” , “basketball” ); -
Product product = productDao.getProductMap(map); -
System.out.println(product); -
}
- public
void getProductMap() throws SQLException{ -
Map map = new HashMap(); -
map.put(“id”, new Integer(1)); -
map.put(“description”, “basketball”); -
Product product = productDao.getProductMap(map); -
System.out.println(product); -
}
结果:
class java.util.HashMap
{prd_id=1, prd_price=206.99, prd_description=basketball}
class java.util.HashMap
{prd_id=2, prd_price=106.99, prd_description=football}
class java.util.HashMap
{price=206.99, description=basketball, id=1}
class java.util.HashMap
{price=106.99, description=football, id=2}
注意: Map作为resultClass时,必须指定具体的实现类,比如java.util.HashMap,否则会报错
Caused by: java.lang.RuntimeException: JavaBeansDataExchange could not instantiate result class.
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/38290.html