我想订张table。但当我按下书桌按钮时,我发现一个错误。不支持请求方法“post”。我以前在其他类似的项目中也做过,效果不错。我想问题出在html文件中,但我找不到它。我怎样才能解决这个问题。这是我的实体类
`@Entity
@Table(name = "reservation")
public class Reservation {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private int id;
@Column(name = "arrival_date")
private String arrivalDate;
@Column(name = "arrival_time")
private String arrivalTime;
@Column(name = "num_of_person")
private String numOfPerson;
@Column(name = "first_name")
private String firstName;
@Column(name = "email")
private String email;
@Column(name = "phone_number")
private String phoneNumber;
Here is my Controller Class @Controller public class RestaurantController {` ```
@Autowired
private ReservationService reservationService;
@InitBinder
public void init(WebDataBinder binder) {
StringTrimmerEditor editor = new StringTrimmerEditor(true);
binder.registerCustomEditor(StringTrimmerEditor.class, editor);
}
@GetMapping("/")
public String home() {
return "index";
}
@GetMapping("/reservation")
public String reservation(Model model) {
model.addAttribute("newRes", new Reservation());
return "reservation";
}
@PostMapping("/save-reservation")
public String proceed(@Valid @ModelAttribute("newRes") Reservation reservation, BindingResult result, Model model) {
reservationService.saveReservation(reservation);
return "redirect:/reservation";
}
这是我的html文件
1条答案
按热度按时间jchrr9hc1#
在控制器类级别添加@requestmapping。