Mybatis传递多个参数
2011-12-17 15:23
316 查看
ibatis3如何传递多个参数有两个方法:一种是使用Map,另一种是使用JavaBean。
<!-- 使用HashMap传递多个参数 parameterType 可以是别名或完全限定名 ,map->java.util.Map,这两个都是可以的 --> <selectid="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> <!-- 使用JavaBean传递多个参数 --> <selectid="selectBlogByBean"parameterType="Blog"resultType="Blog"> SELECT t.ID, t.title, t.content FROM blog t WHERE t.title = #{title} AND t.content =#{content} </select>
/** * 通过Map传递多个参数 */ @Test 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传递多个参数 */ @Test 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()); }
相关文章推荐
- mybatis 传递多个参数
- mybatis向sql语句中传递多个参数
- Mybatis 传递参数示例
- mybatis 传递多个参数的方法(Multiple parameters)
- @Param 注解在Mybatis中的使用 以及传递参数的三种方式
- Mybatis传递多个参数
- mybatis 传递多参数(不使用实体)
- Mybatis参数传递
- mybatis常见问题处理:批量操作,传递多个参数,like语句写法等等
- mybatis传递多个参数
- MyBatis学习——参数的传递和返回
- mybatis传递多种参数
- JavaEE_Mybatis_SpringMVC_自定义的参数绑定,页面的日期类型传递到数据库中datetime
- SSM项目从零开始到入门008-mybatis传递多个参数问题
- Mybatis中可以传递的参数
- mybatis 中sql语句传递多个参数
- mybatis 关联映射传递多参数方法
- mybatis关于传递参数问题
- MyBatis传递参数的四种方案(包括SQL间传递)
- Mybatis传递多个参数的解决办法(三种)