注解参数:
@Action来代替<action>元素!
@Result来代替<result>元素!
@Namespace代替<package>的namespace属性!
@ParentPackage代替<package>的extends属性!
@ParentPackage("json-default")
@Namespace("/html/employee")
@Results({@Result(name="success",type="redirectAction",location="select"),
@Result(name="index",location="listEmployee.jsp"),
@Result(name="oneInfo",location="editEmployee.jsp")
})
public class CustomerAction extends ActionSupport implements ModelDriven<Customer> {
Result:Result注解内的四个参数:
1)name:可选参数,用于指定Result的逻辑名,默认值为success
2)location:必选参数,用于指定Result对应资源的URL
3)type:可选参数,用于指定Result的类型,默认值为NullResult.class
4)params:可选参数,用于为Result指定要传递的参数,格式为:{key1,value1,key2,value2,...}
@Action(value="select",params={"pageSize","5"})
public String select(){
if(customer==null){
customer=new Customer();
}
lstc=customerBizImpl.findInfoByCondition(customer);
return "index";
}
另外在提提struct2的默认规定
通过Action的限制得到结果页面路径
Struts2约定限制Result返回的页面放在/WEB-INF/content/目录中,可以通过下面常量来修改这个限制。
<constant name="struts.convention.result.path" value="/WEB-INF/content/"/>
@ParentPackage("json-default")
@Namespace("/html/employee")
@Results({@Result(name="success",type="redirectAction",location="select"),
@Result(name="index",location="listEmployee.jsp"),
@Result(name="oneInfo",location="editEmployee.jsp")
})
public class CustomerAction extends ActionSupport implements ModelDriven<Customer> {
如果没有修改默认参数name="index"的 result返回的路径为 :/crm_hhs/WEB-INF/content/html/employee/listEmployee.jsp (crm_hhs是项目名)
修改默认参数:<constant name="struts.convention.result.path" value="/" />
返回路径:/crm_hhs/html/employee/listEmployee.jsp