欢迎光临
我们一直在努力

Bean property ‘Id’ is not readable or has an invalid getter method

String sql = "insert into order_item(order_id,food_id,food_servings) values(:Id,:foodId,:foodServings)";
JDBCTemplateHelper.add(sql, orderItem);

JAVA中SQL语句报错如下:

Invalid property 'Id' of bean class [com.newsong.JavaBean.OrderItem]: Bean property 'Id' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?

上述报错,大意思是Id not readable 或者没有写setter,经过一番追踪

OrderItem orderItem = new OrderItem(orderId, foodId, servings);
oim.addOrderItem(orderItem);

OrderItem的构造方法:

public OrderItem(int orderId, int foodId, int foodServings) {
        super();
        this.orderId = orderId;
        this.foodId = foodId;
        this.foodServings = foodServings;
    }

发现并没有Id,因而将文初的SQL语句中的:Id改为:orderId问题解决。如下:

String sql = "insert into order_item(order_id,food_id,food_servings) values(:orderId,:foodId,:foodServings)"; JDBCTemplateHelper.add(sql, orderItem);

总结:遇到这种问题,仔细看错误提示语句,然后再去排查。

赞(0)
版权归原作者所有,如有侵权请告知。达维营-前端网 » Bean property ‘Id’ is not readable or has an invalid getter method

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址