1. 注册ShopService
同用户注册模块里面的UserService服务的注册一样,我们在applicationContext-service.xml配置文件中,配置ShopService的服务,以及它的方法的Spring事务管理,具体配置是在applicationContext-service.xml添加如下配置:
<!-- 商品查看定购服务 -->
<!—配置商品服务三个方法的Spring事务管理à
<bean id="shopServiceProxy" parent="baseServiceProxy">
<property name="target">
<ref bean="shopService" />
</property>
<property name="transactionAttributes">
<props>
<prop key="find*">PROPAGATION_REQUIRED</prop>
<!--
<prop key="findShopsMsg">PROPAGATION_REQUIRED</prop>
-->
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<!—注册商品服务 à
<bean id="shopService"
class="cn.com.book.demo.services.impl.ShopServicesImpl">
<property name="shopDAO">
<ref bean="ShopDAO"/>
</property>
</bean>
2. 编写Form和Action
因为我们在这里没有需要实现表单校验,所以ShopForm就直接继承ActionForm实现,结合页面需要的信息,我们可以整理出ShopForm.java的清单如下:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package cn.com.book.demo.struts.form;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
/**
* MyEclipse Struts
* Creation date: 12-11-2007
*
* XDoclet definition:
* @struts.form name="shopForm"
*/
public class ShopForm extends ActionForm {
private String shopName; //商品名称
private int shopId;// 商品编号
private double price;//商品价格
private List shops;//商品集合
private int targetPage = 1;//当前页码
private int totalPage;//页码总数
private int shopAmount;//商品数量
private boolean hasFirst = false;//是否显示首页
private boolean hasPrev = false;//是否显示前一页
private boolean hasNext = false;//是否显示下一页
private boolean hasLast = false;//是否显示末页
/*
* Generated Methods
*/
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getShopId() {
return shopId;
}
public void setShopId(int shopId) {
this.shopId = shopId;
}
public String getShopName() {
return shopName;
}
public void setShopName(String shopName) {
this.shopName = shopName;
}
public List getShops() {
return shops;
}
public void setShops(List shops) {
this.shops = shops;
}
/**
* Method validate
* @param mapping
* @param request
* @return ActionErrors
*/
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
// TODO Auto-generated method stub
return null;
}
/**
* Method reset
* @param mapping
* @param request
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
// TODO Auto-generated method stub
}
public boolean isHasFirst() {
return hasFirst;
}
public void setHasFirst(boolean hasFirst) {
this.hasFirst = hasFirst;
}
public boolean isHasLast() {
return hasLast;
}
public void setHasLast(boolean hasLast) {
this.hasLast = hasLast;
}
public boolean isHasNext() {
return hasNext;
}
public void setHasNext(boolean hasNext) {
this.hasNext = hasNext;
}
public boolean isHasPrev() {
return hasPrev;
}
public void setHasPrev(boolean hasPrev) {
this.hasPrev = hasPrev;
}
public int getTargetPage() {
return targetPage;
}
public void setTargetPage(int targetPage) {
this.targetPage = targetPage;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getShopAmount() {
return shopAmount;
}
public void setShopAmount(int shopAmount) {
this.shopAmount = shopAmount;
}
}