`
liyonghui160com
  • 浏览: 771658 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

mybatis Sqlserver 存储过程 结果集

阅读更多

 

Sqlserver返回结果集的存储过程调用方式:

 

一、存储过程:

 

create procedure selectCount
 @num int =0
 as
 begin
 SELECT COUNT(0) FROM mytable
 end
 
 create procedure selectId
@num int =0
as
begin
SELECT id FROM mytable
end
 

 

二、Mybatis的映射文件

 

<select id="selectSpreplshowcmds" parameterType="java.lang.Integer" statementType="CALLABLE"  resultMap="BaseResultMap">
           { call sp_replshowcmds(#{maxtrans,jdbcType=INTEGER,mode=IN})}
    </select>

    <select id="selectCount" resultType="java.lang.Integer">
        SELECT COUNT(0) FROM mytable;
    </select>

    <select id="selectCountProcedure" parameterType="java.lang.Integer" statementType="CALLABLE"  resultType="java.lang.Integer">
        { call selectCount(#{num,jdbcType=INTEGER,mode=IN})}
    </select>

    <select id="selectId" parameterType="java.lang.Integer" statementType="CALLABLE"  resultType="java.lang.Integer">
        { call selectId(#{num,jdbcType=INTEGER,mode=IN})}
    </select>
 
其实就是sql不一样 其他调用都一样的。注意加上 statementType="CALLABLE"
Mapper接口
@Repository
public interface SpreplshowcmdsMapper {


    List<Spreplshowcmds> selectSpreplshowcmds(Integer maxtrans);

    Integer selectCount();

    Integer selectCountProcedure(Integer num);

    List<Integer> selectId(Integer num);
}
 
service接口
public interface SpreplshowcmdsService {

    List<Spreplshowcmds> selectSpreplshowcmds(Integer maxtrans);

    Integer selectCount();
    Integer selectCountProcedure(Integer num);

    List<Integer> selectId(Integer num);

}
 
service实现
@Service("spreplshowcmdsService")
public class SpreplshowcmdsServiceImpl implements SpreplshowcmdsService {

    @Resource(name ="spreplshowcmdsMapper")
    private SpreplshowcmdsMapper spreplshowcmdsMapper;

    @Override
    public List<Spreplshowcmds> selectSpreplshowcmds(Integer maxtrans) {

        return spreplshowcmdsMapper.selectSpreplshowcmds(maxtrans);
    }

    @Override
    public Integer selectCount() {
        return spreplshowcmdsMapper.selectCount();
    }

    @Override
    public Integer selectCountProcedure(Integer num) {
        return spreplshowcmdsMapper.selectCountProcedure(1);
    }

    @Override
    public List<Integer> selectId(Integer num) {
        return spreplshowcmdsMapper.selectId(1);
    }
}
 
测试调用
public class App {

    public static void main(String[] args) {


        ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        SpreplshowcmdsService spreplshowcmdsService = ( SpreplshowcmdsService)context.getBean("spreplshowcmdsService");
        Integer count= spreplshowcmdsService.selectCount();
        System.out.println(count);

        Integer countProcedure = spreplshowcmdsService.selectCountProcedure(1);
        System.out.println(countProcedure);

        List<Integer> idList = spreplshowcmdsService.selectId(1);
        System.out.println(idList);


        List<Spreplshowcmds> spreplshowcmdsList = spreplshowcmdsService.selectSpreplshowcmds(100);
        System.out.println("qqqqqqq");
        System.out.println(spreplshowcmdsList.size());

    }


}
 
可以参考mybatis的源码,
https://github.com/mybatis/mybatis-3


 

 

  • 大小: 28.6 KB
分享到:
评论

相关推荐

    MyBatis连接SQLServer的小例子

    MyBatis是一款优秀的Java持久层框架,它支持定制化SQL、存储过程以及高级映射,极大地简化了传统Java开发中的数据库操作。SQLServer是微软公司推出的关系型数据库管理系统,广泛应用于企业级应用开发。本教程将通过...

    springboot+mybatis+sqlserver

    【标题】"springboot+mybatis+sqlserver"是一个基于Spring Boot、MyBatis和Microsoft SQL Server构建的基础开发框架,适用于快速开发企业级应用。这个框架整合了三个关键组件,旨在简化开发流程,提高开发效率。 ...

    SpringMVC+Mybatis+SQLServer整合源码 含数据库文件

    整合SpringMVC、Mybatis和SQLServer的过程主要包括以下步骤: 1. 配置SpringMVC:在web.xml中配置DispatcherServlet,以及Spring的ContextLoaderListener,加载Spring的配置文件。 2. 配置Spring的bean:定义...

    springboot+mybatis+sqlserver 仓库管理系统

    3. 数据库:使用SQLServer存储业务数据,通过Mybatis的动态SQL特性,实现了灵活的数据查询和更新操作。 四、开发流程 1. 搭建环境:安装并配置好Java开发环境、SQLServer数据库以及相关开发工具。 2. 创建项目:...

    springboot+netty+mybatis+sqlserver

    这个项目可能是一个高性能、轻量级的网络通信应用,利用Spring Boot的便利性和Netty的高效网络处理能力,结合MyBatis对数据库操作的支持,并通过SQL Server存储数据。 描述中提到的"socket"是指应用可能包含了基于...

    springmvc+mybatis+sqlserver小例子

    在这个"springmvc+mybatis+sqlserver小例子"中,开发者可能会遇到以下几个关键知识点: 1. **Spring自动装配**:Spring 提供了自动装配(Autowiring)功能,可以通过注解如`@Autowired`自动将依赖注入到类的属性或...

    mybatis基本配置及例子.zip_mybatis_mybatis sql server_mybatis 实例_mybati

    MyBatis是一个优秀的持久层框架,它支持定制化SQL、存储过程以及高级映射。MyBatis避免了几乎所有的JDBC代码和手动设置参数以及获取结果集。MyBatis可以使用简单的XML或注解进行配置和原始映射,将接口和Java的POJOs...

    基于sql server整合SpringMVC Mybatis

    SQL Server提供了可靠的数据存储,SpringMVC实现了MVC架构,提高了代码的可维护性,而Mybatis则简化了数据库操作。这种组合在实际开发中非常常见,适用于各种中大型项目,既满足了业务需求,又保证了开发效率。

    springboot + mybatis +mysql+ sqlserver 双数据源

    本项目"springboot + mybatis +mysql+ sqlserver 双数据源"正是针对这种需求的一个解决方案,它利用SpringBoot框架、MyBatis持久层框架以及MySQL和SQLServer两种数据库,实现了数据源的自动切换,以满足不同业务场景...

    MyBatis通过 JDBC连接 SQL server 数据库简单例子,进阶使用动态代理

    MyBatis是一个优秀的Java持久层框架,它支持定制化SQL、存储过程以及高级映射。在本示例中,我们将探讨如何使用MyBatis通过JDBC连接到SQL Server数据库,并进一步学习如何利用MyBatis的动态代理机制生成Mapper接口的...

    mybatis-sql-dialect

    不同的数据库管理系统(DBMS)有着各自的SQL方言,这些差异可能体现在语法、函数支持、特定的存储过程等方面。例如,MySQL支持`LIMIT`子句进行分页查询,而Oracle则使用`ROWNUM`和子查询。MyBatis-SQL-Dialect包...

    Mybatis调用MySQL存储过程的简单实现

    1. 在MyBatis的Mapper XML文件中定义SQL映射,使用`&lt;select&gt;`标签,并设置`id`属性为存储过程名,`resultType`属性为返回结果的数据类型。由于存储过程不返回普通的SQL查询结果,所以使用`statementType="CALLABLE"`...

    mysql和sqlserver的驱动包

    而SQL Server提供多种存储引擎,如InnoDB、TempDB等,且支持更高级的事务隔离级别。 2. 性能:MySQL因其轻量级和高效而受到青睐,尤其在读取密集型应用中表现出色;SQL Server则在复杂查询和大数据管理方面更具优势...

    mybaits+sqlserver小例子

    MyBatis是一个优秀的Java持久层框架,它支持定制化SQL、存储过程以及高级映射。在本示例中,我们将探讨如何将MyBatis与Microsoft SQL Server数据库结合使用,为初学者提供一个基础的实践教程。 一、MyBatis简介 ...

    sql server2000 驱动程序

    2. 在Java代码中,通过`Class.forName()`方法加载驱动,例如:`Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver")`。 3. 使用`DriverManager.getConnection()`方法创建数据库连接,提供服务器地址、...

    SQL SERVER 双引号问题处理

    ### SQL Server 双引号问题处理 在进行数据库操作时,我们经常需要用到各种各样的字符来构建复杂的查询语句。其中,SQL Server 使用单引号(' ')来标识字符串,这是一种约定俗成的做法。然而,在某些情况下,比如...

    springboot mybatis 动态调用oracle存储过程,通过存储过程名称,就能动态调用存储过程、java动态调用or

    能不能写个动态的业务,只输入存储过程名称,自动获取存储过程参数,并且参数的数据从前台传递过来,这个就通用了。只写一个通用方法,就可以调用所有的存储过程。只根据输入不同的存储过程名称、参数内容,自动调用...

    SpringMVC+Mybatis+SqlServer 增删改查上传下载示例

    这个示例项目涵盖了多个核心知识点,包括SpringMVC作为控制层,Mybatis作为数据访问层,以及SqlServer作为数据库存储。以下是对这些技术及其在示例中应用的详细解释: 1. **SpringMVC**:Spring MVC是Spring框架的...

    SQLServer数据库语法速成

    在IT领域,数据库管理是至关重要的技能之一,而SQL Server作为全球广泛使用的数据库管理系统,其强大的功能和丰富的语法为数据存储、查询和分析提供了坚实的基础。"SQL Server数据库语法速成"旨在帮助初学者快速掌握...

    spring mvc、mybatis、sqlserver代码生成器

    MyBatis是一个优秀的持久层框架,它支持定制化的SQL、存储过程以及高级映射。MyBatis避免了几乎所有的JDBC代码和手动设置参数以及获取结果集。代码生成器可以为MyBatis生成Mapper接口、Mapper XML配置文件以及实体...

Global site tag (gtag.js) - Google Analytics