package demo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.annotation.ComponentScan; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import java.util.Collection; import java.util.Date; import java.util.List; @ComponentScan @EnableJpaRepositories @EnableAutoConfiguration public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } interface ReservationRepository extends JpaRepository<Reservation, Long> { List<Reservation> findByFamilyName(String familyName); } @RestController @RequestMapping(value = "/reservations") class ReservationRestController { @Autowired ReservationRepository reservationRepository; @RequestMapping(method = RequestMethod.GET) Collection<Reservation> reservations() { return this.reservationRepository.findAll(); } } @Controller class ReservationMvcController { @Autowired ReservationRepository reservationRepository; @RequestMapping("/reservations.html") String reservations(Model model) { model.addAttribute("reservations", this.reservationRepository.findAll()); return "reservations"; } } @Entity class Reservation { @Id @GeneratedValue private Long id; private int groupSize = 1; private Date dateAndTime; private String familyName; @Override public String toString() { return "Reservation{" + "groupSize=" + groupSize + ", dateAndTime=" + dateAndTime + ", id=" + id + ", familyName='" + familyName + '\'' + '}'; } public int getGroupSize() { return groupSize; } public Date getDateAndTime() { return dateAndTime; } public Long getId() { return id; } public String getFamilyName() { return familyName; } }