当前位置: 首页 > 知识库问答 >
问题:

缺少用户类-在Microservice中创建与用户实体的实体关系

祁烨
2023-03-14

我想创建一个与JHipster的用户实体有多对一关系的实体。

我使用JDL-Studio创建了以下实体和与用户的关系,它使用jhipster port-jdl作为. jh文件导入到我的微服务中:

entity Profile {
    name String required
    bio String
    location String
    photo ImageBlob
}

relationship ManyToOne {
    Profile{user} to User
}

angularSuffix * with mySuffix

dto * with mapstruct

在编译我的微服务时,我得到以下错误:

轮廓java:44:错误:找不到符号私人用户;符号:类用户位置:类配置文件

轮廓映射器。java:12:错误:找不到symbol@Mapper(componentModel=“spring”,uses={UserMapper.class,})symbol:class UserMapper

轮廓映射器。java:12:错误:无法检索@Mapper annotation@Mapper(componentModel=“spring”,uses={UserMapper.class,})

剖面图第43-44行。java是:

@ManyToOne
private User user;

ProfileMapper.java如下:

package com.moogrisoft.openseas.service.mapper;

import com.moogrisoft.openseas.domain.*;
import com.moogrisoft.openseas.service.dto.ProfileDTO;

import org.mapstruct.*;
import java.util.List;

/**
 * Mapper for the entity Profile and its DTO ProfileDTO.
 */
@Mapper(componentModel = "spring", uses = {UserMapper.class, })
public interface ProfileMapper {

    @Mapping(source = "user.id", target = "userId")
    ProfileDTO profileToProfileDTO(Profile profile);

    List<ProfileDTO> profilesToProfileDTOs(List<Profile> profiles);

    @Mapping(source = "userId", target = "user")
    Profile profileDTOToProfile(ProfileDTO profileDTO);

    List<Profile> profileDTOsToProfiles(List<ProfileDTO> profileDTOs);
    /**
     * generating the fromId for all mappers if the databaseType is sql, as the class has relationship to it might need it, instead of
     * creating a new attribute to know if the entity has any relationship from some other entity
     *
     * @param id id of the entity
     * @return the entity instance
     */

    default Profile profileFromId(Long id) {
        if (id == null) {
            return null;
        }
        Profile profile = new Profile();
        profile.setId(id);
        return profile;
    }


}

在我的项目中没有UserMapper类,因为没有为我生成。

如果我创建一个单片应用程序,那么创建实体关系就可以了,这只是一个微服务的问题,因为缺少用户类和相关类。

共有1个答案

胡彭亮
2023-03-14

在JHipster微服务体系结构中,用户实体位于网关或UAA服务上。

配置文件实体

在UAA中,您可以创建与用户有关系的实体。向实体添加配置文件等附加信息是一个很好的用例。在网关中做同样的事情也是可能的。可以看到创建与用户有关系的实体的示例UAAhttps://github.com/xetys/microxchng-workshop/tree/master/uaa

博客实体

在微服务体系结构中,使用实体子生成器的工作方式略有不同,因为前端和后端代码不位于同一个应用程序中。https://jhipster.github.io/microservices-architecture/#generating_entities

对于这种类型的实体,我建议将用户的ID与实体一起存储。您将需要从客户端传递用户ID,因为该ID不容易从微服务访问。我们使用用户ID而不是登录的原因是登录可以通过用户管理页面进行修改,导致关系失败(从旧的登录值)。

另一个选项是使用userLogin,它可以通过SecurityU在微服务中访问tils.java.只要您处理登录可以更改,这是另一个选项。

 类似资料:
  • 好的,我知道错误了。但是在JHipster的情况下,我不能更改表名。 有人能帮我吗?

  • 阅读本文以了解在 Dreamweaver 中如何指定缺少的字符实体来替换 XSLT 的特殊字符。 注意:用户界面已经在 Dreamweaver CC 和更高版本中做了简化。因此,您可能在 Dreamweaver CC 和更高版本中找不到本文中描述的一些选项。有关详细信息,请参阅此文章。 指定缺少的字符实体 在 XSLT 中,某些上下文中不允许存在某些字符。例如,您无法在标签之间的文本或属性值中使用

  • 我对Spring和JPA等比较陌生。我试图在标签和客户之间建立一种多对多的关系(双向) 我想我的关系是对的。除了一个问题外,一切都很好。标记值保存到数据库后为“Null”。 因此,我要做的是——向客户添加一个新的标签列表,然后在保存客户时使用级联选项来保存它。在调用CustomerRepository之前,我设置了一个调试点。保存(customer),标记都有值。在保存操作(在客户存储库上)后,我

  • 我正在创建医生、患者和专科三张表。患者可以有一个全科医生,但一个医生可以是许多患者的全科医生。每个医生都有自己的专长(例如神经外科医生、心脏病专家、泌尿科医生等)。当我尝试使用中间表在医生和专长之间建立多对多连接时,我会遇到一个错误“创建名为“entityManagerFactory”的bean时出错,该bean在类路径资源中定义”由特定mappedBy引用未知目标实体属性中的BeanCreati

  • 我有个问题。当我有其他实体时,我不知道如何创建API。我与邮递员工作,当我做一个请求,以看到所有项目从数据库,我想收到实体也。 例如,这是我的实体:

  • 我试图测试mvcControllers注入UserPrincipal的访问: restPockMockMvc.perform(get(“/pocs”).principal(authToken)).andreturn();