at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
以下是GoodsCate .java
package com.bean.informng;
import java.util.HashSet;
import java.util.Set;
public class GoodsCate {
private int goods_num;
private String goods_cateName;
private Set
public int getGoods_num() {
return goods_num;
}
public void setGoods_num(int goods_num) {
this.goods_num = goods_num;
}
public String getGoods_cateName() {
return goods_cateName;
}
public void setGoods_cateName(String goods_cateName) {
this.goods_cateName = goods_cateName;
}
public Set
return goodsInfor;
}
public void setGoodsInfor(Set
this.goodsInfor = goodsInfor;
}
}
商品信息GoodsInfor.java
package com.bean.informng;
public class GoodsInfor {
private int goods_code;
private String goods_name;
private int goods_category;
private String goods_mnemonic;
private String goods_model;
private String goods_unit;
private String goods_address;
private int goods_price;
private int goods_presale;
private String goods_remark;
private GoodsCate goodsCate;
public int getGoods_code() {
return goods_code;
}
public void setGoods_code(int goods_code) {
this.goods_code = goods_code;
}
public String getGoods_name() {
return goods_name;
}
public void setGoods_name(String goods_name) {
this.goods_name = goods_name;
}
public int getGoods_category() {
return goods_category;
}
public void setGoods_category(int goods_category) {
this.goods_category = goods_category;
}
public String getGoods_mnemonic() {
return goods_mnemonic;
}
public void setGoods_mnemonic(String goods_mnemonic) {
this.goods_mnemonic = goods_mnemonic;
}
public String getGoods_model() {
return goods_model;
}
public void setGoods_model(String goods_model) {
this.goods_model = goods_model;
}
public String getGoods_unit() {
return goods_unit;
}
public void setGoods_unit(String goods_unit) {
this.goods_unit = goods_unit;
}
public String getGoods_address() {
return goods_address;
}
public void setGoods_address(String goods_address) {
this.goods_address = goods_address;
}
public int getGoods_price() {
return goods_price;
}
public void setGoods_price(int goods_price) {
this.goods_price = goods_price;
}
public int getGoods_presale() {
return goods_presale;
}
public void setGoods_presale(int goods_presale) {
this.goods_presale = goods_presale;
}
public String getGoods_remark() {
return goods_remark;
}
public void setGoods_remark(String goods_remark) {
this.goods_remark = goods_remark;
}
public GoodsCate getGoodsCate() {
return goodsCate;
}
public void setGoodsCate(GoodsCate goodsCate) {
this.goodsCate = goodsCate;
}
}
映像文件:
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
Action:
package com.action.informng;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import com.bean.informng.GoodsCate;
import com.bean.informng.GoodsInfor;
import com.opensymphony.xwork2.ActionSupport;
import com.service.informng.GoodsCateManageService;
import com.service.informng.GoodsInforManageService;
public class GoodsInforAction extends ActionSupport{
private int goods_code;
private int goods_category;
private String goods_name;
private String goods_mnemonic;
private String goods_model;
private String goods_unit;
private String goods_address;
private int goods_price;
private int goods_presale;
private String goods_remark;
private GoodsInfor goodsInfor;
private GoodsInforManageService goodsInforService;
private List
private String json;
private String delids;
private GoodsCate goodsCate;
private GoodsCateManageService cateService;
private int goods_num;
public String execute() throws Exception {
goodsInforList = goodsInforService.findAllGoodsInfor();
json="{Rows:[";
for (int i = 0; i < goodsInforList.size(); i++) {
GoodsInfor su = goodsInforList.get(i);
json+="{goods_code:\""+su.getGoods_code()+"\",goodsCate:\""+su.getGoodsCate().getGoods_cateName()+"\",goods_name:\""+su.getGoods_name()+"\"," +
"goods_mnemonic:\""+su.getGoods_mnemonic()+"\"," +
"goods_model:\""+su.getGoods_model()+"\"," +
"goods_unit:\""+su.getGoods_unit()+"\"," +
"goods_address:\""+su.getGoods_address()+"\"," +
"goods_price:\""+su.getGoods_price()+"\"," +
"goods_presale:\""+su.getGoods_presale()+"\"," +
"goods_remark:\""+su.getGoods_remark()+"\" },";
}
json+="]}";
System.out.println(json);
return SUCCESS;
}
public String addGoodsInfor() throws Exception {
GoodsInfor goodsInfor=new GoodsInfor();
goodsInfor.setGoods_code(goods_code);
GoodsCate cate=cateService.findoneGoodsCate(goods_num);
goodsInfor.setGoodsCate(cate);
goodsInfor.setGoods_name(goods_name);
goodsInfor.setGoods_mnemonic(goods_mnemonic);
goodsInfor.setGoods_model(goods_model);
goodsInfor.setGoods_unit(goods_unit);
goodsInfor.setGoods_address(goods_address);
goodsInfor.setGoods_price(goods_price);
goodsInfor.setGoods_presale(goods_presale);
goodsInfor.setGoods_remark(goods_remark);
goodsInforService.addGoodsInfor(goodsInfor);
return SUCCESS;
}
public void delGoodsInfor() throws Exception {
List
String[] ids = delids.split(",");
for (int i = 0; i < ids.length; i++) {
idlist.add(Integer.parseInt(ids[i]));
}
goodsInforService.delGoodsInfor(idlist);
goodsInforList = goodsInforService.findAllGoodsInfor();
json="{Rows:[";
for (int i = 0; i < goodsInforList.size(); i++) {
GoodsInfor su = goodsInforList.get(i);
json+="{goods_code:\""+su.getGoods_code()+"\",goodsCate:\""+su.getGoodsCate().getGoods_cateName()+"\",goods_name:\""+su.getGoods_name()+"\"," +
"goods_mnemonic:\""+su.getGoods_mnemonic()+"\"," +
"goods_model:\""+su.getGoods_model()+"\"," +
"goods_unit:\""+su.getGoods_unit()+"\"," +
"goods_address:\""+su.getGoods_address()+"\"," +
"goods_price:\""+su.getGoods_price()+"\"," +
"goods_presale:\""+su.getGoods_presale()+"\"," +
"goods_remark:\""+su.getGoods_remark()+"\" },";
}
json+="]}";
System.out.println(json);
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
out.println(json);
}
public String findOneGoodsInfor() throws Exception{
System.out.println(goods_code);
goodsInfor=goodsInforService.findoneGoodsInfor(goods_code);
return SUCCESS;
}
public String updateGoodsInfor() throws Exception{
goodsInforService.updateGoodsInfor(goodsInfor);
return SUCCESS;
}
public int getGoods_code() {
return goods_code;
}
public void setGoods_code(int goods_code) {
this.goods_code = goods_code;
}
public int getGoods_category() {
return goods_category;
}
public void setGoods_category(int goods_category) {
this.goods_category = goods_category;
}
public String getGoods_name() {
return goods_name;
}
public void setGoods_name(String goods_name) {
this.goods_name = goods_name;
}
public String getGoods_mnemonic() {
return goods_mnemonic;
}
public void setGoods_mnemonic(String goods_mnemonic) {
this.goods_mnemonic = goods_mnemonic;
}
public String getGoods_model() {
return goods_model;
}
public void setGoods_model(String goods_model) {
this.goods_model = goods_model;
}
public String getGoods_unit() {
return goods_unit;
}
public void setGoods_unit(String goods_unit) {
this.goods_unit = goods_unit;
}
public String getGoods_address() {
return goods_address;
}
public void setGoods_address(String goods_address) {
this.goods_address = goods_address;
}
public int getGoods_price() {
return goods_price;
}
public void setGoods_price(int goods_price) {
this.goods_price = goods_price;
}
public int getGoods_presale() {
return goods_presale;
}
public void setGoods_presale(int goods_presale) {
this.goods_presale = goods_presale;
}
public String getGoods_remark() {
return goods_remark;
}
public void setGoods_remark(String goods_remark) {
this.goods_remark = goods_remark;
}
public GoodsInfor getGoodsInfor() {
return goodsInfor;
}
public void setGoodsInfor(GoodsInfor goodsInfor) {
this.goodsInfor = goodsInfor;
}
public GoodsInforManageService getGoodsInforService() {
return goodsInforService;
}
public void setGoodsInforService(GoodsInforManageService goodsInforService) {
this.goodsInforService = goodsInforService;
}
public List
return goodsInforList;
}
public void setGoodsInforList(List
this.goodsInforList = goodsInforList;
}
public String getJson() {
return json;
}
public void setJson(String json) {
this.json = json;
}
public String getDelids() {
return delids;
}
public void setDelids(String delids) {
this.delids = delids;
}
public GoodsCate getGoodsCate() {
return goodsCate;
}
public void setGoodsCate(GoodsCate goodsCate) {
this.goodsCate = goodsCate;
}
public GoodsCateManageService getCateService() {
return cateService;
}
public void setCateService(GoodsCateManageService cateService) {
this.cateService = cateService;
}
public int getGoods_num() {
return goods_num;
}
public void setGoods_num(int goods_num) {
this.goods_num = goods_num;
}
}
JSP添加页:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
如果外键删了,添加功能是能实现的,个人觉得问题出在Action方法里:
GoodsCate cate=cateService.findoneGoodsCate(goods_num);
goodsInfor.setGoodsCate(cate);
就是商品信息里的商品类别值没传进去,求大神帮忙,在此谢谢了