MerchantsService层功能重构

This commit is contained in:
myh 2023-10-25 18:12:29 +08:00
parent b51f777a98
commit 632c7b96e6
2 changed files with 60 additions and 4 deletions

View File

@ -1,9 +1,20 @@
package com.example.springdemo.service; package com.example.springdemo.service;
import com.example.springdemo.dao.MerchantsRepository; import com.example.springdemo.entities.Merchants;
import org.springframework.stereotype.Service;
@Service import java.util.List;
public interface MerchantsService extends MerchantsRepository { import java.util.Optional;
public interface MerchantsService {
Merchants insetMerchants(Merchants merchant);
void deleteMerchantsById(Long id);
Merchants updateMerchants(Merchants merchant);
List<Merchants> findAllMerchants();
Optional<Merchants> findById(Long id);
Merchants findByName(String name);
} }

View File

@ -0,0 +1,45 @@
package com.example.springdemo.service;
import com.example.springdemo.dao.MerchantsRepository;
import com.example.springdemo.entities.Merchants;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
@Service
public class MerchantsServiceImpl implements MerchantsService {
@Resource
private MerchantsRepository merchantsRepository;
@Override
public Merchants insetMerchants(Merchants merchant) {
return merchantsRepository.save(merchant);
}
@Override
public void deleteMerchantsById(Long id) {
merchantsRepository.deleteById(id);
}
@Override
public Merchants updateMerchants(Merchants merchant) {
return merchantsRepository.save(merchant);
}
@Override
public List<Merchants> findAllMerchants() {
return merchantsRepository.findAll();
}
@Override
public Optional<Merchants> findById(Long id) {
return merchantsRepository.findById(id);
}
@Override
public Merchants findByName(String name) {
return merchantsRepository.findByName(name);
}
}