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

    • <bdo id='4hl7L'></bdo><ul id='4hl7L'></ul>

  • <legend id='4hl7L'><style id='4hl7L'><dir id='4hl7L'><q id='4hl7L'></q></dir></style></legend>

      1. <small id='4hl7L'></small><noframes id='4hl7L'>

        <tfoot id='4hl7L'></tfoot>
      2. CRUDRepository 中的 Update 或 saveorUpdate

        Update or saveorUpdate in CRUDRepository(CRUDRepository 中的 Update 或 saveorUpdate)
          <i id='t1mmm'><tr id='t1mmm'><dt id='t1mmm'><q id='t1mmm'><span id='t1mmm'><b id='t1mmm'><form id='t1mmm'><ins id='t1mmm'></ins><ul id='t1mmm'></ul><sub id='t1mmm'></sub></form><legend id='t1mmm'></legend><bdo id='t1mmm'><pre id='t1mmm'><center id='t1mmm'></center></pre></bdo></b><th id='t1mmm'></th></span></q></dt></tr></i><div id='t1mmm'><tfoot id='t1mmm'></tfoot><dl id='t1mmm'><fieldset id='t1mmm'></fieldset></dl></div>

              <bdo id='t1mmm'></bdo><ul id='t1mmm'></ul>

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

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

                1. 本文介绍了CRUDRepository 中的 Update 或 saveorUpdate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我知道之前已经回答了一个类似的问题,但我的问题是在界面中有 3 个方法时使用更新实现保存.我目前在我的项目中使用以下方法,但不知道如何在其中进行 saveOrUpdate.以下是我的课程:

                  I know there's already a similar question answered previously, but my problem is implementing save with update while there are 3 methods in the interface. I'm currently using the following methods in my project and don't know how to make saveOrUpdate in this. The following are my classes:

                     public interface CompanyRepository extends CrudRepository<Company,Long>{
                     Company findByCompanyName (String companyName);
                     List<Company> findAll();
                     Company findById(Long id);
                     }
                  

                  以下是我的公司课程的一部分

                  The following is part of my Company Class

                  @Entity
                  public class Company extends BaseEntity{
                   @NotNull
                  @Size(min = 2, max = 16)
                  private String companyName;
                  @Length(max = 60)
                  private String desc;
                  //TODO max: add LOGO class later for pic saving
                  @OneToMany
                  private List<MobileModel> mobileModels;
                  
                  public Company()
                  {
                    super();
                    mobileModels = new ArrayList<>();
                    }
                  
                  //Getters n setters
                   }
                  

                  以下是我的 baseEntity 类

                  The following is my baseEntity clas

                  @MappedSuperclass
                  public abstract class BaseEntity {
                  @Id
                  @GeneratedValue(strategy =  GenerationType.AUTO)
                  protected final Long id;
                  
                  @Version
                  private Long version;  
                  //Getters n setters
                  }
                  

                  提前致谢.我到处阅读,并在 5 个小时内尝试了很多东西.我只希望 CompanyRepository 实现所有 3 种方法,而无需我在其他类中覆盖它们,但如果我也有,请解释如何因为我的部分代码依赖于 CompanyRepository.我只是想添加保存更新,请解释我的代码.

                  Thanks in advance. I read everywhere and tried so many things for 5 hours. I just want CompanyRepository to implement all 3 methods without me overriding them in some other class but if I have too then explain how because part of my code is dependent on CompanyRepository. I just wish to add save with update, please explain with respect to my code.

                  推荐答案

                  CrudRepository 只有 save 但它也可以作为 update.

                  CrudRepository has only save but it acts as update as well.

                  • 当您对具有空 id 的实体执行 save 时,它将执行 save.
                  • 当您对具有现有 id 的实体执行 save 时,它会执行 update,这意味着在您使用 findById 例如并更改了对象中的某些内容,您可以在此对象上调用 save ,它实际上会执行 update 因为在 findById 之后获取数据库中存在的填充了 id 的对象.
                  • CrudRepository 中的
                  • save 可以接受单个实体或您的实体类型的 Iterable.
                  • When you do save on entity with empty id it will do a save.
                  • When you do save on entity with existing id it will do an update that means that after you used findById for example and changed something in your object, you can call save on this object and it will actually do an update because after findById you get an object with populated id that exist in your DB.
                  • save in CrudRepository can accept a single entity or Iterable of your entity type.

                  这篇关于CRUDRepository 中的 Update 或 saveorUpdate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)

                2. <legend id='Et51g'><style id='Et51g'><dir id='Et51g'><q id='Et51g'></q></dir></style></legend>

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

                    <tbody id='Et51g'></tbody>

                          <bdo id='Et51g'></bdo><ul id='Et51g'></ul>

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