基于ssh之优化具体参数值
方法一: 通过spring注入
xml: 中可以有多个key1,key2,key3...,根据需要
<bean id="app1Action" class="org.ssh_manage.action.App1Action" scope="prototype" p:service-ref="service" p:key1="teacherDao" p:key2="studentDao"> </bean>
action父类:
private String key1; private String key2; get/set(...)
action类:
List<Teacher> teachers = getService().getAll(getKey1);
以上相当于写了:
List<Teacher> teachers = getService().getAll("teacherDao");
方法二: 通过静态final定义常量
action父类:
public static final String TEACHER = "teacherDao"; public static final String STUDENT = "studentDao";
action子类:
List<Teacher> teachers = getService().getAll(STUDENT);

浙公网安备 33010602011771号