mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-04-25 20:02:47 +00:00
fix: Add constant and improvement in PetClinic Signed-off-by: Sukhminder Arora <sukhminderarora@gmail.com>
Signed-off-by: Sukhminder Arora <sukhminderarora@gmail.com>
This commit is contained in:
parent
aa2273e955
commit
c2a2bab3f6
3 changed files with 28 additions and 30 deletions
|
@ -28,11 +28,11 @@ import jakarta.validation.constraints.NotBlank;
|
||||||
public class Person extends BaseEntity {
|
public class Person extends BaseEntity {
|
||||||
|
|
||||||
@Column(name = "first_name")
|
@Column(name = "first_name")
|
||||||
@NotBlank
|
@NotBlank(message = "First name is required")
|
||||||
private String firstName;
|
private String firstName;
|
||||||
|
|
||||||
@Column(name = "last_name")
|
@Column(name = "last_name")
|
||||||
@NotBlank
|
@NotBlank(message = "Last name is required")
|
||||||
private String lastName;
|
private String lastName;
|
||||||
|
|
||||||
public String getFirstName() {
|
public String getFirstName() {
|
||||||
|
|
|
@ -47,6 +47,7 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||||
class OwnerController {
|
class OwnerController {
|
||||||
|
|
||||||
private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm";
|
private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm";
|
||||||
|
public static final String REDIRECT_OWNERS = "redirect:/owners/";
|
||||||
|
|
||||||
private final OwnerRepository owners;
|
private final OwnerRepository owners;
|
||||||
|
|
||||||
|
@ -81,7 +82,7 @@ class OwnerController {
|
||||||
|
|
||||||
this.owners.save(owner);
|
this.owners.save(owner);
|
||||||
redirectAttributes.addFlashAttribute("message", "New Owner Created");
|
redirectAttributes.addFlashAttribute("message", "New Owner Created");
|
||||||
return "redirect:/owners/" + owner.getId();
|
return REDIRECT_OWNERS + owner.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/owners/find")
|
@GetMapping("/owners/find")
|
||||||
|
@ -108,7 +109,7 @@ class OwnerController {
|
||||||
if (ownersResults.getTotalElements() == 1) {
|
if (ownersResults.getTotalElements() == 1) {
|
||||||
// 1 owner found
|
// 1 owner found
|
||||||
owner = ownersResults.iterator().next();
|
owner = ownersResults.iterator().next();
|
||||||
return "redirect:/owners/" + owner.getId();
|
return REDIRECT_OWNERS + owner.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
// multiple owners found
|
// multiple owners found
|
||||||
|
|
|
@ -1,28 +1,25 @@
|
||||||
<html>
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
<body>
|
<!-- Define the fragment 'input' that takes label, name, and type as parameters -->
|
||||||
<form>
|
<th:block th:fragment="input(label, name, type)">
|
||||||
<th:block th:fragment="input (label, name, type)">
|
|
||||||
<div th:with="valid=${!#fields.hasErrors(name)}"
|
<div th:with="valid=${!#fields.hasErrors(name)}"
|
||||||
th:class="${'form-group' + (valid ? '' : ' has-error')}"
|
th:class="'form-group' + (valid ? '' : ' has-error')">
|
||||||
class="form-group">
|
|
||||||
<label class="col-sm-2 control-label" th:text="${label}">Label</label>
|
<label class="col-sm-2 control-label" th:text="${label}">Label</label>
|
||||||
<div class="col-sm-10">
|
<div class="col-sm-10">
|
||||||
<div th:switch="${type}">
|
<div th:switch="${type}">
|
||||||
|
<!-- For text input -->
|
||||||
<input th:case="'text'" class="form-control" type="text" th:field="*{__${name}__}" />
|
<input th:case="'text'" class="form-control" type="text" th:field="*{__${name}__}" />
|
||||||
<input th:case="'date'" class="form-control" type="date" th:field="*{__${name}__}"/>
|
<!-- For date input -->
|
||||||
|
<input th:case="'date'" class="form-control" type="date" th:field="*{__${name}__}" />
|
||||||
|
<!-- Add other input types as needed -->
|
||||||
</div>
|
</div>
|
||||||
<span th:if="${valid}"
|
<!-- Show a check icon if there are no errors -->
|
||||||
class="fa fa-ok form-control-feedback"
|
<span th:if="${valid}" class="fa fa-ok form-control-feedback" aria-hidden="true"></span>
|
||||||
aria-hidden="true"></span>
|
<!-- When there are errors, show an error icon and display error messages -->
|
||||||
<th:block th:if="${!valid}">
|
<th:block th:if="${!valid}">
|
||||||
<span
|
<span class="fa fa-remove form-control-feedback" aria-hidden="true"></span>
|
||||||
class="fa fa-remove form-control-feedback"
|
|
||||||
aria-hidden="true"></span>
|
|
||||||
<span class="help-inline" th:errors="*{__${name}__}">Error</span>
|
<span class="help-inline" th:errors="*{__${name}__}">Error</span>
|
||||||
</th:block>
|
</th:block>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</th:block>
|
</th:block>
|
||||||
</form>
|
|
||||||
</body>
|
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in a new issue