开发者社区> 问答> 正文

提交Set集合出错? 400 报错

提交Set集合出错? 400 报错

 

package oshop.entity;

import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

/**
 * 产品品牌
 * 
 * @author sky
 * 
 */
@Entity
@org.hibernate.annotations.Entity(dynamicUpdate = true)
@Table(name = "brand")
public class Brand extends BaseEntity {

    /**
	 * 
	 */
    private static final long serialVersionUID = -982632398252926845L;
    /**
     * 产品类型
     */

    private Set<ProductType> productTypes;
    private String name;
    private String siteUrl;

    @Column(unique = true, nullable = false)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSiteUrl() {
        return siteUrl;
    }

    public void setSiteUrl(String siteUrl) {
        this.siteUrl = siteUrl;
    }

    @ManyToMany(fetch = FetchType.LAZY)
    public Set<ProductType> getProductTypes() {
        return productTypes;
    }

    public void setProductTypes(Set<ProductType> productTypes) {
        this.productTypes = productTypes;
    }

}
package oshop.entity;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * 产品类型
 * 
 * @author sky
 * 
 */
@Entity
@Table(name = "product_type")
public class ProductType extends BaseEntity {

    private static final long serialVersionUID = 4500336342773347538L;

    private ProductCategory parentCategory; // 商品分类

    private String name;// 商品类型名称

    private Set<ProductTypeAttribute> productTypeAttributes; // 商品属性

    private Set<Brand> brands;// 商品类型可选的品牌

    private String priceRange;// 价格区间

    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    public ProductCategory getParentCategory() {
        return parentCategory;
    }

    public void setParentCategory(ProductCategory parentCategory) {
        this.parentCategory = parentCategory;
    }

    @Column(nullable = false)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY, mappedBy = "productType")
    public Set<ProductTypeAttribute> getProductTypeAttributes() {
        return productTypeAttributes;
    }

    public void setProductTypeAttributes(
            Set<ProductTypeAttribute> productTypeAttributes) {
        this.productTypeAttributes = productTypeAttributes;
    }

    public String getPriceRange() {
        return priceRange;
    }

    public void setPriceRange(String priceRange) {
        this.priceRange = priceRange;
    }

    @ManyToMany(fetch = FetchType.LAZY)
    public Set<Brand> getBrands() {
        return brands;
    }

    public void setBrands(Set<Brand> brands) {
        this.brands = brands;
    }

}

 

<tr>
	<th class="label">可选品牌:</th>
	<td><#if (brandList?size > 0)> <#list brandList as brand>
		<ul class="checkboxList">
		<li>
<input id="brand_${brand.id}" type="checkbox" name="productType.brands.makeNew[${brand_index}].id" value="${brand.id}" /> <label for="brand_${brand.id}" title="${(brand.siteUrl)!}"> ${brand.name} </label> </li> </ul> </#list> </#if> <div class="cb"></div> </td> </tr>

 

properites:

KeyProperty_brands=id
Element_brands=oshop.entity.Brand
CreateIfNull_brands=true

提交表单报错是:

2011-3-11 10:37:58 com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
警告: Error setting expression 'productType.brands.makeNew[0].id' with value '[Ljava.lang.String;@472ebf9a'
ognl.OgnlException: Error getting property descriptor: null
    at com.opensymphony.xwork2.ognl.accessor.XWorkCollectionPropertyAccessor.getProperty(XWorkCollectionPropertyAccessor.java:126)
    at com.opensymphony.xwork2.ognl.accessor.XWorkListPropertyAccessor.getProperty(XWorkListPropertyAccessor.java:80)

 

 

找了一上午了,网上说要写properties文件和makeNew也写了。就是提交不上去。Set new 过了也是这个错误。Brand里面有getId,setId

展开
收起
爱吃鱼的程序员 2020-06-01 10:50:42 351 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB
    1. KeyProperty_brands=id  
    2. Element_brands=oshop.entity.Brand  
    3. CreateIfNull_brands=true 

    问题主要出在这里:

    Action下面没有brands,应该是Action下的productType.brands 但是不知道这样的话上面的配置应该怎么写?

    2020-06-01 10:50:44
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载