MerchantsService层功能重构
This commit is contained in:
		@@ -1,9 +1,20 @@
 | 
			
		||||
package com.example.springdemo.service;
 | 
			
		||||
 | 
			
		||||
import com.example.springdemo.dao.MerchantsRepository;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
import com.example.springdemo.entities.Merchants;
 | 
			
		||||
 | 
			
		||||
@Service
 | 
			
		||||
public interface MerchantsService extends MerchantsRepository {
 | 
			
		||||
import java.util.List;
 | 
			
		||||
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);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user