During the internship, we were given the task of creating a web application with authorization, registration, adding to friends and displaying a list of friends. Authorization and registration made on video (Spring security: https://www.youtube.com/watch?v=iivY8B5A0Tk&t=143s ).
To display friends made a separate jsp page at / freinds. All data is in the PostgreSQL database. There are 2 tables in the database:
users (id, login, password)
friends (first_friend (this is the user id from the first table), second_friend (also the id from the first table but a different user) and status) (status is a number from 0 to 2, 0 application, 1 accepted, 2 refused. Like is logical.
But implementation pumped up, because of that it is not familiar with Spring'om. How to connect user tables with friends table?
The user and friends tables are bound to the corresponding classes via @Entity.
@Entity @Table(name = "users") public class User { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @Column(name = "username") private String username; @Column(name = "password") private String password; and
@Entity @Table(name="friends") public class Friends { @Column(name = "friend_one") String friend_one; @Column(name = "friend_two") String friend_two; @Column(name ="status") int status; How to connect friend_one cells to id and friend_two to another id (is it a foreign key?) I don’t know how to access the database via Sql, and how to make a statement. Because authorization and registration are done through model or bean.
And tell me how to display data from the database on the jsp village. My example:
<table> <c:forEach items="${friends}" var="friend"> <tr> <td>${friend.username}</td> <td><input type="submit" name="action" value="delete"/></td> </tr> </c:forEach> </table>