1.mybatis中调用存储过程
存储过程
CREATE OR REPLACE procedure getStudentByScore(scores IN NUMBER,students OUT SYS_REFCURSOR) isbeginOPEN students FOR SELECT * from student WHERE score = scores;end getStudentByScore;
mapper接口
void selectStudentByscore(Mapparams);
mapper映射
测试
public static ListprocedureTest(int scores) throws IOException { String resource = "sqlMapConfig.xml"; InputStream inputStream = Resources.getResourceAsStream(resource); SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream); SqlSession session = sessionFactory.openSession(); StudentMapper studentMapper = session.getMapper(StudentMapper.class); Map parameter = new HashMap (); parameter.put("scores", scores); studentMapper.selectStudentByscore(parameter); return (List )parameter.get("students");}public static void main(String[] args) throws IOException { Student student = procedureTest(111).get(1); System.out.println(student.getUsername());}
mybatis 中调用存储函数
存储过程
create or replace function queryEmpIncome(eno in number) return numberas psal emp.sal%type; pcomm emp.comm%type;begin select sal,comm into psal,pcomm from emp where empno=eno; return psal*12+nvl(pcomm,0);end;/
mapper接口
void selectEmpSalByEmpno(Mapparams);
mapper映射
测试
public static int selectEmpSalByEmpnoTest(int empno) throws IOException { String resource = "sqlMapConfig.xml"; InputStream inputStream = Resources.getResourceAsStream(resource); SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream); SqlSession session = sessionFactory.openSession(); StudentMapper studentMapper = session.getMapper(StudentMapper.class); Mapparameter = new HashMap (); parameter.put("eno", empno); studentMapper.selectEmpSalByEmpno(parameter); return (Integer)parameter.get("salCount");}public static void main(String[] args) throws IOException { int salCount = selectEmpSalByEmpnoTest(7369); System.out.println(salCount);}