i'm new on site , new in coding. struggling link 2 referencing competition user, , retrieve data database (i'm using mysql workbench). it's connected can't make work on localhost (gave me whitelabel error page). code or template needs correcting. thanks
@entity public class competition { @id @generatedvalue(strategy = generationtype.auto) private integer id; private string title; private string description; @onetomany(mappedby = "competition", targetentity = user.class) private list<user> users; public competition() {} public competition(integer id, string title, string description) { this.id = id; this.title = title; this.description = description; } public integer getid() { return id; } public string gettitle() { return title; } public string getdescription() { return description; } public list<user> getusers() { return users; }} ================================================== @entity public class user { @id @generatedvalue(strategy = generationtype.auto) private integer id_user; private string name; private string role; @manytoone(fetch=fetchtype.lazy) @joincolumn(name = "id") private competition competition; public user() {} public user(integer id_user, string name, string role) { this.id_user = id_user; this.name = name; this.role = role; } public integer getid_user() { return id_user; } public string getname() { return name; } public string getrole() { return role; } public competition getcompetition() { return competition; }} =================================================== public class competitionservice { @autowired competitionrepository competitionrepository; public list<competition> getallcompetitions(){ list<competition> competitions = new arraylist<>(); competitionrepository.findall().foreach(competitions :: add); return competitions; }} ========================================== public class userservice { @autowired private userrepository userrepository; public list<user> getallusers(){ list<user> users = new arraylist<>(); userrepository.findall().foreach(users :: add); return users; }} ===================================================== public interface competitionrepository extends crudrepository<competition, integer> { public list<competition> getallcompetitions(); } public interface userrepository extends crudrepository<user, integer>{} ===================================================== @controller public class competitioncontroller { @autowired private competitionservice competitionservice; @requestmapping(value = "/list", method = requestmethod.get) public string competitionlisting(model model) { model.addattribute("competitions", competitionservice.getallcompetitions()); return "list"; }} ======================================================= <!doctype html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="utf-8"/> <title>list of competitions</title> </head> <body> <h1>short competitions</h1> <table> <tr> <th>competition title</th> <th>description</th> </tr> <tr th:each="competition : ${competitions}"> <td><a th:href="@{'/competition/' + ${competition.id}}" th:text="${competition.title}">competition title</a></td> <td th:text="${competition.description}">competition description</td> </tr>> </table> </body> </html>
what exact error ? there problems finding path /list or error. can see services not annotated @service
, repositories (@repository
) can cause problem ( not pretty sure). please tell whats exact error ? when run app, @ console of ide stack trace.
cheers!
Comments
Post a Comment