代码:
public ActionForward saveForecastType(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
String url = "forecastType/forecastType/indexforecastType.ftl";
String path = "message/sucess.ftl";
SysUser user = (SysUser) request.getSession().getAttribute("user");
String infoId = (String) getService().getForecastTypeManager()
.getGeneratId();// 用于生成新的Id
ForecastType info = new ForecastType();
Map root = new HashMap();
root.put("url", url);
String vegetableTypeId = (String) request.getParameter("vegetableTypeId");
String oldPri = (String) request.getParameter("oldPrice");
double oldPrice = Double.parseDouble(oldPri);
String pri = (String) request.getParameter("price");
double price = Double.parseDouble(pri);
String oldSa = (String) request.getParameter("oldSale");
double oldSale = Double.parseDouble(oldSa);
String sal = (String) request.getParameter("sale");
double sale = Double.parseDouble(sal);
System.out.println("vegetableTypeId:"+vegetableTypeId+"  oldPrice:"+oldPrice+"  price:"+price+"  oldSale:"+oldSale+"sale:"+sale);

//开始计算系数
double e = 0;
double q = sale-oldSale;
System.out.println("q:"+q);
double p = price-oldPrice;
System.out.println("p:"+p);
e = (q/p)*(oldPrice/oldSale);
System.out.println("e: "+e);

info.setE(e);
info.setOldPrice(oldPrice);
info.setPrice(price);
info.setOldSale(oldSale);
info.setSale(sale);
if (vegetableTypeId != null) {
VegetableType ct = new VegetableType();
ct.setId(vegetableTypeId);
info.setVegetableType(ct);
}
info.setCreator(user);
info.setCreateTime(new Date());

if (getService().getForecastTypeManager().save(info)) {
root.put("message", "操作成功");
} else {
path = "message/failed.ftl";
root.put("message", "操作失败");
}
super.goToFtl(path, root, request, response);
return null;
}

解决方案 »

  1.   

    info这个对象条用了一系列set方法,这明显就是更新info表的数据了,肯定是update了,没有insert,说明你save方法没有执行成功
      

  2.   

    但是我们其他的新增方法也是如此写的,且都成功了,执行的也是insert
    照搬过来改了字段就不行了
      

  3.   

    save方法的参数是个对象,你save方法返回类型是boolean型?
      

  4.   

    if (getService().getForecastTypeManager().save(info)) {这行弄个断点,看下info和getService().getForecastTypeManager().save(info)的值各是什么,还有,怎么没有对象调用getService().getForecastTypeManager().save(info)它