<tfoot id='cOc8i'></tfoot>
  • <legend id='cOc8i'><style id='cOc8i'><dir id='cOc8i'><q id='cOc8i'></q></dir></style></legend>

    <small id='cOc8i'></small><noframes id='cOc8i'>

    <i id='cOc8i'><tr id='cOc8i'><dt id='cOc8i'><q id='cOc8i'><span id='cOc8i'><b id='cOc8i'><form id='cOc8i'><ins id='cOc8i'></ins><ul id='cOc8i'></ul><sub id='cOc8i'></sub></form><legend id='cOc8i'></legend><bdo id='cOc8i'><pre id='cOc8i'><center id='cOc8i'></center></pre></bdo></b><th id='cOc8i'></th></span></q></dt></tr></i><div id='cOc8i'><tfoot id='cOc8i'></tfoot><dl id='cOc8i'><fieldset id='cOc8i'></fieldset></dl></div>

        • <bdo id='cOc8i'></bdo><ul id='cOc8i'></ul>
      1. 如何在 Spring Data REST 中公开 @EmbeddedId 转换器

        时间:2024-08-24
          <bdo id='stlL0'></bdo><ul id='stlL0'></ul>
        • <i id='stlL0'><tr id='stlL0'><dt id='stlL0'><q id='stlL0'><span id='stlL0'><b id='stlL0'><form id='stlL0'><ins id='stlL0'></ins><ul id='stlL0'></ul><sub id='stlL0'></sub></form><legend id='stlL0'></legend><bdo id='stlL0'><pre id='stlL0'><center id='stlL0'></center></pre></bdo></b><th id='stlL0'></th></span></q></dt></tr></i><div id='stlL0'><tfoot id='stlL0'></tfoot><dl id='stlL0'><fieldset id='stlL0'></fieldset></dl></div>
          <tfoot id='stlL0'></tfoot>

                <tbody id='stlL0'></tbody>

                <legend id='stlL0'><style id='stlL0'><dir id='stlL0'><q id='stlL0'></q></dir></style></legend>

                  <small id='stlL0'></small><noframes id='stlL0'>

                  本文介绍了如何在 Spring Data REST 中公开 @EmbeddedId 转换器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有些实体具有复合主键,并且这些实体在暴露时具有不正确的链接,在 _links 内的 URL 中具有类的完整限定名称

                  There are some Entities with composite Primary Keys and these entities when exposed are having incorrect Links having full qualified name of classes in URL inside _links

                  点击链接也会出现此类错误 -

                  Also clicking on links gives such errors -

                  org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type java.lang.String to type com.core.connection.domains.UserFriendshipId
                  

                  我有 XML 配置的 Spring Repository 并启用了 jpa:repositories 并且 Respository 从 JpaRepository 扩展

                  I have XML configured Spring Repository with jpa:repositories enabled and Respository extending from JpaRepository

                  我可以让 Repository 实现 org.springframework.core.convert.converter.Converter 来处理这个问题.目前正在获取如下链接-

                  Can I make Repository implement org.springframework.core.convert.converter.Converter to handle this. Currently getting links as below -

                  _links: {
                  userByFriendshipId: {
                  href: "http://localhost:8080/api/userFriendships/com.core.connection.domains.UserFriendshipId@5b10/userByFriendId"
                  }
                  

                  在 xml 配置中,我启用了 jpa:repositories 并在 Repositories 中启用了 @RestResource

                  in xml config , I have jpa:repositories enabled and @RestResource enabled inside Repositories

                  推荐答案

                  首先你需要得到一个可用的链接.目前,您的复合 ID 公开为 com.core.connection.domains.UserFriendshipId@5b10.重写 UserFriendshipIdtoString 方法应该足以生成像 2-3 这样有用的东西.

                  At first you need to get a usable link. Currently your composite id is exposed as com.core.connection.domains.UserFriendshipId@5b10. It should be enough to override the toString method of UserFriendshipIdto produce something useful like 2-3.

                  接下来你需要实现一个转换器 以便 2-3 可以转换回 UserFriendshipId:

                  Next you need to implement a converter so that 2-3 can be converted back to a UserFriendshipId:

                  class UserFriendShipIdConverter implements Converter<String, UserFriendshipId> {
                  
                    UserFriendShipId convert(String id) {
                      ...
                    }
                  }
                  

                  最后你需要注册转换器.您已经建议覆盖 configureConversionService:

                  Finally you need to register the converter. You already suggested to override configureConversionService:

                  protected void configureConversionService(ConfigurableConversionService conversionService) {
                     conversionService.addConverter(new UserFriendShipIdConverter());
                  } 
                  

                  如果您更喜欢 XML 配置,您可以按照 文档.

                  If you prefer a XML configuration you can follow the instructions in the documentation.

                  这篇关于如何在 Spring Data REST 中公开 @EmbeddedId 转换器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Spring Data 不处理 Pageable 动作参数创建 下一篇:Spring Data Repository @Query - 更新并返回修改后的实体

                  相关文章

                • <small id='sh3fV'></small><noframes id='sh3fV'>

                  <legend id='sh3fV'><style id='sh3fV'><dir id='sh3fV'><q id='sh3fV'></q></dir></style></legend>

                  <i id='sh3fV'><tr id='sh3fV'><dt id='sh3fV'><q id='sh3fV'><span id='sh3fV'><b id='sh3fV'><form id='sh3fV'><ins id='sh3fV'></ins><ul id='sh3fV'></ul><sub id='sh3fV'></sub></form><legend id='sh3fV'></legend><bdo id='sh3fV'><pre id='sh3fV'><center id='sh3fV'></center></pre></bdo></b><th id='sh3fV'></th></span></q></dt></tr></i><div id='sh3fV'><tfoot id='sh3fV'></tfoot><dl id='sh3fV'><fieldset id='sh3fV'></fieldset></dl></div>

                    • <bdo id='sh3fV'></bdo><ul id='sh3fV'></ul>

                    <tfoot id='sh3fV'></tfoot>