ibatis 传递多个参数

不知何时,ibatis3改为mybatis3了,听说mybatis3不用再需要自己手动实现DAO的实现类了,Service层可以直接使用DAO接口中的方法。

ibatis3如何传递多个参数有两个方法:一种是使用Map,另一种是使用JavaBean。

sqlXml配置:

测试代码:/** * 通过Map传递多个参数 */ @Test public void testSelectByMap() { SqlSession session = sqlSessionFactory.openSession(); Map param=new HashMap(); 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()); }

你可能感兴趣的:(Java,开发)