跟着尚硅谷的框架整合学的,有一步实在觉得奇怪。
我在action中加了id这个属性,按道理struts会将这个id值写到action的成员变量id中,并调用input方法,然后这个action实现了preparable接口,于是加上了
public void prepareInput() {
System.out.println(id);
if(id != null){
model = employeeService.getEmployeeById(id);
System.out.println(model);
}
}
public String input() {
request.put("departments", departmentService.getAll());
System.out.println(id);
return INPUT;
}
也就是说会先调用prepareInput()方法,再调用input方法,可是prepareInput无法获得id的值(打印出来显示是null),但input方法里面打印出来是有id的,也就是说只有input被调用时id才会set进来,但是视频里prepareInput中id是可以获取的,这是为什么?