2016-03-28 15 views
0
​​

はModelAttributeはSpring MVCの

<div class="form-group"> 
     <label for="name">Name</label> 
     <form:input path="productName" id="name" class="form-control"/> 
    </div> 

    <div class="form-group"> 
     <label for="Category">Category</label> 
     <label class="checkbox-inline"><form:radiobutton path="productCategory" id="category" 
                 value="Instrument"/>Instrument</label> 
     <label class="checkbox-inline"><form:radiobutton path="productCategory" id="category" 
                 value="Record"/>Record</label> 
     <label class="checkbox-inline"><form:radiobutton path="productCategory" id="category" 
                 value="accessory"/>Accessory</label> 
    </div> 

    <div class="form-group"> 
     <label for="description">Description</label> 
     <form:input path="productDescription" id="description" class="form-control" value="${product.productDescription}"/> 
    </div> 

    <div class="form-group"> 
     <label for="name">price</label> 
     <form:input path="productPrice" id="price" class="form-control" value="${product.productName}"/> 
    </div> 


    <div class="form-group"> 
     <label for="condition">Condition</label> 
     <label class="checkbox-inline"><form:radiobutton path="productCondition" id="condition" 
                 value="New"/>New</label> 
     <label class="checkbox-inline"><form:radiobutton path="productCondition" id="condition" 
                 value="Used"/>Used</label> 
    </div> 

ファイルのアップロード

<div class="form-group"> 
     <label for="status">Status</label> 
     <label class="checkbox-inline"><form:radiobutton path="productStatus" id="status" 
                 value="active"/>Active</label> 
     <label class="checkbox-inline"><form:radiobutton path="productStatus" id="status" 
                 value="inactive"/>inActive</label> 
    </div> 

    <div class="form-group"> 
     <label for="unitInStock">Unit in stock</label> 
     <form:input path="unitInStock" id="unitInStock" class="form-control" value="${product.unitInStock}"/> 
    </div> 

    <div class="form-group"> 
     <label for="manufacturer">manufacturer</label> 
     <form:input path="productManufacturer" id="manufacturer" class="form-control" value="${product.productManufacturer}"/> 
    </div> 

    <br><br> 

    <input type="submit" value="submit" class="btn btn-default"> 
    <a href="<c:url value="/admin/productInventory"/>" class="button btn-default">Cancel</a> 

    </form:form> 

パブリッククラス製品{

@Id 
@GeneratedValue(strategy = GenerationType.AUTO) 
private String productId; 
private String productName; 
private String productCategory; 
private String productDescription; 
private double productPrice; 
private String productCondition; 
private String productStatus; 
private int unitInStock; 
private String productManufacturer; 

@Transient 
private MultipartFile productImage; 

public String getProductName() { 
    return productName; 
} 

public String getProductId() { 
    return productId; 
} 

public void setProductId(String productId) { 
    this.productId = productId; 
} 

public void setProductName(String productName) { 
    this.productName = productName; 
} 

public String getProductCategory() { 
    return productCategory; 
} 

public void setProductCategory(String productCategory) { 
    this.productCategory = productCategory; 
} 

public String getProductDescription() { 
    return productDescription; 
} 

public void setProductDescription(String productDescription) { 
    this.productDescription = productDescription; 
} 

public double getProductPrice() { 
    return productPrice; 
} 

public void setProductPrice(double productPrice) { 
    this.productPrice = productPrice; 
} 

public String getProductCondition() { 
    return productCondition; 
} 

public void setProductCondition(String productCondition) { 
    this.productCondition = productCondition; 
} 

public String getProductStatus() { 
    return productStatus; 
} 

public void setProductStatus(String productStatus) { 
    this.productStatus = productStatus; 
} 

public int getUnitInStock() { 
    return unitInStock; 
} 

public void setUnitInStock(int unitInStock) { 
    this.unitInStock = unitInStock; 
} 

public String getProductManufacturer() { 
    return productManufacturer; 
} 

public void setProductManufacturer(String productManufacturer) { 
    this.productManufacturer = productManufacturer; 
} 

public MultipartFile getProductImage() { 
    return productImage; 
} 

public void setProductImage(MultipartFile productImage) { 
    this.productImage = productImage; 
} 
エラーを引き起こし

}

<mvc:annotation-driven/> 

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="prefix" value="/WEB-INF/views/" /> 
    <property name="suffix" value=".jsp"/> 
</bean> 

<mvc:resources mapping="/resources/**" location="/WEB-INF/resources/"/> 

<tx:annotation-driven/> 

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> 
    <property name="dataSource" ref="dataSource"></property> 
    <property name="hibernateProperties"> 
     <props> 
      <prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop> 
      <prop key="hibernate.hbm2ddl.auto">update</prop> 
      <prop key="hibernate.show_sql">true</prop> 
      <prop key="hibernate.format_sql">true</prop> 
     </props> 
    </property> 
    <property name="packagesToScan"> 
     <list> 
      <value>com.emusicstore</value> 
     </list> 
    </property> 
</bean> 

<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> 
    <property name="sessionFactory" ref="sessionFactory"/> 
</bean> 

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> 
    <property name="maxUploadSize" value="10000024" /> 
</bean> 

私が削除した場合、私はイムが間違ってやって何いけないが、例えば400エラーを取得していますth e ModelAttributeそれはそれが動作する誰かがここで間違って何が起こって私を助けることができます。たとえば、新しいコントローラを作成した場合、ポストは機能しますが、Firefoxのデバッガでチェックしようとしていないと、正しくないリクエストが表示されます。

+0

フォーム宣言の先頭に追加してください。 – nnunes10

+0

また、少し紹介しても痛いことはありません - あなたはどんなサーバーを使っていますか?どのコンテナ、Javaのバージョンなど – JoeG

+0

Tomcat 8.0サーバーとjdk 1.8.0 – NoR3s

答えて

0

MVCレイヤーのエンティティをモデルとして使用することは悪い習慣です。別のモデルを使用してみてください。

ここに入力されている商品はdoubleです。文字列に割り当てることはできません。

<div class="form-group"> 
     <label for="name">price</label> 
     <form:input path="productPrice" id="price" class="form-control" value="${product.productName}"/> 
    </div> 

に変更し、それを:

<div class="form-group"> 
      <label for="name">price</label> 
      <form:input path="productPrice" id="price" class="form-control" value="${product.productPrice}"/> 
     </div> 

とモデルの属性としてprimitivesの使用を避け、他の賢明なあなたはprimitivesので、空の彼らの入力を提出する場合は、ビューとエラーでの無用のデフォルト値で終わるだろうデフォルト値はnullではありません。

+0

これは私が私がそれを見ていない方法を知っていない私を働いてくれてありがとう。 – NoR3s

関連する問題