簡體   English   中英

無法使用Mybatis使用db從數據庫中檢索值

[英]Unable to retrieve value from database using db using mybatis

通過rollno列表並獲取學生詳細信息,不確定我在daoImpl或call或mybatis中哪里出錯了

學生詳細資料

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> 

只有收集是錯誤的

<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> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM