Spring+Hibernate+Struts2整合[Action类配置][6/6]
上一章节主要讲解了关于Service类配置的具体内容,这一章节主要讲解了关于Action层的配置详情
有两种解决方案:
- 一种是依然用Struts.xml配置文件的方式:
1 <action name="createBook" class="bookAction" method="createBook"> 2 <result name="success">/WEB-INF/jsp/temp.jsp</result> 3 </action>
class属性不再是写类的全路径了,而是写Spring管理的Bean的id属性值;因为action已经交由Spring管理了。
- 一种是用注解的方式:
1 @Controller("customerAction") 2 @Scope("prototype") 3 @ParentPackage("struts-default") 4 @Namespace("/customer") 5 @Results({@Result(name="addUI",type="dispatcher",location="/WEB-INF/jsp/customer/add.jsp")}) 6 public class CustomerAction extends ActionSupport implements ModelDriven<Customer> { 7 private Customer customer = new Customer(); 8 9 @Override 10 public Customer getModel() { 11 return customer; 12 } 13 /** 14 * 获取添加客户页面 15 * @return 16 */ 17 @Action("addUICustomer") 18 public String addUICustomer() { 19 return "addUI"; 20 } 21 }
- @Controller
- @Scope
- @ParentPackage
- @Namespace
- @Results
- @Action
其中,值得注意的是Scope属性一定不要忘了,Spring默认是单例模式,需要改成prototype类型。
以上主要讲解了Action类的主要配置详情,接下来就是多开发、多锻炼,由浅入深!加油,奋斗,趁年轻!自信,相信自己能行的!其实你也是能行的!
凝一眸碧水,拈一缕清风,于一怀静谧中倾听凡尘的落音。
不再奢求什么,做简单的自己,过简单的生活,心在,梦在,你在,便是光阴赐予我的最美。

浙公网安备 33010602011771号