Mybatis传递多个参数
2015-11-25 14:35
141 查看
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/
相关文章推荐
- UISegmentedControl用法详解
- Java注解
- 语音编码算法
- Mysql 学习笔记之索引篇
- 使用android:process的注意事项
- IOS Runtime(三)
- javascript实现很浪漫的气泡冒出特效
- 天生人语
- RTP/RTCP/SRTP语音传输技术
- 移动端开发 干货知识分享
- Javascript异步编程的4种方法
- Eclipse快捷键 10个最有用的快捷键
- BZOJ2535: [Noi2010]Plane 航空管制2
- C#定制Excel界面并实现与数据库交互的方法
- IOS Runtime(二)
- linux网卡配置
- struts2 错误总结 自己会不断更新中。。。。。
- 精彩作图
- Python之自动化打包脚本(针对server设备)
- 每日_VS Assembly resolve 程序自定义加载Dll文件