mirror of
https://gitee.com/coder-xiaomo/flashsale
synced 2025-09-13 23:41:39 +08:00
手机号重复注册验证
This commit is contained in:
@@ -11,6 +11,7 @@ import com.cxyxiaomo.flashsale.service.model.UserModel;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -50,7 +51,11 @@ public class UserServiceImpl implements UserService {
|
||||
|
||||
// 实现 model -> dataobject 方法
|
||||
UserDO userDO = convertFormModel(userModel);
|
||||
userDOMapper.insertSelective(userDO);
|
||||
try {
|
||||
userDOMapper.insertSelective(userDO);
|
||||
} catch (DuplicateKeyException ex) {
|
||||
throw new BusinessException(EmBusinessError.PARAMETER_VALIDATION_ERROR, "手机号已被注册");
|
||||
}
|
||||
|
||||
userModel.setId(userDO.getId());
|
||||
|
||||
|
Reference in New Issue
Block a user