我的Service
班级
@Override
public void addFilterDetails(FilterDetails filterDetails) {
// TODO Auto-generated method stub
FilterDetails fd = new FilterDetails(filterDetails.getGender(),filterDetails.getAge(),filterDetails.getCity(),filterDetails.getState());
filterDetailsRepository.save(fd);
}
这是我的存储库
package com.thoughtclan.segmentation_of_customers.repository;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import com.thoughtclan.segmentation_of_customers.model.Customer;
import com.thoughtclan.segmentation_of_customers.model.FilterDetails;
@Repository
public interface FilterDetailsRepository extends CrudRepository<Customer, Long>{
}
@Override
public void addCustomer(Customer custObj) {
// TODO Auto-generated method stub
Customer customer = new Customer( custObj.getFirstName(), custObj.getLastName(),custObj.getEmail(),custObj.getGender(),custObj.getPhoneno(),custObj.getCity(),custObj.getState(),custObj.getAge());
customerRepository.save(customer);
}
addCustomer()
正在使用完全相同的语法,为什么filterdetails.save
会出现以下错误?
CrudRepository不适用于参数(FilterDetails)
答案 0 :(得分:0)
这是因为您已为Customer
类创建了一个存储库。
public interface FilterDetailsRepository extends CrudRepository<Customer, Long>
在上述情况下,除save
外,它不允许Customer
任何类型的实体。
如果您要保存FilterDetails
,则必须为FilterDetails
创建另一个存储库,如下所示:
public interface FilterDetailsRepository extends CrudRepository<FilterDetails, Long>
然后,通过引用FilterDetailsRepository
,您可以保存FilterDetails