无法使用mybatis使用db从数据库中检索值

时间:2017-09-06 17:09:56

标签: java hashmap mybatis

传递rollno列表并获取学生详细信息,不确定daoImpl或call或mybatis错误的地方

studentDetailsDao

SqlSessionTemplate sqlSessionTemplate;
    public List<HashMap<String, String>> studentDataFromDataBase(List<String> rollNumberList) throws Exception{
        try {               
            List<HashMap<String, String>> studentListInput= new ArrayList<HashMap<String, String>>();    
            List<HashMap<String, String>> studentListOutput= new ArrayList<HashMap<String, String>>();          
            studentList.put("rollNumberList", rollNumberList);                      
            studentListOutput= sqlSessionTemplate.selectList("mybatisXml.studentDetails", studentListInput);
            return studentListOutput;               
        }
        catch(Exception e){}
    }

该方法称为:

    List<HashMap<String, String>> studentDetails = studentDetailsDao
    .studentDataFromDataBase(rollNumberList);

mybatisXml.studentDetails

 <mapper namespace="mybatisXml">
    <resultMap id="studentDataMap" type="java.util.HashMap" />
<select id="studentDetails" resultMap="studentDataMap"
    parameterType="java.util.HashMap">          
    SELECT
    STUDENT_NAME as studentName,
    TOTAL as total,
    RANK as rank,       
    FROM
      schema.studentTable
     WHERE ROLL_NUMBER
       IN            
       <foreach item="rollNoIndex" collection="list" open="(" separator="," close=")">
           #{rollNumberList.get(rollNoIndex)}
       </foreach>        
    </select> 

1 个答案:

答案 0 :(得分:0)

只有收藏错误

<mapper namespace="mybatisXml">
        <resultMap id="studentDataMap" type="java.util.HashMap" />
    <select id="studentDetails" resultMap="studentDataMap"
        parameterType="java.util.HashMap">          
        SELECT
        STUDENT_NAME as studentName,
        TOTAL as total,
        RANK as rank,       
        FROM
          schema.studentTable
         WHERE ROLL_NUMBER
           IN            
           <foreach item="rollNo" index="index" collection="studentListInput" open="(" separator="," close=")">
               #{rollNo}
           </foreach>        
        </select>