@Component
@RequestMapping("/student")
public?class?StudentController?extends?BaseController?{
@Autowired
StudentService?studentService;
@RequestMapping(value?=?"/listStudent")
public?void?list()?throws?Exception?{
...
//這里調用getStudents方法正常
List<Student>?stuList?=?this.getStudents();
...
}
public?List<Student>?getStudents()?{
try?{
List<Student>?stuList?=?studentService.listStudent(page,?rows,?sort,?order);
return?stuList;
}?catch?(Exception?e)?{
e.printStackTrace();
}
return?null;
}
@RequestMapping(value?=?"/export")
public?void?export()?throws?Exception?{
...
//?獲取類
//根據傳過來的參數?className,?methodName?調用相應的方法
Class?clazz?=?Class.forName(className);
Object?o?=?clazz.newInstance();
Method?m?=?clazz.getDeclaredMethod(methodName);
//這里調用getStudents方法出現studentService空指針異常
List?list?=?(List)?m.invoke(o);
...
}
}以上是省略過的代碼!
添加回答
舉報
0/150
提交
取消