根据下列代码<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>新增航班信息</title> </head> <body> <h1>新增航班信息</h1> <form method="post" action="/flightAdd"> <label for="id">航班编号:</label><input type="text" id="id" name="id"><br/> <label for="src">出发地:</label><input type="text" id="src" name="src"><br/> <label for="des">目的地:</label><input type="text" id="des" name="des"><br/> <label for="date">日期:</label><input type="date" id="date" name="date"><br/> <label for="startTime">起飞时间:</label><input type="time" id="startTime" name="startTime"><br/> <label for="endTime">到达时间:</label><input type="time" id="endTime" name="endTime"><br/> <label for="remainSeats">剩余座位数:</label><input type="number" id="remainSeats" name="remainSeats"><br/> <label for="fares">票价:</label><input type="number" id="fares" name="fares"><br/> <label for="discountNums">折扣数:</label><input type="number" id="discountNums" name="discountNums"><br/> <label for="discount">折扣:</label><input type="number" id="discount" name="discount"><br/> <label for="company">航空公司:</label><input type="text" id="company" name="company"><br/> <input type="submit" value="提交"> </form> </body> </html>给出对应的controler接口
时间: 2023-07-02 13:16:06 浏览: 144
假设你使用的是 Spring MVC,以下是 controller 的代码示例:
```java
@Controller
public class FlightController {
@Autowired
private FlightService flightService;
@GetMapping("/flightAdd")
public String showAddFlightForm(Model model) {
model.addAttribute("flightDO", new FlightDO());
return "addFlight";
}
@PostMapping("/flightAdd")
public String addFlight(@ModelAttribute("flightDO") FlightDO flightDO) {
flightService.addFlight(flightDO);
return "redirect:/flightList";
}
}
```
其中 FlightDO 是一个 POJO 类,用于存储航班信息的各个属性。在 GET 请求中,我们返回一个空的 FlightDO 对象,用于在页面中显示表单。在 POST 请求中,我们将提交的表单数据绑定到 FlightDO 对象上,并调用 Service 层的方法将其存储到数据库中。最后,我们重定向到航班列表页面。