Mybatis传递多个参数
2012-04-13 16:27
295 查看
ibatis3如何传递多个参数有两个方法:一种是使用java.Map,另一种是使用JavaBean。
通过Map传递多个参数
parameterType 可以是别名或完全限定名,map或者java.util.Map,这两个都是可以的
<select id="selectBlogByMap" parameterType="map" resultType="Blog">
select t.ID, t.title, t.content
FROM blog t
where t.title = #{h_title}
and t.content =#{h_content}
</select>
public void testSelectByMap() {
SqlSession session = sqlSessionFactory.openSession();
Map<String, Object> param=new HashMap<String, Object>();
param.put("h_title", "oracle");
param.put("h_content", "使用序列");
Blog blog = (Blog)session.selectOne("cn.enjoylife.BlogMapper.selectBlogByMap",param);
session.close();
System.out.println("blog title:"+blog.getTitle());
}
通过JavaBean传递多个参数
<select id="selectBlogByBean" parameterType="Blog" resultType="Blog">
select t.ID, t.title, t.content
from blog t
wheret.title = #{title}
and t.content =#{content}
</select>
public void testSelectByBean() {
SqlSession session = sqlSessionFactory.openSession();
Blog blog=new Blog();
blog.setTitle("oracle");
blog.setContent("使用序列!");
Blog newBlog = (Blog)session.selectOne("cn.enjoylife.BlogMapper.selectBlogByBean",blog);
session.close();
System.out.println("new Blog ID:"+newBlog.getId());
}
原帖地址:http://kb.cnblogs.com/a/2291110/
通过Map传递多个参数
parameterType 可以是别名或完全限定名,map或者java.util.Map,这两个都是可以的
<select id="selectBlogByMap" parameterType="map" resultType="Blog">
select t.ID, t.title, t.content
FROM blog t
where t.title = #{h_title}
and t.content =#{h_content}
</select>
public void testSelectByMap() {
SqlSession session = sqlSessionFactory.openSession();
Map<String, Object> param=new HashMap<String, Object>();
param.put("h_title", "oracle");
param.put("h_content", "使用序列");
Blog blog = (Blog)session.selectOne("cn.enjoylife.BlogMapper.selectBlogByMap",param);
session.close();
System.out.println("blog title:"+blog.getTitle());
}
通过JavaBean传递多个参数
<select id="selectBlogByBean" parameterType="Blog" resultType="Blog">
select t.ID, t.title, t.content
from blog t
wheret.title = #{title}
and t.content =#{content}
</select>
public void testSelectByBean() {
SqlSession session = sqlSessionFactory.openSession();
Blog blog=new Blog();
blog.setTitle("oracle");
blog.setContent("使用序列!");
Blog newBlog = (Blog)session.selectOne("cn.enjoylife.BlogMapper.selectBlogByBean",blog);
session.close();
System.out.println("new Blog ID:"+newBlog.getId());
}
原帖地址:http://kb.cnblogs.com/a/2291110/
相关文章推荐
- ibatis 和mybatis中 >,<作为参数在ibatis传递时要注意 $值$
- Mybatis中模糊查询时相关的参数传递及xml配置
- mybatis,Dao层传递多个参数报错
- mybatis 传递参数的三种方式
- mybatis多参数传递以及大于等于号的处理
- Mybatis dao传递参数为List时,需要注意的点
- MyBatis(二):Select语句传递参数的集中方案
- MyBatis 传递多个参数
- mybatis多个参数传递
- Mybatis参数传递总结
- 【mybatis】零碎拾起之参数传递
- MyBatis-----MyBatis传递数组参数
- MyBatis多参数传递之Map方式示例
- mybatis中传递普通参数和实体List
- Mybatis参数传递
- springmvc MyBatis 调用Oracle存储过程,使用Map传递参数
- mybatis补充教程之二:传递多个参数的方法(Multiple parameters)
- MYBATIS 的参数传递及XML内使用
- MyBatis传递多个参数的方法
- mybatis直接执行前台传递的sql语句(mapper参数即为sql字符串)