从数据库中获取的数据,存到一个model中,需要注意两点。
一个是在dao中,只能用List类型接受结果
二是,要在mapper中写清楚resultType
//DAO
@Override
public ArrayList<YourModel> getMainInfo(int id) {
// TODO Auto-generated method stub
List<YourModel> result = null;
try{
sqlSession = this.getSqlSession();
}catch (Exception e){
e.printStackTrace();
YourModel yourModel = new YourModel();
try{
/**
* 很奇怪,在这里不能直接强转类型为ArrayList<GradeCheck>
* 只能在下面return的时候强转类型.....
* */
result = sqlSession.selectList(this.NAMESPACE.concat("getMainInfo"), yourModel);
}catch (Exception e){
return null;
}
return (ArrayList<YourModel>)result;
}
//mapper
List<model> findByIds(Long... ids);
<select id="findByIds" resultMap="BaseResultMap">
select <include refid="Base_Column_List" /> from model(tableName)
where ID in
<foreach item="item" index="index" collection="array" open="(" separaotr="," close=")">
#{item}
</foreach>
</select>