MyBaits:Mysqlストレージ・プロシージャの複数の戻りセットを受信する方法
3011 ワード
私がテストしたテーブルはapp_です.action、app_action_type、integral_sign_ソースの内容は勝手で、みんなは勝手に創立することができます;
ストアド・プロシージャ名:mytest作成文は次のとおりです.
ストアド・プロシージャ名:mytest作成文は次のとおりです.
DROP PROCEDURE IF EXISTS `mytest`$$
CREATE DEFINER=`wsrp`@`%` PROCEDURE `mytest`()
BEGIN
SELECT COUNT(1) AS test1 FROM app_action;
SELECT COUNT(1) AS test2 FROM app_action_type;
SELECT COUNT(1) AS test3 FROM integral_sign_source;
END$$
DELIMITER ;
Service層コードpackage com.hori.jfms.service;
import java.util.List;
public interface TestService {
List> test ();
}
サービス層実装クラスコードpackage com.hori.jfms.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hori.jfms.mapper.TestMapper;
import com.hori.jfms.service.TestService;
/**
* app service
* @author laizs
* @time 2018 1 2 11:17:11
*/
@Service("testService")
public class TestServiceImpl implements TestService{
@Autowired
private TestMapper testMapper;
@Override
public List> test() {
return testMapper.test();
}
}
Mapperインタフェースコードpackage com.hori.jfms.mapper;
import java.util.List;
public interface TestMapper {
List> test();
}
Mapper.xmlコンテンツ:
テストクラスpackage com.hori.jfms;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.hori.jfms.model.IntegralSource;
import com.hori.jfms.service.TestService;
@RunWith(SpringJUnit4ClassRunner.class)
@org.springframework.boot.test.context.SpringBootTest(classes=JfmsSrvApplication.class)// spring-boot
public class ConsumerTest {
@Autowired
private TestService testService;
@Test
public void test(){
List> integralSource = testService.test();
System.out.println("test1:"+((List)integralSource.get(0)).get(0));// List
System.out.println("test2:"+((List)integralSource.get(1)).get(0));
System.out.println("test3:"+((List)integralSource.get(2)).get(0));
}
}
テスト結果:test1:18
test2:3
test3:7
作者用フレームワークSpringBoot,ありがとうございました!!