小编Anu*_*hra的帖子

在CRUDRepository中更新或saveorUpdate

我知道之前已经回答了类似的问题,但是我的问题是在接口中使用r 3方法实现save更新.我目前正在我的项目中使用以下方法.不知道在这里制作saveorUpdate.在我的课程之后:

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

以下是我公司类的一部分

@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
 }
Run Code Online (Sandbox Code Playgroud)

以下是我的baseEntity clas

@MappedSuperclass
public abstract class BaseEntity {
@Id
@GeneratedValue(strategy =  GenerationType.AUTO)
protected final …
Run Code Online (Sandbox Code Playgroud)

java spring spring-data spring-boot

10
推荐指数
1
解决办法
2万
查看次数

标签 统计

java ×1

spring ×1

spring-boot ×1

spring-data ×1