add create appointment
This commit is contained in:
parent
7e12068e8b
commit
2b8514b8e2
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
@ -26,17 +26,18 @@ public class AppointmentMVCController
|
|||||||
appointmentService.findAllAppointments().stream()
|
appointmentService.findAllAppointments().stream()
|
||||||
.map(AppointmentDTO::new)
|
.map(AppointmentDTO::new)
|
||||||
.toList());
|
.toList());
|
||||||
|
model.addAttribute("appointmentDTO", new AppointmentDTO());
|
||||||
return "appointment";
|
return "appointment";
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
public String createAppointment(String name, Model model){
|
public String createAppointment(@ModelAttribute AppointmentDTO appointmentDTO, Model model){
|
||||||
|
|
||||||
Random r = new Random();
|
Random r = new Random();
|
||||||
var app = new Appointment(r.nextLong(), name);
|
var app = new Appointment(r.nextLong(), appointmentDTO.getName());
|
||||||
appointmentService.addAppointment(new AppointmentDTO(app));
|
appointmentService.addAppointment(new AppointmentDTO(app));
|
||||||
model.addAttribute("appointmentName", name);
|
// model.addAttribute("appointmentName", name);
|
||||||
model.addAttribute("appointmentDTO", new AppointmentDTO(appointmentService.addAppointment(new AppointmentDTO(app))));
|
// model.addAttribute("appointmentDTO", new AppointmentDTO(appointmentService.addAppointment(new AppointmentDTO(app))));
|
||||||
return "redirect:/appointment";
|
return "redirect:/appointment";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,19 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div layout:fragment="content">
|
<div layout:fragment="content">
|
||||||
|
<div>
|
||||||
|
<form action="#" th:action="@{/appointment/create}" th:object="${appointmentDTO}" method="post">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="name" class="form-label">Название</label>
|
||||||
|
<input type="text" class="form-control" id="name" th:field="${appointmentDTO.name}" required="true">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<button type="submit" class="btn btn-primary button-fixed">
|
||||||
|
<span >Добавить</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
@ -19,8 +32,8 @@
|
|||||||
<tr th:each="appointment, iterator: ${appointments}">
|
<tr th:each="appointment, iterator: ${appointments}">
|
||||||
<td th:text="${appointment.id}"/>
|
<td th:text="${appointment.id}"/>
|
||||||
<td ><!--<td th:text="${appointment.name}"/>-->
|
<td ><!--<td th:text="${appointment.name}"/>-->
|
||||||
<form th:action="@{/appointment/edit/{id}(id=*{id})}" th:object="${appointment}" th:method="post">
|
<form th:action="@{/appointment/edit/{id}(id=*{id})}" th:object="${appointmentDTO}" th:method="post">
|
||||||
<input type="text" class="form-control" id="name" th:value="*{name}" style="width: 60%; display: inline-block" >
|
<input type="text" class="form-control" id="nameAppointment" th:field="${appointmentDTO.name}" th:value="${appointment.name}" style="width: 60%; display: inline-block" >
|
||||||
<button class="btn btn-warning button-fixed button-sm"
|
<button class="btn btn-warning button-fixed button-sm"
|
||||||
type="submit" style="display: inline-block"> Изменить
|
type="submit" style="display: inline-block"> Изменить
|
||||||
</button>
|
</button>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user