Hej,
Mam problem z moją aplikacją, szukałam już wszędzie i dalej nie wiem w czym problem.. W ramach nauki/treningu chcę zrobić aplikację gdzie użytkownicy będą mieć możliwość rejestracji, wypożyczenia skuterów wodnych, jachtów i takie tam. Już na starcie chciałam w nav barze pod adresem /skutery po prostu wyświetlić listę skuterów i w konsoli H2 widzę swoje dane testowe, a przy prostej metodzie findAll() z JpaRepository mi ich nie wyświetla, co robię nie tak?
master.xml:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.2.xsd">
<include file="0001_create_table_jetski.xml" relativeToChangelogFile="true"/>
<include file="0002_create_table_yacht.xml" relativeToChangelogFile="true"/>
<include file="0003_create_table_member.xml" relativeToChangelogFile="true"/>
<!-- TEST DATA -->
<include file="../testdata/0001_jetskis.sql" relativeToChangelogFile="true" context="dev"/>
<include file="../testdata/0002_yachts.sql" relativeToChangelogFile="true" context="dev"/>
<include file="../testdata/0003_members.sql" relativeToChangelogFile="true" context="dev"/>
</databaseChangeLog>
0001_jetskis.sql:
INSERT INTO
jetski (name, producer, max_speed, production_year, img, seats)
VALUES
('Spark 2-up', 'Sea-Doo', 90, 2023, 'https://www.brp-world.com/content/brp-world/pl_pl/nasze-produkty/sea-doo/modele_2021/spark/_jcr_content/root/feature_teaser.coreimg.png/1647631348517/sea-my21-reclt-spark-90-3up-conv-pack-ss-dazzling-blue-manta-green-34frt-lr.png', 2),
('GP HO','Yamaha', 110, 2022, 'https://cdn2.yamaha-motor.eu/prod/product-assets/2024/GPHO/2024-Yamaha-GPHO-EU-Black_Solid-Studio-001-03.jpg', 3),
('RXT X','Sea-Doo', 180, 2023, 'https://www.motoar.pl/4125-2274217931-large/10PE%20%20%282%29.webp', 3),
('F-15', 'Honda', 90, 2019, 'https://www.personalwatercraft.com/gallery/specs.php/d/6879-2/default.jpg', 2),
('JetBlaster', 'Yamaha', 90, 2022, 'https://cdn2.yamaha-motor.eu/prod/product-assets/2024/JETBLASTER/2024-Yamaha-JETBLASTER-EU-Deep_Purplish_Blue_Metallic-Studio-001-03.jpg', 2),
('RXP-X', 'Sea-Doo', 90, 2021, 'https://www.brp-world.com/content/brp-world/pl_pl/nasze-produkty/sea-doo/modele_2021/rxp-x/_jcr_content/root/feature_teaser_copy.coreimg.png/1647631354144/sea-my21-perf-rxp-x-300-1up-without-ss-midnight-purple-34frt-lr.png', 2);
JetskitRepository:
import com.jachtekipa.jetskiclub.model.watercraft.jetski.Jetski;
import org.springframework.data.jpa.repository.JpaRepository;
public interface JetskiRepository extends JpaRepository<Jetski, Long> {
}
JetskiService:
import com.jachtekipa.jetskiclub.model.watercraft.jetski.Jetski;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class JetskiService {
private JetskiRepository jetskiRepository;
public JetskiService(JetskiRepository jetskiRepository) {
this.jetskiRepository = jetskiRepository;
}
public List<Jetski> findAllJetskis() {
return jetskiRepository.findAll();
}
}
HomeController:
import com.jachtekipa.jetskiclub.model.watercraft.dto.YachtDto;
import com.jachtekipa.jetskiclub.model.watercraft.jetski.Jetski;
import com.jachtekipa.jetskiclub.model.watercraft.yacht.YachtService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.List;
@Controller
public class HomeController {
private JetskiService jetskiService;
private YachtService yachtService;
public HomeController(JetskiService jetskiService, YachtService yachtService) {
this.jetskiService = jetskiService;
this.yachtService = yachtService;
}
@GetMapping("/")
public String home() {
return "home";
}
@GetMapping("/skutery")
public String showJetskis(Model model) {
List<Jetski> jetskis = jetskiService.findAllJetskis();
model.addAttribute("jetskis", jetskis);
return "jetski-list";
}
Jetski:
import com.jachtekipa.jetskiclub.model.watercraft.Watercraft;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import java.time.Year;
@Entity
public class Jetski extends Watercraft {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private int seats;
public Jetski() {
}
public Jetski(String name, String producer, int maxSpeed, Year productionYear, String img, Long id, int seats) {
super(name, producer, maxSpeed, productionYear, img);
this.id = id;
this.seats = seats;
}
//gettery & settery
application.yml:
spring:
jpa:
hibernate:
ddl-auto: validate
application-dev.yml:
spring:
datasource:
url: jdbc:h2:mem:test
liquibase:
contexts: dev
change-log: classpath:db/changelog/master.xml