@Service
@Transactional
public class HunterNicknameServiceImpl implements HunterNicknameService {
@Autowired
private HunterNicknameDao hunterNicknameDao;
@Override
public Result updateHunterNickName(Hunter hunter) {
Result result = new Result();
//第一: 得到猎头的昵称【看是否为当前要修改的字段】
String nickname = hunter.getNickname();
//第二: 除去空格
if (nickname != null) {
nickname = nickname.replaceAll(" ", "");
}
//第三: 判断是否为空
if (nickname == null || "".equals(nickname)) {
return ResultUtils.returnError("猎头昵称不能为空");
}
//第四: 判断字符长度
if (nickname.length() >= 2 && nickname.length() <= 10) {
try {
this.hunterNicknameDao.updateHunterNickName(hunter.getId(), nickname);
result.setCode(1);
result.setMsg("猎头昵称修改成功");
} catch (Exception e) {
e.printStackTrace();
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();// 回滚数据
result.setCode(0);
result.setMsg("猎头昵称修改失败");
}
} else {
return ResultUtils.returnError("猎头昵称长度范围在2-10个字");
}
return result;
}
}