当前位置:Gxlcms > 数据库问题 > MyBatis从入门到放弃五:调用存储过程(SQLServer2012)

MyBatis从入门到放弃五:调用存储过程(SQLServer2012)

时间:2021-07-01 10:21:17 帮助过:52人阅读

select id="testProc" parameterType="int" resultMap="authorResultMap"> exec usp_getAuthorBlogsById #{id} </select>

 

单元测试

@Test
    public void testProc(){
        SqlSession sqlSession=null;
        try{
            sqlSession=sqlSessionFactory.openSession();

            Author author = sqlSession.selectOne("com.autohome.mapper.Author.testProc",1);
            System.out.println("作者信息 id:"+author.getId()+",name:"+author.getName());
            System.out.println("作者博客:");
            for(Blog blog:author.getBlogs()){
                System.out.println("id:"+blog.getId()+",title:"+blog.getTitle()+",category:"+blog.getCategory());
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
            sqlSession.close();
        }
    }

附单元测试截图

技术分享

MyBatis从入门到放弃五:调用存储过程(SQLServer2012)

标签:存储过程   test   blog   -128   创建   开发环境   sqlserver   final   get   

人气教程排行