小编tru*_*025的帖子

OneToMany 和 ManyToOne 映射 JPA/Hibernate

我有两个具有外键关系的表。我试过搜索如何做到这一点,它总是导致 OneToMany 和 ManyToOne 映射。我有这两张桌子。

用户角色

在此处输入图片说明

用户

在此处输入图片说明

我试图通过将位置列的值获取到 user_role 表来显示所有用户并显示他们的位置。

这些是我的课

用户.java

@Entity
@Table(name="user")
public class User {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    ..........

    private UserRole userRole;

    @ManyToOne()
    @JoinColumn(name="role_id")
    public UserRole getUserRole() {
        return userRole;
    }

    public void setUserRole(UserRole userRole) {
        this.userRole = userRole;
    }

    .......
}
Run Code Online (Sandbox Code Playgroud)

用户角色.java

@Entity
@Table(name="user_role")
public class UserRole {

    .......

    private List<User> user;

    @OneToMany(targetEntity=User.class, mappedBy="userRole",cascade=CascadeType.ALL, fetch = FetchType.LAZY)
    public List<User> getUser() {
        return user;
    }

    public void setUser(List<User> user) {
        this.user = user; …
Run Code Online (Sandbox Code Playgroud)

hibernate jpa one-to-many many-to-one spring-data-jpa

9
推荐指数
1
解决办法
7万
查看次数

TypeError:参数1对于URL.createObjectURL的任何1参数重载无效

我一直在使用getUserMedia从浏览器访问相机。我在几种浏览器上尝试过它,除了在Firefox上它可以工作。它适用于Chrome,avast,opera mini。这是我的代码:

<button type="button" onclick="turnOn()">turn on cam</button>
function turnOn() {
     document.getElementsByTagName('video')[0].play();

     var video = document.querySelector('video')
      , canvas;

    /**
     *  generates a still frame image from the stream in the <video>
     *  appends the image to the <body>
     */

    // use MediaDevices API
    // docs: https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia
    if (navigator.mediaDevices) {
      // access the web cam
       navigator.mediaDevices.getUserMedia({video: true})
      // permission granted:
        .then(function(stream) {
          video.src = window.URL.createObjectURL(stream);
          /* video.addEventListener('click', takeSnapshot); */
        })
        // permission denied:
        .catch(function(error) {
          document.body.textContent = 'Could not access the camera. …
Run Code Online (Sandbox Code Playgroud)

javascript getusermedia

7
推荐指数
1
解决办法
7099
查看次数