SpringBoot Mybatis Thymeleaf 在线预约挂号系统 写一套java代码
时间: 2024-02-07 14:04:15 浏览: 119
很抱歉,由于时间和篇幅的限制,我无法在这里提供完整的在线预约挂号系统的Java代码。不过,我可以为您提供一些示例代码,帮助您更好地理解该系统的实现方式。
1. 注册功能Controller代码:
```java
@Controller
public class RegisterController {
@Autowired
private UserService userService;
@GetMapping("/register")
public String registerForm(Model model) {
model.addAttribute("user", new User());
return "register";
}
@PostMapping("/register")
public String registerSubmit(@ModelAttribute User user, Model model) {
if(userService.getUserByUsername(user.getUsername()) != null) {
model.addAttribute("error", "用户名已存在");
return "register";
}
userService.addUser(user);
return "redirect:/login";
}
}
```
2. 医院管理Controller代码:
```java
@Controller
@RequestMapping("/admin")
public class HospitalAdminController {
@Autowired
private HospitalService hospitalService;
@GetMapping("/hospitals")
public String hospitalList(Model model) {
List<Hospital> hospitals = hospitalService.getAllHospitals();
model.addAttribute("hospitals", hospitals);
return "hospital_list";
}
@GetMapping("/hospitals/new")
public String newHospitalForm(Model model) {
model.addAttribute("hospital", new Hospital());
return "hospital_form";
}
@PostMapping("/hospitals/new")
public String newHospitalSubmit(@ModelAttribute Hospital hospital) {
hospitalService.addHospital(hospital);
return "redirect:/admin/hospitals";
}
@GetMapping("/hospitals/{id}")
public String hospitalDetail(@PathVariable Long id, Model model) {
Hospital hospital = hospitalService.getHospitalById(id);
model.addAttribute("hospital", hospital);
return "hospital_detail";
}
@GetMapping("/hospitals/{id}/edit")
public String editHospitalForm(@PathVariable Long id, Model model) {
Hospital hospital = hospitalService.getHospitalById(id);
model.addAttribute("hospital", hospital);
return "hospital_form";
}
@PostMapping("/hospitals/{id}/edit")
public String editHospitalSubmit(@ModelAttribute Hospital hospital) {
hospitalService.updateHospital(hospital);
return "redirect:/admin/hospitals";
}
@GetMapping("/hospitals/{id}/delete")
public String deleteHospital(@PathVariable Long id) {
hospitalService.deleteHospitalById(id);
return "redirect:/admin/hospitals";
}
}
```
3. 挂号功能Controller代码:
```java
@Controller
public class AppointmentController {
@Autowired
private AppointmentService appointmentService;
@GetMapping("/appointments")
public String appointmentList(Model model) {
List<Appointment> appointments = appointmentService.getAllAppointments();
model.addAttribute("appointments", appointments);
return "appointment_list";
}
@GetMapping("/appointments/new")
public String newAppointmentForm(Model model) {
model.addAttribute("appointment", new Appointment());
return "appointment_form";
}
@PostMapping("/appointments/new")
public String newAppointmentSubmit(@ModelAttribute Appointment appointment) {
appointmentService.addAppointment(appointment);
return "redirect:/appointments";
}
@GetMapping("/appointments/{id}")
public String appointmentDetail(@PathVariable Long id, Model model) {
Appointment appointment = appointmentService.getAppointmentById(id);
model.addAttribute("appointment", appointment);
return "appointment_detail";
}
}
```
这些示例代码只是系统代码的一部分,但希望可以帮助您了解该系统的实现方式。
阅读全文