如何在所有人的列表中显示用户朋友?

时间:2014-07-02 05:18:53

标签: java spring hibernate jsp

Oookay,编辑问题。

我正在使用spring,hibernate和JSP。

SQL架构:

CREATE TABLE public.users
(
  uuid              VARCHAR(36) PRIMARY KEY                     NOT NULL,
  username          VARCHAR(45) UNIQUE                          NOT NULL,
  first_name        VARCHAR(255)                                NOT NULL,
  last_name         VARCHAR(255),
  middle_name       VARCHAR(255)
);



CREATE TABLE public.user_friends
(
  uuid          VARCHAR(36) PRIMARY KEY,
  user_uuid     VARCHAR(36) REFERENCES public.users (uuid) NOT NULL,
  friend_uuid   VARCHAR(36) REFERENCES public.users (uuid) NOT NULL,
  friendAddDate TIMESTAMP                                  NOT NULL,
  friendTypeId  INT                                        NOT NULL,
  CONSTRAINT friend_unique UNIQUE (user_uuid, friend_uuid)
);

Java实体:

@Entity
@Table(name = "users")
public class User implements Serializable {

    @Id
    @GeneratedValue(generator = "system-uuid", strategy = GenerationType.IDENTITY)
    @GenericGenerator(name = "system-uuid", strategy = "uuid2")
    @Column(name = "uuid", unique = true)
    protected String uuid;

    @Column(name = "username")
    protected String username;

    @JsonIgnore
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
    private Set<UserFriend> userFriends = new HashSet<>();
}

@Entity
@Table(name = "user_friends")
@AssociationOverrides({
        @AssociationOverride(name = "user",
                joinColumns = @JoinColumn(name = "user_uuid")),
        @AssociationOverride(name = "friendUser",
                joinColumns = @JoinColumn(name = "friend_uuid")) })
public class UserFriend implements Serializable {
    @Id
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "uuid2")
    @Column(name = "uuid", unique = true)
    protected String uuid;

    @ManyToOne
    @JoinColumn(name="user_uuid")
    private User user;

    @ManyToOne
    @JoinColumn(name="friend_uuid")
    private User friendUser;

    @Column(name = "friendadddate")
    protected Date friendAddDate;

    @Column(name = "friendtypeid")
    protected int friendTypeId;
}

现在我正在制作JSP页面,我将展示系统的所有用户。所以我有两套: 设置 - 系统的所有用户 和 设置 - 当前登录用户的朋友。

我希望在JSP上显示所有用户并标记为已登录用户的朋友的用户。 我想问一下:做什么最佳做法?

1 个答案:

答案 0 :(得分:1)

您需要在后端设置某种标记,该标记将在您的jsp页面中用于确定当前登录用户的朋友。如果标志存在则标记用户,否则您将正常进行。