java.lang.IllegalStateException:Bean名称“ firstName”的BindingResult和普通目标对象都不能用作请求属性

时间:2019-05-19 07:10:16

标签: java spring spring-mvc

java.lang.IllegalStateException:Bean名称“ firstName”的BindingResult和普通目标对象都不能用作请求属性

这是控制器类

  @Controller
    @RequestMapping("/customer")

    public class CustomerController {

    @Autowired
    private CustomerService customerService;

    @GetMapping("/list")
    public String listCustomer(Model theModel) {

    List<Customer> customers = customerService.getCustomers();
    theModel.addAttribute("customers", customers);  
    return "list-customers";

    }
    @GetMapping("/showFormForAdd")
    public String showFormForAdd(Model theModel) {

    Customer theCustomer = new Customer();
    theModel.addAttribute("customers",theCustomer); 

    return "customer-form";
    }
    }

这是jsp页面

 <form action="saveCustomer" modelAttribute="customers" method="POST">
    <table>
    <tbody>
    <tr>
    <td><label>First name:</label></td>
    <td><form:input path="firstName"/></td>
    </tr>   
    </tbody>

这是实体类

 @Entity
    @Table(name = "customer")
    public class Customer { 
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private int id; 
    @Column(name = "first_name")
    private String firstName;
    @Column(name = "last_name")
    private String lastName;
    @Column(name = "email")
    private String email;

0 个答案:

没有答案