加入商家密码CRUD操作
This commit is contained in:
parent
f8123c6e52
commit
02dddf6699
@ -0,0 +1,18 @@
|
|||||||
|
package com.example.springdemo.dao;
|
||||||
|
|
||||||
|
|
||||||
|
import com.example.springdemo.entities.password.MerchantsPassword;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface MerchantsPasswordRepository
|
||||||
|
extends JpaRepository<MerchantsPassword, Long> {
|
||||||
|
@Query("update MerchantsPassword MerchantsPwd set MerchantsPwd.password = ?1 where MerchantsPwd.merchants.id = ?2")
|
||||||
|
void updatePassword(String password, Long merchantID);
|
||||||
|
|
||||||
|
//删除账户时删除密码
|
||||||
|
@Query("delete from MerchantsPassword MerchantsPwd where MerchantsPwd.merchants.id = ?1")
|
||||||
|
void deletePasswordById(Long merchantID);
|
||||||
|
}
|
@ -1,11 +1,12 @@
|
|||||||
package com.example.springdemo.service;
|
package com.example.springdemo.service;
|
||||||
|
|
||||||
import com.example.springdemo.entities.Merchants;
|
import com.example.springdemo.entities.Merchants;
|
||||||
|
import com.example.springdemo.entities.password.MerchantsPassword;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface MerchantsService {
|
public interface MerchantsService {
|
||||||
Merchants addMerchants(Merchants merchant);
|
Merchants addMerchants(Merchants merchant, MerchantsPassword merchantsPassword);
|
||||||
|
|
||||||
void deleteMerchantsById(Long id);
|
void deleteMerchantsById(Long id);
|
||||||
|
|
||||||
@ -16,4 +17,6 @@ public interface MerchantsService {
|
|||||||
Merchants findById(Long id);
|
Merchants findById(Long id);
|
||||||
|
|
||||||
Merchants findByName(String name);
|
Merchants findByName(String name);
|
||||||
|
|
||||||
|
void updatePassword(String password, Long id);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
package com.example.springdemo.service;
|
package com.example.springdemo.service;
|
||||||
|
|
||||||
|
import com.example.springdemo.dao.MerchantsPasswordRepository;
|
||||||
import com.example.springdemo.dao.MerchantsRepository;
|
import com.example.springdemo.dao.MerchantsRepository;
|
||||||
import com.example.springdemo.entities.Merchants;
|
import com.example.springdemo.entities.Merchants;
|
||||||
|
import com.example.springdemo.entities.password.MerchantsPassword;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -11,18 +15,31 @@ import java.util.List;
|
|||||||
public class MerchantsServiceImpl implements MerchantsService {
|
public class MerchantsServiceImpl implements MerchantsService {
|
||||||
@Resource
|
@Resource
|
||||||
private MerchantsRepository merchantsRepository;
|
private MerchantsRepository merchantsRepository;
|
||||||
|
@Resource
|
||||||
|
private MerchantsPasswordRepository merchantsPasswordRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Merchants addMerchants(Merchants merchant) {
|
@Modifying
|
||||||
return merchantsRepository.save(merchant);
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
//添加商户时添加密码
|
||||||
|
public Merchants addMerchants(Merchants merchant, MerchantsPassword merchantsPassword) {
|
||||||
|
Merchants m = merchantsRepository.save(merchant);
|
||||||
|
merchantsPasswordRepository.save(merchantsPassword);
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteMerchantsById(Long id) {
|
@Modifying
|
||||||
merchantsRepository.deleteById(id);
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
//删除商户时删除密码
|
||||||
|
public void deleteMerchantsById(Long merchantID) {
|
||||||
|
merchantsRepository.deleteById(merchantID);
|
||||||
|
merchantsPasswordRepository.deletePasswordById(merchantID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Modifying
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Merchants updateMerchants(Merchants merchant) {
|
public Merchants updateMerchants(Merchants merchant) {
|
||||||
return merchantsRepository.save(merchant);
|
return merchantsRepository.save(merchant);
|
||||||
}
|
}
|
||||||
@ -41,4 +58,12 @@ public class MerchantsServiceImpl implements MerchantsService {
|
|||||||
public Merchants findByName(String name) {
|
public Merchants findByName(String name) {
|
||||||
return merchantsRepository.findByName(name);
|
return merchantsRepository.findByName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Modifying
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
//修改密码
|
||||||
|
public void updatePassword(String password, Long merchantID) {
|
||||||
|
merchantsPasswordRepository.updatePassword(password, merchantID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user