【问题标题】:Binding object in SpringSpring中的绑定对象
【发布时间】:2016-06-04 05:11:46
【问题描述】:

spring 和 jsp 中的绑定错误,如果有人可以提供帮助,我将不胜感激。

我有这些属性的正确 getter 和 setter,

private int sydinv;
@NotNull(message="You must specify the inventory in Melbourne warehouse")
private int melinv;

当我在 jsp 文件中使用它们时,错误消息说“Bean property 'sydinv' is not readable or has an invalid getter method: If the return type of the getter match the parameter type of the setter?”

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri = "http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<form:form action="${pageContext.request.contextPath}/products/save" method = "post" commandName="product">
<label>Title
<form:input  path="title" /> <form:errors path="title"/></label>
<br/>
<label> Description 
<form:input type = "text" path= "description"/></label>
<br/>
<label>Price
<form:input  path= "price" /><form:errors path="price"/></label>
<label>Image
<form:input  path= "imageUrl" /><form:errors path="imageUrl"/></label>
<label>sydinv
<form:input  path= "sydinv" /><form:errors path="sydinv"/></label>
<label>Inventory
<form:input  path= "inventory" /><form:errors path="inventory"/></label>
<form:input type="hidden" path="productId"/>
<br/>
<input type = "submit" value = "Submit"/>
<br/>
<input type = "reset" />
</form:form>

这是我的控制器

@RequestMapping("/edit/{productId}")
public String edit(@PathVariable int productId, Model model){
    //add your code here to find a product based on its id
    //and put it in the model
    Product product = pdao.getProductById(productId);
    System.out.println("@@"+product.getSydInv()+"##"+product.getMelInv());

    model.addAttribute("product", product);
    return "product";
}

jsp文件可以读取除syd_inv之外的所有属性,谁能给我一些提示?干杯

【问题讨论】:

  • 实际错误是什么?

标签: java spring jsp


【解决方案1】:

Bean 属性 'sydinv' 不可读

这里你的sydinv 写得很简单,但是你的getter 方法指向SydInvgetSydInv()。我认为你的gettersetter 方法是错误的 把它改成

setsydinv(int sydinv){this.sydinv = sydinv}
int getsydinv(){return sydinv}

【讨论】:

  • 非常感谢,我将参数列表中的名称更改为与类属性相同,它可以工作,非常感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-04-25
  • 2013-01-17
  • 2014-05-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多