在JSP页面中是这样定义的:
[code="HTML"]
${c.name}
style="background-color: #F7F7F7;" value=""/>
/c:forEach
[/code]
在Action类中
[code="java"]
private CrmBusinessProduct model;
private CrmBusinessProduct[] models; //得到业务机会产品数值
public CrmBusinessProduct[] getModels() {
return models;
}
public void setModels(CrmBusinessProduct[] models) {
this.models = models;
}
public String save() throws Exception {
if(subBox == null){
addActionError("参数错误!");
return ADDTWO;
}
if(StringUtils.isEmpty(this.bid)) {
addActionError("参数错误!");
return ADDTWO;
}
if(null == models){
addActionError("参数错误!");
return ADDTWO;
}
CrmBusiness crmBusiness = this.crmBusinessService
.getObjectBusiness(this.bid);
if (null == crmBusiness) {
addActionError("参数错误!");
return ADDTWO;
}
//循环添加产品数据
for(int i=0;i<subBox.length;i++){
this.crmProduct=this.crmProductService.get(subBox[i]);
this.crmBusiness= this.crmBusinessService.getObjectBusiness(this.bid);
this.models[i].setTenantID(this.getCurrenTenantID());
this.models[i].setBusinessID(crmBusiness.getId());
this.models[i].setBusinessName(crmBusiness.getBussName());
this.models[i].setProductID(crmProduct.getId());
this.models[i].setProductName(crmProduct.getName());
this.models[i].setProductTypeID(crmProduct.getProductTypeID());
this.models[i].setQuantity(models[i].getQuantity());
this.models[i].setDescription(models[i].getDescription());
this.models[i].setPrice(crmProduct.getPrice());
this.models[i].setCostPrice(models[i].getPrice());
this.models[i].setDate(this.models[i].getDate());
this.models[i].setCreateDate(new Date());
this.models[i].setModifyDate(new Date());
this.crmBusinessProductService.insert(this.models[i]);
}
// 2.保存自定义数据
if (null != this.getModelColumnList()) {
CrmColumnDefineData data = null;
for (CrmColumnDefine o : this.modelColumnList) {
data = new CrmColumnDefineData();
String columnVal = request.getParameter(o.getId());
data.setColumnId(o.getId());
data.setTargetId(this.model.getId());
data.setTenantId(this.model.getTenantID());
data.setValue(columnVal);
this.crmColumnDefineService.storeColumnData(data);
}
}
this.id = this.model.getId();
if (this.btnType.equals("save")) {
return SUCCESS;
} else if (this.btnType.equals("save_new")) {
return add();
}
return SUCCESS;
}
[/code]
为什么models我用debug测试 models为空是什么原因?
[code="java"]
s2sh的
//添加
public String save() throws Exception {
this.userService.saveUser(user);
return SUCCESS;
}
//查询
@SuppressWarnings("unchecked")
public String list() throws Exception {
Map request = (Map) ActionContext.getContext().get("request");
request.put("list", this.userService.users());
return SUCCESS;
}
[/code]
[code="java"]
普通java写的
public class UserDaoTest {
@Test
public void testQueryAll() {
UserDao userDao = new UserDao();
List<User> list=userDao.queryAll();
for(int i=0;i<list.size();i++){
User user =new User();
list.add(user);
System.out.println(user.getName());
}
}
}
[/code]
[code="java"]
参考一下,缕缕思路,要不晚上远程
[/code]
[code="java"]
哥哥你先从request里面取,定义一下 例如name
private String name 提供相应的getter
然后你在获取request.get.........获取参数
如果是struts2以后高版本可能不用
[/code]
实现modeldriver了?
[code="java"]
sql 写错了..........汗
[/code]
你这样循环想直接得到数组应该是不行的
写个测试类测试一下,能都拿到数据?如果不能拿到,说明你dbug没问题,肯定sql有问题,逻辑有问题。
[code="java"]
save()保存一下,最后调一下该方法,把对象保存进去。
[/code]
[code="java"]
循环后,是拿到了,但是你要再次添加给你的对象,添加之后对象才能有你所要的值,这样就不是空的了。
[/code]