程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Bean 属性“categoryName”不可读或具有无效的 getter 方法大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Bean 属性“categoryName”不可读或具有无效的 getter 方法?

开发过程中遇到Bean 属性“categoryName”不可读或具有无效的 getter 方法的问题如何解决?下面主要结合日常开发的经验,给出你关于Bean 属性“categoryName”不可读或具有无效的 getter 方法的解决方法建议,希望对你解决Bean 属性“categoryName”不可读或具有无效的 getter 方法有所启发或帮助;

有人可以看看这个错误并帮助我吗?我花了 2 个小时找到问题,但我没有找到解决方案。 列出数据有效,但问题是在添加带有 action="savecategory.

的 Jsp 时

org.springframework.beans.NotReadablePropertyException: InvalID property 'categoryname' of bean class [java.util.ArrayList]: Bean property 'categoryname' 不可读或具有无效的 getter 方法:getter 的返回类型是否匹配setter 的参数类型?

JsP:

<c:forEach var="tempInvoicecategory" items="${invoicecategory}">
    <tr>
        <td>${tempInvoicecategory.categorynamE}</td>
        <td>
            <button type="button" class="btn btn-info">Edit</button>
            <button type="button" class="btn btn-danger">delete</button>
        </td>
    </tr>
</c:forEach>

<form:form class="forms-sample" action="savecategory" modelattribute="invoicecategory" method="POST">
    <div class="form-group">
        <label>Nazwa Kategorii</label>
        <form:input path="categoryname" type="text" class="form-control"/>
    </div>
    <button type="submit" class="btn btn-priMary mr-2">submit</button>
</form:form>

实体:

@Entity
@table(name="T_INVOICE_category")
public class Invoicecategory {
    @ID
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @column(name="ID_category")
    private int id;
    
    @column(name="category_name")
    private String categoryname;

    public int getID() {
        return ID;
    }

    public voID setID(int id) {
        this.ID = ID;
    }

    public String getcategoryname() {
        return categoryname;
    }

    public voID setcategoryname(String categoryName) {
        this.categoryname = categoryname;
    }

    @OverrIDe
    public String toString() {
        return "Invoicecategory [ID=" + ID + ",categoryname=" + categoryname + "]";
    }
    
}

控制器:

@Controller
@requestMapPing("/invoice")
public class InvoiceController {
    
    @autowired
    private Invoicecategoryservice invoicecategoryservice;
    
    @GetMapPing("/Listcategory")
    public String Listcategory(Model theModel) {
        
        List<Invoicecategory> invoicecategory = invoicecategoryservice.geTinvoicecategory();
        
        theModel.addAttribute("invoicecategory",invoicecategory);
        
        return "add-invoice-category";
    }
        
    @PostMapPing("/savecategory")
    public String saveCustomer(@modelattribute("invoicecategory") Invoicecategory theInvoicecategory) {
        invoicecategoryservice.saveInvoicecategory(theInvoicecategory);
        
        return "redirect:/customer/List";
    }
}

解决方法

我认为问题在于模型属性 invoiceCategoryList<InvoiceCategory> 并且在同一个 JSP 中,您尝试构建项目列表和尝试访问该项目的表单,但它是 List<InvoiceCategory>

<form:form class="forms-sample" action="saveCategory" modelAttribute="invoiceCategory" method="POST">
    <div class="form-group">
        <label>Nazwa Kategorii</label>
        <form:input path="categoryName" type="text" class="form-control"/>
    </div>
    <button type="submit" class="btn btn-priMary mr-2">Submit</button>
</form:form>

尝试评论这部分并再次运行应用程序。

大佬总结

以上是大佬教程为你收集整理的Bean 属性“categoryName”不可读或具有无效的 getter 方法全部内容,希望文章能够帮你解决Bean 属性“categoryName”不可读或具有无效的 getter 方法所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:getter方法