-
Notifications
You must be signed in to change notification settings - Fork 29.4k
Pet controller success msg #2362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
708288e
da1f7a4
19c5f46
13db3ee
deca6f1
70b427c
b774500
d8c55de
94fc35a
2c83887
a0fa874
b38e86a
b8af30f
2ce65df
6ae9627
efd7941
6fbd3da
967aae1
448eb19
9be2311
993eb5f
39a503d
685c828
1b84c1c
392c2b3
6cb6757
4fef434
bce820f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -121,7 +121,7 @@ public String processCreationForm(Owner owner, @Valid Pet pet, BindingResult res | |||||
|
|
||||||
| owner.addPet(pet); | ||||||
| this.owners.save(owner); | ||||||
| redirectAttributes.addFlashAttribute("message", "New Pet has been Added"); | ||||||
| redirectAttributes.addFlashAttribute("message", "Pet added successfully."); | ||||||
| return "redirect:/owners/{ownerId}"; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -154,7 +154,7 @@ public String processUpdateForm(Owner owner, @Valid Pet pet, BindingResult resul | |||||
| } | ||||||
|
|
||||||
| updatePetDetails(owner, pet); | ||||||
| redirectAttributes.addFlashAttribute("message", "Pet details has been edited"); | ||||||
| redirectAttributes.addFlashAttribute("message", "Pet details updated successfully."); | ||||||
|
||||||
| redirectAttributes.addFlashAttribute("message", "Pet details updated successfully."); | |
| redirectAttributes.addFlashAttribute("message", "Pet Details Updated"); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,58 +1,69 @@ | ||
| /* | ||
| * Copyright 2012-2025 the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.springframework.samples.petclinic.vet; | ||
|
|
||
|
Comment on lines
16
to
17
|
||
| import org.springframework.cache.annotation.Cacheable; | ||
| import org.springframework.dao.DataAccessException; | ||
| import java.util.List; | ||
|
|
||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.PageRequest; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.data.repository.Repository; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.util.Collection; | ||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.ui.Model; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.bind.annotation.ResponseBody; | ||
|
|
||
| /** | ||
| * Repository class for <code>Vet</code> domain objects All method names are compliant | ||
| * with Spring Data naming conventions so this interface can easily be extended for Spring | ||
| * Data. See: | ||
| * https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-creation | ||
| * | ||
| * @author Ken Krebs | ||
| * @author Juergen Hoeller | ||
| * @author Sam Brannen | ||
| * @author Michael Isvy | ||
| * @author Mark Fisher | ||
| * @author Ken Krebs | ||
| * @author Arjen Poutsma | ||
| */ | ||
| public interface VetRepository extends Repository<Vet, Integer> { | ||
|
|
||
| /** | ||
| * Retrieve all <code>Vet</code>s from the data store. | ||
| * @return a <code>Collection</code> of <code>Vet</code>s | ||
| */ | ||
| @Transactional(readOnly = true) | ||
| @Cacheable("vets") | ||
| Collection<Vet> findAll() throws DataAccessException; | ||
|
|
||
| /** | ||
| * Retrieve all <code>Vet</code>s from data store in Pages | ||
| * @param pageable | ||
| * @return | ||
| * @throws DataAccessException | ||
| */ | ||
| @Transactional(readOnly = true) | ||
| @Cacheable("vets") | ||
| Page<Vet> findAll(Pageable pageable) throws DataAccessException; | ||
|
|
||
| } | ||
| @Controller | ||
| class VetController { | ||
|
|
||
| private static final int PAGE_SIZE = 5; | ||
|
|
||
|
||
| private final VetRepository vetRepository; | ||
|
|
||
| public VetController(VetRepository vetRepository) { | ||
| this.vetRepository = vetRepository; | ||
|
||
| } | ||
|
|
||
| @GetMapping("/vets.html") | ||
| public String showVetList(@RequestParam(defaultValue = "1") int page, Model model) { | ||
| int currentPage = Math.max(page, 1); | ||
|
|
||
| // Here we are returning an object of type 'Vets' rather than a collection of Vet | ||
| // objects so it is simpler for Object-Xml mapping | ||
| Vets vets = new Vets(); | ||
| Page<Vet> paginated = findPaginated(currentPage); | ||
| vets.getVetList().addAll(paginated.toList()); | ||
|
|
||
| return addPaginationModel(currentPage, paginated, model); | ||
| } | ||
|
|
||
| private String addPaginationModel(int page, Page<Vet> paginated, Model model) { | ||
| List<Vet> listVets = paginated.getContent(); | ||
| model.addAttribute("currentPage", page); | ||
| model.addAttribute("totalPages", paginated.getTotalPages()); | ||
| model.addAttribute("totalItems", paginated.getTotalElements()); | ||
| model.addAttribute("listVets", listVets); | ||
| model.addAttribute("hasNext", paginated.hasNext()); | ||
| model.addAttribute("hasPrevious", paginated.hasPrevious()); | ||
| return "vets/vetList"; | ||
| } | ||
|
|
||
| private Page<Vet> findPaginated(int page) { | ||
| Pageable pageable = PageRequest.of(page - 1, PAGE_SIZE); | ||
| return vetRepository.findAll(pageable); | ||
| } | ||
|
|
||
| @GetMapping({ "/vets" }) | ||
| public @ResponseBody Vets showResourcesVetList() { | ||
| // Here we are returning an object of type 'Vets' rather than a collection of Vet | ||
| // objects so it is simpler for JSon/Object mapping | ||
| Vets vets = new Vets(); | ||
| vets.getVetList().addAll(this.vetRepository.findAll()); | ||
| return vets; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,13 +4,13 @@ | |||||||||
|
|
||||||||||
| <body> | ||||||||||
|
|
||||||||||
| <h2 th:text="#{vets}">Veterinarians</h2> | ||||||||||
| <h2 th:text="#{vets}">Veterinarian Directory</h2> | ||||||||||
|
||||||||||
| <h2 th:text="#{vets}">Veterinarian Directory</h2> | |
| <h2 th:text="#{vets}">Vets</h2> |
Copilot
AI
Apr 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These header text changes are only fallbacks; the actual rendered text comes from #{name} and #{specialties} (both defined in messages*.properties), so the page will still display the translated "Name" / "Specialties" strings. If you want the UI to read "Veterinarian Name" / "Areas of Expertise", introduce dedicated message keys (and translations) or change the existing message values (not just the fallback text).
| <th th:text="#{name}">Veterinarian Name</th> | |
| <th th:text="#{specialties}">Areas of Expertise</th> | |
| <th th:text="'Veterinarian Name'">Veterinarian Name</th> | |
| <th th:text="'Areas of Expertise'">Areas of Expertise</th> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These success messages now use sentence case with trailing periods, but other controllers use title case without punctuation (e.g.,
OwnerController: "New Owner Created",VisitController: "Your visit has been booked"). Consider aligning the message style across controllers for consistent UI, or move these to i18n message bundles if you want more control over copy/translation.