节点/小火箭/美区ID/国外苹果ID/美区小火箭购买/美区小火箭兑换码/shadowrocket兑换码/苹果商店下载shadowrocket网址
一、简介
在Java开发过程中,实现用户注册功能是最基本的。用户使用手机号或邮箱作为注册账号也是一种很常见的操作方式。不管是手机号注册还是邮箱注册,原理都是一样的,所以这篇文章就来了。分享Java开发过程中用户注册账号的功能实现。
2. 准备工作
1、通过Java语言实现用户注册登录后台功能;
2.使用环境包括JDK6,,,,等;
三、具体实现思路和核心步骤
1. 数据库设计
①数据库的表名及要求:
表名:users 主键:id
字段名:id:用户id,:用户名,:密码,:用户类型id ②创建数据表,创建主外键,创建序列,添加新的测试数据
2.用于创建web项目
3.在项目项目中添加支持等,并正确引入并集成到项目中,以及配置
4、创建数据持久化类和对应的映射文件,建立用户类型和用户的双向一对多关系
5、新建接口和实现类注册苹果国外版id邮箱怎么填,使用数据库对象实现相应的数据库操作
6、创建接口和实现类,实现相应的业务逻辑
7、创建类,引入接口和访问器,完成配置文件
8、新建配置文件,实现对应的对象声明和配置
9、前端接口搭建与接口联调
10、测试环节:调试成功后,将对应的数据库对象导出为sql文件注册苹果国外版id邮箱怎么填,并处理用户注册数据的备份机制,完成测试,实现用户注册登录功能。
四、核心代码 1、.java文件的核心代码
public interface UserService {
/**
* 用户注册
*
* @param userId
* @param dto
* @throws Exception
*/
void userRegister(Long userId, UserRegisterDTO dto) throws Exception;
/**
* 忘记密码
*
* @param userId
* @param dto
* @throws Exception
*/
void updatePassword(Long userId, UpdatePasswordDTO dto) throws Exception;
/**
* 通过邮箱发送验证码
*
* @param userId
* @param email
* @throws BusinessException
*/
void sendVerificationCode(Long userId, String email) throws BusinessException;
/**
* 通过用户名密码获取用户
*
* @param loginName
* @param loginPwd
* @return
* @throws BusinessException
*/
User getUser(String loginName, String loginPwd) throws BusinessException;
}
2..java文件的核心代码
@RestController
@Slf4j
public class UserController extends BaseController {
private final UserService userService;
@Autowired
public UserController(UserService userService) {
this.userService = userService;
}
/**
* 会员注册
*
* @param dto
* @param request
* @return
* @throws Exception
*/
@ApiOperation(value = "会员注册", produces = "application/json")
@ApiResponses({@ApiResponse(code = AjaxReturn.SUCCESS, message = "注冊成功", response = AjaxReturn.class)})
@PostMapping(path = {"/user-save"})
public AjaxReturn userRegister(@ModelAttribute UserRegisterDTO dto, HttpServletRequest request) throws Exception {
log.info(dto.toString());
Long userId = getAuthentication(request);
if (StringUtils.isBlank(dto.getMobile()) && StringUtils.isBlank(dto.getEmail())) {
throw new BusinessException("请输入手机号或邮箱");
}
if (StringUtils.isNotBlank(dto.getMobile()) && !StringUtils.isNumeric(dto.getMobile())) {
throw new BusinessException("请输入正确的手机号");
}
if (StringUtils.isNotBlank(dto.getEmail()) && !StringUtils.isEmail(dto.getEmail())) {
throw new BusinessException("请输入正确的邮箱");
}
if (StringUtils.isBlank(dto.getLoginPwd())) {
throw new BusinessException("password must not be null");
}
// 密码MD5加密
dto.setLoginPwd(DigestUtils.md5Hex(dto.getLoginPwd()));
if (StringUtils.isBlank(dto.getVerificationCode())) {
throw new BusinessException("verification code must not be null");
}
userService.userRegister(userId, dto);
return AjaxReturn.builder().build();
}
/**
* 忘记密码
*
* @param dto
* @param request
* @return
* @throws Exception
*/
@ApiOperation(value = "忘记密码", produces = "application/json")
@ApiResponses({@ApiResponse(code = AjaxReturn.SUCCESS, message = "更新密码成功", response = AjaxReturn.class)})
@PostMapping(path = {"/user-password-forget"})
public AjaxReturn updatePassword(@ModelAttribute UpdatePasswordDTO dto, HttpServletRequest request) throws Exception {
Long userId = getAuthentication(request);
if (StringUtils.isBlank(dto.getMobile()) && StringUtils.isBlank(dto.getEmail())) {
throw new BusinessException("请输入手机号或邮箱");
}
if (StringUtils.isNotBlank(dto.getMobile()) && !StringUtils.isNumeric(dto.getMobile())) {
throw new BusinessException("请输入正确的手机号");
}
if (StringUtils.isNotBlank(dto.getEmail()) && !StringUtils.isEmail(dto.getMobile())) {
throw new BusinessException("请输入正确的邮箱");
}
if (StringUtils.isBlank(dto.getLoginPwd())) {
throw new BusinessException("password must not be null");
}
// 密码MD5加密
dto.setLoginPwd(DigestUtils.md5Hex(dto.getLoginPwd()));
if (StringUtils.isBlank(dto.getVerificationCode())) {
throw new BusinessException("verification code must not be null");
}
userService.updatePassword(userId, dto);
return AjaxReturn.builder().build();
}
/**
* 通过邮件发送验证码
*
* @param email
* @param request
* @return
* @throws BusinessException
*/
@ApiOperation(value = "通过邮件发送验证码", produces = "application/json")
@ApiResponses({@ApiResponse(code = AjaxReturn.SUCCESS, message = "通过邮件发送验证码成功", response = AjaxReturn.class)})
@PostMapping(path = {"/verification-code-send"})
public AjaxReturn sendVerificationCode(@ApiParam(name = "email", value = "邮箱", required = true) @RequestParam String email, HttpServletRequest request) throws BusinessException {
Long userId = getAuthentication(request);
userService.sendVerificationCode(userId, email);
return AjaxReturn.builder().build();
}
}
3. 文件
五、注意事项
1、注意代码编写和命名约定;
2.对关键代码进行注释,方便后期维护;
3.考虑控件的整齐放置,注意界面美观;
4、操作数据库时,需要注意必要的异常处理,建立容错机制。
最后
通过以上介绍的流程步骤,简单实现了比较全面的用户注册和登录功能。虽然这个功能很常见,但是对于Java开发的新手来说还是比较难的。这个命题可以作为进入Java开发的途径。以上就是本文的全部内容。如果有什么问题,请提出来。
节点/小火箭/美区ID/国外苹果ID/美区小火箭购买/美区小火箭兑换码/shadowrocket兑换码/苹果商店下载shadowrocket网址
原文链接:一下在Java开发过程中的用户注册账号的功能实现。,转载请注明来源!