Mybatis传递多个参数
2016-04-16 09:17
399 查看
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());
}
通过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());
}
相关文章推荐
- phpstorm
- 山东省第四届ACM大学生程序设计竞赛 The number of steps 概率dp
- 在字符串中有序插入一个新字符
- 刘烨:家里官方语言是中文 听不懂娘仨说法语
- 神奇的位运算
- Metal 着色语言编程指南 四
- maven安装最佳实践
- 复选框默认勾选
- 练习二1010
- Java 下的 JSON库性能比较:JSON.simple vs. GSON vs. Jackson vs. JSONP
- EasyPusher安卓Android手机直播推送之RTSP流媒体协议流程
- 练习二1010
- EasyPusher安卓Android手机直播推送之RTSP流媒体协议流程
- vc++怎么可以直接刷掉MBR?搞笑的吧
- 对话人工智能专家-吴恩达等人 重要总结
- vc++怎么可以直接刷掉MBR?搞笑的吧
- vc++怎么可以直接刷掉MBR?搞笑的吧
- mysql 远程连接配置
- mysql 远程连接配置
- vc++怎么可以直接刷掉MBR?搞笑的吧