基于Spring EL表达式给bean的属性赋默认值,如果属性已有值,则不会被EL重新赋值
在需要被EL赋值的属性上打@ElValue注解,指定EL表达式
public class User {
@ElValue("2 + 2")
private int userId;
@ElValue("'123'")
private String password;
@ElValue("1 == 1")
private boolean nativeUser;
//getters and setters
}
final SpringElBeanProcessor elBeanProcessor = new SpringElBeanProcessor(new SpelExpressionParser());
final User user = new User();
elBeanProcessor.process(user);
配置aop
<aop:config proxy-target-class="true"/>
<bean class="cn.yxffcode.beanel.aop.ElParameterAdvisor">
<constructor-arg>
<bean class="cn.yxffcode.beanel.SpringElBeanProcessor"/>
</constructor-arg>
</bean>
在需要处理的方法参数上加@ElBean注解
public class TestDao implements ITestDao {
@Override public void save(@ElBean User user) {
System.out.println(user);
}
}