请看我涉及到的代码
存储库:
import org.HappyRestApi.springREST.domain.BankDeposit;
import org.springframework.data.jpa.repository.JpaRepository;
public interface BankDepositRepositorie extends JpaRepository<BankDeposit,Long> {
}
服务:
package org.HappyRestApi.springREST.services;
import org.HappyRestApi.springREST.domain.BankDeposit;
import org.HappyRestApi.springREST.repositories.BankDepositRepositorie;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class BankDepositServiceImpl implements BankDepositService {
private final BankDepositRepositorie bankDepositRepositorie;
public BankDepositServiceImpl(BankDepositRepositorie bankDepositRepositorie) {
this.bankDepositRepositorie = bankDepositRepositorie;
}
@Override
public BankDeposit findBankDepositById(Long id) {
return bankDepositRepositorie.findById(id).get();
}
@Override
public List<BankDeposit> findAllBankDeposit() {
return bankDepositRepositorie.findAll();
}
@Override
public void addBankDeposit(BankDeposit bankDeposit) {
this.bankDepositRepositorie.save(bankDeposit);
}
@Override
public void deleteBankDepositaById(Long id){
this.bankDepositRepositorie.deleteById(id);
}
}
测试:
package org.HappyRestApi.springREST.services;
import org.HappyRestApi.springREST.domain.BankDeposit;
import org.HappyRestApi.springREST.domain.enums.Period;
import org.HappyRestApi.springREST.repositories.BankDepositRepositorie;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.runner.RunWith;
}
炎炎设计
相关分类