第一种:通过构造name和value属性(不常用)
<!-- userAction --> <bean id="userAction" class="com.xx.action.UserAction"> <constructor-arg name="add" value="山东"></constructor-arg> <constructor-arg name="age" value="29"></constructor-arg> </bean>
第二种:构造通过index/value 配合type使用(常用)
<!-- userAction --> <bean id="userAction" class="com.xx.action.UserAction"> <constructor-arg index="0" value="孔府" type="String"></constructor-arg> <constructor-arg index="1" value="29" type="Integer"></constructor-arg> </bean>
bean类
public class UserAction { private String name; private Integer age; private String add; public UserAction(String name, Integer age) { this.name = name; this.age = age; } public UserAction(Integer age, String add) { this.age = age; this.add = add; } }