mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-21 15:25:49 +00:00
Merge branch 'spring-projects:main' into main
This commit is contained in:
commit
2a08ab24f1
9 changed files with 91 additions and 16 deletions
31
build.gradle
31
build.gradle
|
@ -3,10 +3,12 @@ plugins {
|
|||
id 'org.springframework.boot' version '3.2.0'
|
||||
id 'io.spring.dependency-management' version '1.1.4'
|
||||
id 'org.graalvm.buildtools.native' version '0.9.28'
|
||||
id 'io.spring.javaformat' version '0.0.40'
|
||||
id 'io.spring.javaformat' version '0.0.41'
|
||||
id "io.spring.nohttp" version "0.0.11"
|
||||
}
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'checkstyle'
|
||||
apply plugin: 'io.spring.javaformat'
|
||||
|
||||
gradle.startParameter.excludedTaskNames += [ "checkFormatAot", "checkFormatAotTest" ]
|
||||
|
@ -43,8 +45,35 @@ dependencies {
|
|||
testImplementation 'org.springframework.boot:spring-boot-docker-compose'
|
||||
testImplementation 'org.testcontainers:junit-jupiter'
|
||||
testImplementation 'org.testcontainers:mysql'
|
||||
checkstyle 'io.spring.javaformat:spring-javaformat-checkstyle:0.0.41'
|
||||
checkstyle 'com.puppycrawl.tools:checkstyle:10.12.5'
|
||||
}
|
||||
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
checkstyle {
|
||||
configDirectory = project.file('src/checkstyle')
|
||||
configFile = file('src/checkstyle/nohttp-checkstyle.xml')
|
||||
}
|
||||
|
||||
checkstyleNohttp {
|
||||
configDirectory = project.file('src/checkstyle')
|
||||
configFile = file('src/checkstyle/nohttp-checkstyle.xml')
|
||||
}
|
||||
|
||||
tasks.named("formatMain").configure { dependsOn("checkstyleMain") }
|
||||
tasks.named("formatMain").configure { dependsOn("checkstyleNohttp") }
|
||||
|
||||
tasks.named("formatTest").configure { dependsOn("checkstyleTest") }
|
||||
tasks.named("formatTest").configure { dependsOn("checkstyleNohttp") }
|
||||
|
||||
checkstyleAot.enabled = false
|
||||
checkstyleAotTest.enabled = false
|
||||
|
||||
checkFormatAot.enabled = false
|
||||
checkFormatAotTest.enabled = false
|
||||
|
||||
formatAot.enabled = false
|
||||
formatAotTest.enabled = false
|
||||
|
|
4
pom.xml
4
pom.xml
|
@ -237,10 +237,12 @@
|
|||
<phase>validate</phase>
|
||||
<configuration>
|
||||
<configLocation>src/checkstyle/nohttp-checkstyle.xml</configLocation>
|
||||
<suppressionsLocation>src/checkstyle/nohttp-checkstyle-suppressions.xml</suppressionsLocation>
|
||||
<sourceDirectories>${basedir}</sourceDirectories>
|
||||
<includes>**/*</includes>
|
||||
<excludes>**/.git/**/*,**/.idea/**/*,**/target/**/,**/.flattened-pom.xml,**/*.class</excludes>
|
||||
<propertyExpansion>
|
||||
config_loc=${basedir}/src/checkstyle/
|
||||
</propertyExpansion>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>check</goal>
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
|
||||
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
|
||||
<suppressions>
|
||||
<suppress files="node_modules/.*" checks=".*"/>
|
||||
<suppress files="node/.*" checks=".*"/>
|
||||
<suppress files="build/.*" checks=".*"/>
|
||||
<suppress files="node_modules[\\/].*" checks=".*"/>
|
||||
<suppress files="node[\\/].*" checks=".*"/>
|
||||
<suppress files="build[\\/].*" checks=".*"/>
|
||||
<suppress files="target[\\/].*" checks=".*"/>
|
||||
<suppress files=".+\.(jar|git|ico|p12|gif|jks|jpg|svg|log)" checks="NoHttp"/>
|
||||
</suppressions>
|
||||
|
|
|
@ -4,4 +4,7 @@
|
|||
"https://checkstyle.org/dtds/configuration_1_2.dtd">
|
||||
<module name="com.puppycrawl.tools.checkstyle.Checker">
|
||||
<module name="io.spring.nohttp.checkstyle.check.NoHttpCheck"/>
|
||||
<module name="SuppressionFilter">
|
||||
<property name="file" value="${config_loc}/nohttp-checkstyle-suppressions.xml"/>
|
||||
</module>
|
||||
</module>
|
||||
|
|
|
@ -18,7 +18,11 @@ package org.springframework.samples.petclinic;
|
|||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ImportRuntimeHints;
|
||||
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* PetClinic Spring Boot Application.
|
||||
|
|
|
@ -17,7 +17,7 @@ package org.springframework.samples.petclinic.owner;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
@ -34,6 +34,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
|
@ -70,12 +71,14 @@ class OwnerController {
|
|||
}
|
||||
|
||||
@PostMapping("/owners/new")
|
||||
public String processCreationForm(@Valid Owner owner, BindingResult result) {
|
||||
public String processCreationForm(@Valid Owner owner, BindingResult result, RedirectAttributes redirectAttributes) {
|
||||
if (result.hasErrors()) {
|
||||
redirectAttributes.addFlashAttribute("error", "There was an error in creating the owner.");
|
||||
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
|
||||
this.owners.save(owner);
|
||||
redirectAttributes.addFlashAttribute("message", "New Owner Created");
|
||||
return "redirect:/owners/" + owner.getId();
|
||||
}
|
||||
|
||||
|
@ -133,14 +136,16 @@ class OwnerController {
|
|||
}
|
||||
|
||||
@PostMapping("/owners/{ownerId}/edit")
|
||||
public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result,
|
||||
@PathVariable("ownerId") int ownerId) {
|
||||
public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result, @PathVariable("ownerId") int ownerId,
|
||||
RedirectAttributes redirectAttributes) {
|
||||
if (result.hasErrors()) {
|
||||
redirectAttributes.addFlashAttribute("error", "There was an error in updating the owner.");
|
||||
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
|
||||
owner.setId(ownerId);
|
||||
this.owners.save(owner);
|
||||
redirectAttributes.addFlashAttribute("message", "Owner Values Updated");
|
||||
return "redirect:/owners/{ownerId}";
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
|
@ -98,7 +99,8 @@ class PetController {
|
|||
}
|
||||
|
||||
@PostMapping("/pets/new")
|
||||
public String processCreationForm(Owner owner, @Valid Pet pet, BindingResult result, ModelMap model) {
|
||||
public String processCreationForm(Owner owner, @Valid Pet pet, BindingResult result, ModelMap model,
|
||||
RedirectAttributes redirectAttributes) {
|
||||
if (StringUtils.hasText(pet.getName()) && pet.isNew() && owner.getPet(pet.getName(), true) != null) {
|
||||
result.rejectValue("name", "duplicate", "already exists");
|
||||
}
|
||||
|
@ -115,18 +117,21 @@ class PetController {
|
|||
}
|
||||
|
||||
this.owners.save(owner);
|
||||
redirectAttributes.addFlashAttribute("message", "New Pet has been Added");
|
||||
return "redirect:/owners/{ownerId}";
|
||||
}
|
||||
|
||||
@GetMapping("/pets/{petId}/edit")
|
||||
public String initUpdateForm(Owner owner, @PathVariable("petId") int petId, ModelMap model) {
|
||||
public String initUpdateForm(Owner owner, @PathVariable("petId") int petId, ModelMap model,
|
||||
RedirectAttributes redirectAttributes) {
|
||||
Pet pet = owner.getPet(petId);
|
||||
model.put("pet", pet);
|
||||
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
|
||||
@PostMapping("/pets/{petId}/edit")
|
||||
public String processUpdateForm(@Valid Pet pet, BindingResult result, Owner owner, ModelMap model) {
|
||||
public String processUpdateForm(@Valid Pet pet, BindingResult result, Owner owner, ModelMap model,
|
||||
RedirectAttributes redirectAttributes) {
|
||||
|
||||
String petName = pet.getName();
|
||||
|
||||
|
@ -150,6 +155,7 @@ class PetController {
|
|||
|
||||
owner.addPet(pet);
|
||||
this.owners.save(owner);
|
||||
redirectAttributes.addFlashAttribute("message", "Pet details has been edited");
|
||||
return "redirect:/owners/{ownerId}";
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
|
@ -81,13 +82,14 @@ class VisitController {
|
|||
// called
|
||||
@PostMapping("/owners/{ownerId}/pets/{petId}/visits/new")
|
||||
public String processNewVisitForm(@ModelAttribute Owner owner, @PathVariable int petId, @Valid Visit visit,
|
||||
BindingResult result) {
|
||||
BindingResult result, RedirectAttributes redirectAttributes) {
|
||||
if (result.hasErrors()) {
|
||||
return "pets/createOrUpdateVisitForm";
|
||||
}
|
||||
|
||||
owner.addVisit(petId, visit);
|
||||
this.owners.save(owner);
|
||||
redirectAttributes.addFlashAttribute("message", "Your vist has been boked");
|
||||
return "redirect:/owners/{ownerId}";
|
||||
}
|
||||
|
||||
|
|
|
@ -7,8 +7,18 @@
|
|||
|
||||
|
||||
<h2>Owner Information</h2>
|
||||
|
||||
|
||||
|
||||
<div th:if="${message}" class="alert alert-success" id="success-message">
|
||||
<span th:text="${message}"></span>
|
||||
</div>
|
||||
|
||||
<div th:if="${error}" class="alert alert-danger" id="error-message">
|
||||
<span th:text="${error}"></span>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<table class="table table-striped" th:object="${owner}">
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
|
@ -73,7 +83,20 @@
|
|||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
<script>
|
||||
// Function to hide the success and error messages after 3 seconds
|
||||
function hideMessages() {
|
||||
setTimeout(function() {
|
||||
document.getElementById("success-message").style.display = "none";
|
||||
document.getElementById("error-message").style.display = "none";
|
||||
}, 3000); // 3000 milliseconds (3 seconds)
|
||||
}
|
||||
|
||||
// Call the function to hide messages
|
||||
hideMessages();
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
|
||||
</html>
|
||||
|
|
Loading…
Reference in a new issue