sql >> Database teknologi >  >> RDS >> Oracle

MyBatis Mapping til hentning af liste over brugerdefinerede posttyper i Oracle

Skift mapper som følger

<resultMap type="detail" id="myResultMap"  >
        <result property="objectNamee" column="P_OBJECT_NAME" />
        <result property="objectStatus" column="p_object_status" />
</resultMap>

<select id="getLearnerMap" parameterType="spInOut" statementType="CALLABLE">

 {call p1.data_collection_append(#{objList, jdbcType=CURSOR, mode=OUT, resultMap=myResultMap, javaType=java.sql.ResultSet})}

</select>

opret en type i SpInOut i dit domænebibliotek

public class SpInOut {

    private Object objList;
   //getter setting follows
}

Her er et fuldstændig simpelt eksempel

DB side

Opret brugerdefineret type

PACKAGE KP_EMP_PCK AS

  type empType is ref cursor;

END KP_EMP_PCK;

Opret en lagret procedure

create or replace PROCEDURE KPLISTEMP
( empList OUT kp_emp_pck.empType
) AS
BEGIN
  open empList for select empid, fname, lname,address from kpemployee order by fname;
END KPLISTEMP;

Java Side

Opret domæneklasse

public class User {

    private String fName;
    private String company;
    private int age;
    private int salary;
    //getter Setter

}

Opret domæne til SpInOut

public class SpInOut {

        private Object empList;
       //getter setting follows
    }

Mapper-grænseflade

public interface EmployeeMapper {

    void getEmployees(SpInOut param);

}

Mapper xml-fil

<mapper namespace="com.kp.swasthik.db.oracle.persistence.EmployeeMapper">

    <resultMap type="employee" id="empResultMap"  >
        <id property="empId" column="EMPID" />
        <result property="fName" column="FNAME" />
        <result property="lName" column="LNAME" />
        <result property="address" column="ADDRESS"  />
    </resultMap>

    <select id="getEmployees"  statementType="CALLABLE" parameterType="spInOut" >
        {call kplistemp(#{empList, jdbcType=CURSOR, mode=OUT, resultMap=empResultMap, javaType=java.sql.ResultSet})}
    </select>
</mapper>

Og endelig serviceklassen

public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    EmployeeMapper mapper;

    @Override
    public List<Employee> getEmps() {
        try{
            SpInOut data= new SpInOut();
            mapper.getEmployees(data);
            return (List<Employee>) data.getEmpList();
        }catch(Exception e){
            e.printStackTrace();
        }
        return null;
    }

}



  1. Brug NEWID() til at oprette en unik værdi i SQL Server

  2. Sådan fungerer sys.dm_exec_describe_first_result_set_for_object i SQL Server

  3. Java-database mySQL-adgang nægtet

  4. Hvordan konverteres denne MySQL-sætning til symfony Propel?