传递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>
答案 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>