【异常类:AllErrorException】
package com.eshop.utils;
/**
* 该类为异常类,继承RuntimeException父类
* 提供不同的构造方法,用于保存不同的异常信息
* 私有属性obj为发生异常的对象实例
* 私有属性message为发生异常的信息
* @author qianjunsheng
*
*/
public class AllErrorException extends RuntimeException {
//发生异常的对象实例
private Object[] obj;
//发生是异常信息
private String message;
//参数为空的构造方法
public AllErrorException(){}
//参数为message的构造方法
public AllErrorException( String message){
this.message = message;
}
//参数为message和obj的构造方法
public AllErrorException(String message,Object obj){
this.message = message;
this.obj[0] = obj;
}
//参数为message和obj组的构造方法
public AllErrorException(String message,Object[] obj){
this.message = message;
this.obj = obj;
}
/** 属性obj和message的getter和setter方法*/
public Object[] getObj() {
return obj;
}
public void setObj(Object[] obj) {
this.obj = obj;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
【Dao接口:GoodsDao】
package com.eshop.dao;
import java.util.List;
import com.eshop.forms.Goods;
/**
* 定义接口GoodsDao和各个抽象方法
* 具体实现在GoodsDaoImpl中
* @author qianjunsheng
*
*/
public interface GoodsDao {
/**
* 物品添加
* @param goods
*/
public void addGoods(Goods goods);
/**
* 物品信息更新
* @param goods
*/
public void updateGoods(Goods goods);
/**
* 删除单个物品信息
* @param id为传入的删除物品的id编号
*/
public void deleteGoods(int id);
/**
* 删除一组物品信息
* @param ids为传入的一组id编号
*/
public void deleteGoods(int[] ids);
/**
* 查询所有物品信息
* @return Goods类的list
*/
public List<Goods> getGoods();
/**
* 查询单个物品信息
* @param id查询的物品id
* @return 该物品的实例
*/
public Goods getGoods(int id);
}
【Dao实现:GoodsDaoImpl】
package com.eshop.dao;
import java.util.ArrayList;
import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.eshop.forms.Goods;
import com.eshop.utils.AllErrorException;
/**
* Dao层
*接口GoodsDao的具体实现
*继承HibernateDaoSupport父类
*调用getHibernateTemplate()的save()、find()、update()、和delete()等方法
*完成数据库的各项操作
*执行失败抛出AllErrorException()异常
* @author qianjunsheng
*
*/
public class GoodsDaoImpl extends HibernateDaoSupport implements GoodsDao {
/**
* 向数据库中添加物品
* 调用save()方法,保存数据
* 失败抛出AllErrorException异常
*/
@Override
public void addGoods(Goods goods) {
try {
this.getHibernateTemplate().save(goods);
} catch (Exception e) {
e.printStackTrace();
throw new AllErrorException("物品添加失败", goods.getName());
}
}
/**
* 根据传入的id编号,构造查询Hql语句
* 调用find()方法,查询出该物品相关信息
* 调用delete()方法
* 向数据库中删除该物品信息
* 失败抛出AllErrorException异常
*/
@Override
public void deleteGoods(int id) {
String sql = "from Goods g where g.id= ?";
try {
Goods goods = (Goods) this.getHibernateTemplate().find(sql,
new Integer(id)).get(0);
this.getHibernateTemplate().delete(goods);
} catch (Exception e) {
throw new AllErrorException("删除失败");
}
}
/**
* 根据传入的id编号组,构造查询Hql语句
*在for循环内 调用find()方法,查询出该组物品相关信息
* 调用deleteAll()方法
* 向数据库中删除该组物品信息
* 失败抛出AllErrorException异常
*/
@Override
public void deleteGoods(int[] ids) {
String sql = "from Goods g where g.id= ?";
List<Goods> goodslist = new ArrayList<Goods>();
try {
for (int id : ids) {
Goods goods = (Goods) this.getHibernateTemplate().find(sql,
new Integer(id)).get(0);
goodslist.add(goods);
}
this.getHibernateTemplate().deleteAll(goodslist);
} catch (Exception e) {
throw new AllErrorException("删除失败", goodslist);
}
}
/**
* 定义泛型的List:goodslist
* 调用find()方法,查询出所有物品相关信息
* 将查询结果保存到goodslist里返回
* 失败抛出AllErrorException异常
*/
@SuppressWarnings("unchecked")
@Override
public List<Goods> getGoods() {
List<Goods> goodslist = new ArrayList<Goods>();
try{
goodslist = this.getHibernateTemplate().find("from Goods");
}catch(Exception e){
e.printStackTrace();
throw new AllErrorException("查询数据库失败");
}
return goodslist;
}
/**
* 根据传入的id编号,调用find()方法
* 将查询结果保存到goods里返回
* 失败抛出AllErrorException异常
*/
@Override
public Goods getGoods(int id) {
Goods goods = null;
String sql = "from Goods g where g.id= ?";
try{
goods = (Goods)this.getHibernateTemplate().find(sql,new Integer(id)).get(0);
}catch(Exception e){
e.printStackTrace();
throw new AllErrorException("查询失败");
}
return goods;
}
/**
* 根据传入的Goods对象实例信息
* 调用update()方法,更新数据库中该物品的相关信息
* 失败抛出AllErrorException异常
*/
@Override
public void updateGoods(Goods goods) {
try{
this.getHibernateTemplate().update(goods);
}catch(Exception e){
e.printStackTrace();
throw new AllErrorException("更新失败",goods.getName());
}
}
}
【Manager接口:GoodsManager】
package com.eshop.managers;
import java.util.List;
import com.eshop.forms.Goods;
/**
* 定义接口GoodsManager和各个抽象方法
* 具体实现在GoodsManagerImpl中
* @author qianjunsheng
*
*/
public interface GoodsManager {
//获取message信息
public abstract String getMsg();
//添加物品
public void addGoods(Goods goods);
//更新物品信息
public void updateGoods(Goods goods);
//删除物品信息
public void deleteGoods(int id);
//删除物品信息
public void deleteGoods(int[] ids);
//查询物品信息
public List<Goods> getGoods();
//查询物品信息
public Goods getGoods(int id);
}
【manger实现:GoodsManagerImpl】
package com.eshop.managers;
import java.util.List;
import com.eshop.dao.GoodsDao;
import com.eshop.forms.Goods;
/**
* 对GoodsManager接口的具体实现
* 定义私有属性msg,用于保存操作信息
* 调用GoodsDao的各个方法,完成各项操作
* @author qianjunsheng
*
*/
public class GoodsManagerImpl implements GoodsManager {
private GoodsDao goodsDao;
//保存操作信息
private String msg;
//GoodsDao的setter方法,为spring注入做准备
public void setGoodsDao(GoodsDao goodsDao) {
this.goodsDao = goodsDao;
}
/**
* 添加物品
* 保存添加成功信息
*/
@Override
public void addGoods(Goods goods) {
goodsDao.addGoods(goods);
this.msg="添加成功";
}
/**
* 删除物品
* 保存删除成功信息
*/
@Override
public void deleteGoods(int id) {
goodsDao.deleteGoods(id);
this.msg = "删除成功";
}
/**
* 删除物品
* 保存删除成功信息
*/
@Override
public void deleteGoods(int[] ids) {
goodsDao.deleteGoods(ids);
this.msg = "删除成功";
}
/**
*查询物品
*将查询结果返回
*/
@Override
public List<Goods> getGoods() {
return goodsDao.getGoods();
}
/**
*查询物品
*将查询结果返回
*/
@Override
public Goods getGoods(int id) {
return goodsDao.getGoods(id);
}
/**
*更新物品信息
*保存更新操作信息
*/
@Override
public void updateGoods(Goods goods) {
goodsDao.updateGoods(goods);
this.msg = "更新成功";
}
/**属性msg的getter和setter方法*/
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}
【Action:GoodsAction】
package com.eshop.actions;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import com.eshop.forms.Goods;
import com.eshop.managers.GoodsManager;
/**
* Goods类的Action,继承Struts的DispatchAction父类
* 该Action有insert、update、delete、query等方法
* 为GoodsManager提供setter方法,为spring注入做准备
* 在各个方法中调用GoodsManager中的方法的具体实现,完成各项操作
* 在各个方法中,调用GoodsManager.getMsg方法,获取message做转向判断
* @author qianjunsheng
*
*/
public class GoodsAction extends DispatchAction {
private GoodsManager goodsManager;
/**
* 物品添加
* 操作成功转success页面
* 操作失败转error页面
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward insert(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
Goods goods = (Goods)form;
goodsManager.addGoods(goods);
if("添加成功".equals(goodsManager.getMsg())){
return mapping.findForward("success");
}else{
return mapping.findForward("error");
}
}
/**
* 物品信息更新
* 操作成功转success页面
* 操作失败转error页面
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward update(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
Goods goods = (Goods)form;
goodsManager.updateGoods(goods);
if("更新成功".equals(goodsManager.getMsg())){
return mapping.findForward("success");
}else{
return mapping.findForward("error");
}
}
/**
* 物品删除
* 根据传入id编号数量的多少执行单物品删除或组删除
* 操作成功转success页面
* 操作失败转error页面
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward delete(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
int[] ids = null;
String[] idstr = request.getParameterValues("goodsid");
for(int i=0; i<idstr.length;i++){
ids[i] = Integer.parseInt(idstr[i].trim());
}
if(1 == ids.length){
goodsManager.deleteGoods(ids[0]);
}else if(ids.length>1){
goodsManager.deleteGoods(ids);
}
if("更新成功".equals(goodsManager.getMsg())){
return mapping.findForward("success");
}else{
return mapping.findForward("error");
}
}
/**
* 根据id编号,查询该物品信息
* 操作成功,把查询结果set到request中,转success页面
* 操作失败转error页面
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward query(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
int id = Integer.parseInt(request.getParameter("goodsid"));
Goods goods = goodsManager.getGoods(id);
if("更新成功".equals(goodsManager.getMsg())){
request.setAttribute("goods", goods);
return mapping.findForward("success");
}else{
return mapping.findForward("error");
}
}
/**
* 查询所有物品信息
* 操作成功,把查询结果set到request中,转success页面
* 操作失败转error页面
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward queryAll(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
List<Goods> goodslist = goodsManager.getGoods();
if("更新成功".equals(goodsManager.getMsg())){
request.setAttribute("goodslist", goodslist);
return mapping.findForward("success");
}else{
return mapping.findForward("error");
}
}
/**
* GoodsManager的setter方法,为spring注入准备
* @param goodsManager
*/
public void setGoodsManager(GoodsManager goodsManager) {
this.goodsManager = goodsManager;
}
}
【ActionForm:Goods】
package com.eshop.forms;
import org.apache.struts.action.ActionForm;
public class Goods extends ActionForm {
//物品id
private int id;
//物品名称
private String name;
//物品价格
private double price;
//物品数量
private int count;
//投递费用
private double transportCost;
//物品描述信息
private String details;
//物品类别
private Category category;
/**各个属性的getter和setter方法*/
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public double getTransportCost() {
return transportCost;
}
public void setTransportCost(double transportCost) {
this.transportCost = transportCost;
}
public String getDetails() {
return details;
}
public void setDetails(String details) {
this.details = details;
}
}
package com.eshop.utils;
/**
* 该类为异常类,继承RuntimeException父类
* 提供不同的构造方法,用于保存不同的异常信息
* 私有属性obj为发生异常的对象实例
* 私有属性message为发生异常的信息
* @author qianjunsheng
*
*/
public class AllErrorException extends RuntimeException {
//发生异常的对象实例
private Object[] obj;
//发生是异常信息
private String message;
//参数为空的构造方法
public AllErrorException(){}
//参数为message的构造方法
public AllErrorException( String message){
this.message = message;
}
//参数为message和obj的构造方法
public AllErrorException(String message,Object obj){
this.message = message;
this.obj[0] = obj;
}
//参数为message和obj组的构造方法
public AllErrorException(String message,Object[] obj){
this.message = message;
this.obj = obj;
}
/** 属性obj和message的getter和setter方法*/
public Object[] getObj() {
return obj;
}
public void setObj(Object[] obj) {
this.obj = obj;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
【Dao接口:GoodsDao】
package com.eshop.dao;
import java.util.List;
import com.eshop.forms.Goods;
/**
* 定义接口GoodsDao和各个抽象方法
* 具体实现在GoodsDaoImpl中
* @author qianjunsheng
*
*/
public interface GoodsDao {
/**
* 物品添加
* @param goods
*/
public void addGoods(Goods goods);
/**
* 物品信息更新
* @param goods
*/
public void updateGoods(Goods goods);
/**
* 删除单个物品信息
* @param id为传入的删除物品的id编号
*/
public void deleteGoods(int id);
/**
* 删除一组物品信息
* @param ids为传入的一组id编号
*/
public void deleteGoods(int[] ids);
/**
* 查询所有物品信息
* @return Goods类的list
*/
public List<Goods> getGoods();
/**
* 查询单个物品信息
* @param id查询的物品id
* @return 该物品的实例
*/
public Goods getGoods(int id);
}
【Dao实现:GoodsDaoImpl】
package com.eshop.dao;
import java.util.ArrayList;
import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.eshop.forms.Goods;
import com.eshop.utils.AllErrorException;
/**
* Dao层
*接口GoodsDao的具体实现
*继承HibernateDaoSupport父类
*调用getHibernateTemplate()的save()、find()、update()、和delete()等方法
*完成数据库的各项操作
*执行失败抛出AllErrorException()异常
* @author qianjunsheng
*
*/
public class GoodsDaoImpl extends HibernateDaoSupport implements GoodsDao {
/**
* 向数据库中添加物品
* 调用save()方法,保存数据
* 失败抛出AllErrorException异常
*/
@Override
public void addGoods(Goods goods) {
try {
this.getHibernateTemplate().save(goods);
} catch (Exception e) {
e.printStackTrace();
throw new AllErrorException("物品添加失败", goods.getName());
}
}
/**
* 根据传入的id编号,构造查询Hql语句
* 调用find()方法,查询出该物品相关信息
* 调用delete()方法
* 向数据库中删除该物品信息
* 失败抛出AllErrorException异常
*/
@Override
public void deleteGoods(int id) {
String sql = "from Goods g where g.id= ?";
try {
Goods goods = (Goods) this.getHibernateTemplate().find(sql,
new Integer(id)).get(0);
this.getHibernateTemplate().delete(goods);
} catch (Exception e) {
throw new AllErrorException("删除失败");
}
}
/**
* 根据传入的id编号组,构造查询Hql语句
*在for循环内 调用find()方法,查询出该组物品相关信息
* 调用deleteAll()方法
* 向数据库中删除该组物品信息
* 失败抛出AllErrorException异常
*/
@Override
public void deleteGoods(int[] ids) {
String sql = "from Goods g where g.id= ?";
List<Goods> goodslist = new ArrayList<Goods>();
try {
for (int id : ids) {
Goods goods = (Goods) this.getHibernateTemplate().find(sql,
new Integer(id)).get(0);
goodslist.add(goods);
}
this.getHibernateTemplate().deleteAll(goodslist);
} catch (Exception e) {
throw new AllErrorException("删除失败", goodslist);
}
}
/**
* 定义泛型的List:goodslist
* 调用find()方法,查询出所有物品相关信息
* 将查询结果保存到goodslist里返回
* 失败抛出AllErrorException异常
*/
@SuppressWarnings("unchecked")
@Override
public List<Goods> getGoods() {
List<Goods> goodslist = new ArrayList<Goods>();
try{
goodslist = this.getHibernateTemplate().find("from Goods");
}catch(Exception e){
e.printStackTrace();
throw new AllErrorException("查询数据库失败");
}
return goodslist;
}
/**
* 根据传入的id编号,调用find()方法
* 将查询结果保存到goods里返回
* 失败抛出AllErrorException异常
*/
@Override
public Goods getGoods(int id) {
Goods goods = null;
String sql = "from Goods g where g.id= ?";
try{
goods = (Goods)this.getHibernateTemplate().find(sql,new Integer(id)).get(0);
}catch(Exception e){
e.printStackTrace();
throw new AllErrorException("查询失败");
}
return goods;
}
/**
* 根据传入的Goods对象实例信息
* 调用update()方法,更新数据库中该物品的相关信息
* 失败抛出AllErrorException异常
*/
@Override
public void updateGoods(Goods goods) {
try{
this.getHibernateTemplate().update(goods);
}catch(Exception e){
e.printStackTrace();
throw new AllErrorException("更新失败",goods.getName());
}
}
}
【Manager接口:GoodsManager】
package com.eshop.managers;
import java.util.List;
import com.eshop.forms.Goods;
/**
* 定义接口GoodsManager和各个抽象方法
* 具体实现在GoodsManagerImpl中
* @author qianjunsheng
*
*/
public interface GoodsManager {
//获取message信息
public abstract String getMsg();
//添加物品
public void addGoods(Goods goods);
//更新物品信息
public void updateGoods(Goods goods);
//删除物品信息
public void deleteGoods(int id);
//删除物品信息
public void deleteGoods(int[] ids);
//查询物品信息
public List<Goods> getGoods();
//查询物品信息
public Goods getGoods(int id);
}
【manger实现:GoodsManagerImpl】
package com.eshop.managers;
import java.util.List;
import com.eshop.dao.GoodsDao;
import com.eshop.forms.Goods;
/**
* 对GoodsManager接口的具体实现
* 定义私有属性msg,用于保存操作信息
* 调用GoodsDao的各个方法,完成各项操作
* @author qianjunsheng
*
*/
public class GoodsManagerImpl implements GoodsManager {
private GoodsDao goodsDao;
//保存操作信息
private String msg;
//GoodsDao的setter方法,为spring注入做准备
public void setGoodsDao(GoodsDao goodsDao) {
this.goodsDao = goodsDao;
}
/**
* 添加物品
* 保存添加成功信息
*/
@Override
public void addGoods(Goods goods) {
goodsDao.addGoods(goods);
this.msg="添加成功";
}
/**
* 删除物品
* 保存删除成功信息
*/
@Override
public void deleteGoods(int id) {
goodsDao.deleteGoods(id);
this.msg = "删除成功";
}
/**
* 删除物品
* 保存删除成功信息
*/
@Override
public void deleteGoods(int[] ids) {
goodsDao.deleteGoods(ids);
this.msg = "删除成功";
}
/**
*查询物品
*将查询结果返回
*/
@Override
public List<Goods> getGoods() {
return goodsDao.getGoods();
}
/**
*查询物品
*将查询结果返回
*/
@Override
public Goods getGoods(int id) {
return goodsDao.getGoods(id);
}
/**
*更新物品信息
*保存更新操作信息
*/
@Override
public void updateGoods(Goods goods) {
goodsDao.updateGoods(goods);
this.msg = "更新成功";
}
/**属性msg的getter和setter方法*/
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}
【Action:GoodsAction】
package com.eshop.actions;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import com.eshop.forms.Goods;
import com.eshop.managers.GoodsManager;
/**
* Goods类的Action,继承Struts的DispatchAction父类
* 该Action有insert、update、delete、query等方法
* 为GoodsManager提供setter方法,为spring注入做准备
* 在各个方法中调用GoodsManager中的方法的具体实现,完成各项操作
* 在各个方法中,调用GoodsManager.getMsg方法,获取message做转向判断
* @author qianjunsheng
*
*/
public class GoodsAction extends DispatchAction {
private GoodsManager goodsManager;
/**
* 物品添加
* 操作成功转success页面
* 操作失败转error页面
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward insert(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
Goods goods = (Goods)form;
goodsManager.addGoods(goods);
if("添加成功".equals(goodsManager.getMsg())){
return mapping.findForward("success");
}else{
return mapping.findForward("error");
}
}
/**
* 物品信息更新
* 操作成功转success页面
* 操作失败转error页面
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward update(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
Goods goods = (Goods)form;
goodsManager.updateGoods(goods);
if("更新成功".equals(goodsManager.getMsg())){
return mapping.findForward("success");
}else{
return mapping.findForward("error");
}
}
/**
* 物品删除
* 根据传入id编号数量的多少执行单物品删除或组删除
* 操作成功转success页面
* 操作失败转error页面
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward delete(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
int[] ids = null;
String[] idstr = request.getParameterValues("goodsid");
for(int i=0; i<idstr.length;i++){
ids[i] = Integer.parseInt(idstr[i].trim());
}
if(1 == ids.length){
goodsManager.deleteGoods(ids[0]);
}else if(ids.length>1){
goodsManager.deleteGoods(ids);
}
if("更新成功".equals(goodsManager.getMsg())){
return mapping.findForward("success");
}else{
return mapping.findForward("error");
}
}
/**
* 根据id编号,查询该物品信息
* 操作成功,把查询结果set到request中,转success页面
* 操作失败转error页面
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward query(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
int id = Integer.parseInt(request.getParameter("goodsid"));
Goods goods = goodsManager.getGoods(id);
if("更新成功".equals(goodsManager.getMsg())){
request.setAttribute("goods", goods);
return mapping.findForward("success");
}else{
return mapping.findForward("error");
}
}
/**
* 查询所有物品信息
* 操作成功,把查询结果set到request中,转success页面
* 操作失败转error页面
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward queryAll(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
List<Goods> goodslist = goodsManager.getGoods();
if("更新成功".equals(goodsManager.getMsg())){
request.setAttribute("goodslist", goodslist);
return mapping.findForward("success");
}else{
return mapping.findForward("error");
}
}
/**
* GoodsManager的setter方法,为spring注入准备
* @param goodsManager
*/
public void setGoodsManager(GoodsManager goodsManager) {
this.goodsManager = goodsManager;
}
}
【ActionForm:Goods】
package com.eshop.forms;
import org.apache.struts.action.ActionForm;
public class Goods extends ActionForm {
//物品id
private int id;
//物品名称
private String name;
//物品价格
private double price;
//物品数量
private int count;
//投递费用
private double transportCost;
//物品描述信息
private String details;
//物品类别
private Category category;
/**各个属性的getter和setter方法*/
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public double getTransportCost() {
return transportCost;
}
public void setTransportCost(double transportCost) {
this.transportCost = transportCost;
}
public String getDetails() {
return details;
}
public void setDetails(String details) {
this.details = details;
}
}