教師公寓與教師的關系 程序是想通過教師公寓的id獲取teacher這個集合 比如幾號公寓住著哪些教師 一直報轉換類型錯誤 求大神看看
service裡面的代碼
public static List<Teacher> findTeacher(int id){
List<Teacher> teacher = new ArrayList<Teacher>();
SqlSession session =MyBatisUtils.getSqlSession();
try{
TeacherApartmentDaoMapper teacherapartmentMapper = session.getMapper(TeacherApartmentDaoMapper.class);
teacher = teacherapartmentMapper.findTeacher(id);
}catch(Exception e){
e.printStackTrace();
}finally{
MyBatisUtils.closeSqlSession(session);
}
return teacher;
}
Action裡面的代碼
@Action(value="findTeacher")
public void findTeacher()throws Exception{
ServletActionContext.getResponse().setCharacterEncoding("utf-8");
List<Teacher> teacher = TeacherApartmentService.findTeacher((Integer.parseInt(ServletActionContext.getRequest().getParameter("ftId"))));// 這裡報錯
ServletActionContext.getResponse().getWriter()
.print(new Gson().toJson(teacher));
ServletActionContext.getResponse().getWriter().flush();
ServletActionContext.getResponse().getWriter().close();
}
請問應該怎麼改,這種1對多的關系做起卡了幾天了 求大神指教 感激不盡!!
控制台報的錯是java.lang.NumberFormatException: null
或者,繼續拆分:
Var = ServletActionContext.getRequest().getParameter("ftId"); // 不清楚返回的數據類型,請按實現返回的數據類型定義。
int iFtld = Integer.parseInt(Var);
List<Teacher> teacher = TeacherApartmentService.findTeacher(iFtld);