@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); ... } }
以上是省略过的代码!
灬java
慕的地7538294
慕的地7538294
相关分类