网站做seo需要些什么,优秀商业空间设计案例分析,wordpress是用php语言的,手机排名企业做项目流程
需求分析 设计#xff08;概要设计 、 详细设计#xff09; 技术选型 初始化项目 / 引入需要的技术 写个小demo 写代码 #xff08;实现业务逻辑#xff09; 测试#xff08;单元测试#xff09; 代码提交 / 代码评审 …企业做项目流程
需求分析 设计概要设计 、 详细设计 技术选型 初始化项目 / 引入需要的技术 写个小demo 写代码 实现业务逻辑 测试单元测试 代码提交 / 代码评审 部署 发布 需求分析
1、登录 / 注册
2、用户管理 管理员权限
3、用户校验机制 仅星球用户 技术选型 前端三件套 React Ant design(组件库)umi ant design pro
后端java
springmvc接口restful接口开发
mybatis 提供数据访 数据持久层支持
mybatis plus mybatis的封装
springboot 快速启动spring项目
mysql
部署服务器 / 容器 初始化项目
1初始化后端项目
初始化一个springboot项目 这里有一个注意点建议就是把springboot的版本改低一点改到2.x要不然后面真的会发生很多不兼容 2初始化数据库
create table user
(id bigint auto_incrementprimary key,username varchar(256) null comment 用户昵称,userAccount varchar(256) null comment 账号,avatarUrl varchar(1024) null comment 用户头像,gender tinyint null comment 性别,userPassword varchar(512) not null comment 密码,phone varchar(128) null comment 电话,email varchar(512) null comment 邮箱,userStatus int default 0 not null comment 用户状态 0-正常,createTime datetime default CURRENT_TIMESTAMP null comment 创建时间,updateTime datetime default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP comment 更新时间,isDelete tinyint default 0 not null comment 是否删除,role int default 0 not null comment 0 : 普通用户 1管理员,planetCode varchar(512) null comment 星球编号
)comment 用户;
3初始化前端项目
Ant Design Pro_ant design pro百度百科-CSDN博客
4springboot的配置文件
spring:application:name: user-centerdatasource:driver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://localhost:3306/userusername: rootpassword: 123456#mybatisplus添加日志功能
mybatis-plus:configuration:log-impl: org.apache.ibatis.logging.stdout.StdOutImplmap-underscore-to-camel-case: false
global-config:db-config:#配置Mybatis-plus操作表的默认前缀table-prefix: t_#配置Mybatis-plus的主键策略# 全局逻辑删除的字段名logic-delete-field: isDelete# 逻辑已删除值(默认为 1)logic-delete-value: 1# 逻辑未删除值(默认为 0)logic-not-delete-value: 0
主要就是配置了数据库和mybatis-plus插件的使用
mybatis-plus插件自动生成器 MyBatisX 插件自动根据数据库生成 domain 实体对象、 mapper操作数据库的对象、 mapper.xml定义了 mapper对象和数据库的关联可以在里面自己写 SQL、 service包含常用的增删改查、 serviceImpl具体实现 service。 5引入常用依赖 !-- mybatis-plus启动器 --dependencygroupIdcom.baomidou/groupIdartifactIdmybatis-plus-boot-starter/artifactIdversion3.5.1/version/dependencydependencygroupIdorg.apache.commons/groupIdartifactIdcommons-lang3/artifactIdversion3.12.0/version/dependency
依赖这一块引入了一个mybatis-plus和一个lang3后面用来给密码进行加密的一个依赖
编写代码
登录接口设计
接受参数用户账户密码
请求类型POST
请求体JSON格式数据
返回值用户信息 在写这个接口之前需要稍微补充一点javaweb的知识 1、连接服务器后得到一个匿名session 2、登录成功后得到登录成功的session并给该session设置一些值比如用户信息返回给前端一个设置cookies的命令。 session cookies 3、前端收到后端的命令后设置cookie保存到浏览器内。 4、前端再次请求后端的时候在请求头中带上cookies去做请求 5、后端拿到前端传来的cookie找到对应的session 6、后端从session中可以取出session中存储变量 具体逻辑设计
1. 用户在前端输入账户和密码、以及校验码todo校验码表示可以先不做后期补充 2. 校验用户的账户、密码、校验密码是否符合要求 非空 账户长度 不小于 4 位 密码 不小于 6 位 账户不能重复 账户不包含特殊字符 密码和校验密码相同 3. 对密码进行加密密码千万不要直接以明文存储到数据库中 4. 向数据库插入用户数据
具体代码实现三层
Controller层
PostMapping(/login)public BaseResponseUser userLogin(RequestBody UserLoginRequest userLoginRequest, HttpServletRequest request){if(userLoginRequestnull){throw new BusinessException(ErrorCode.PARAMS_ERROR);}log.info(用户登录{},userLoginRequest);final String userAccount userLoginRequest.getUserAccount();final String userPassword userLoginRequest.getUserPassword();User user userService.userLogin(userAccount,userPassword,request);return ResultUtils.success(user);}Autowiredprivate UserService userService;Data
NoArgsConstructor
AllArgsConstructor
public class UserLoginRequest {private String userAccount;private String userPassword;
}用UserLoginRequest来接收前端发送过来的JSON数据一开始是没有封装的后面优化的时候进行封装
Service层
Resourceprivate UserMapper userMapper;Overridepublic User userLogin(String userAccount, String password, HttpServletRequest httpServletRequest) {//1:校验输入的账户密码和校验码是否非空if (StringUtils.isAnyBlank(userAccount,password)) {throw new BusinessException(ErrorCode.PARAMS_ERROR, 参数为空);}//账户不小于4位if(userAccount.length()4){throw new BusinessException(ErrorCode.PARAMS_ERROR, 用户账号过短);}//密码不小于8位if(password.length()8){throw new BusinessException(ErrorCode.PARAMS_ERROR, 用户账号过短);}//2:从数据库中查询用户String verifyPassword DigestUtils.md5DigestAsHex((password).getBytes(StandardCharsets.UTF_8));QueryWrapperUser queryWrapper new QueryWrapper();queryWrapper.eq(userAccount,userAccount);queryWrapper.eq(userPassword,verifyPassword);final User user userMapper.selectOne(queryWrapper);if(usernull){log.info(user login failed, userAccount cannot match userPassword);}//3用户脱敏/*** 其实这个脱敏就是创建一个新的用户封装一些我们想让前端看到的值保证用户隐私*/getSaftyUser(user);//4:获取用户登录态httpServletRequest.getSession().setAttribute(UserConstant.USER_LOGIN_STATE,user);return user;}private User getSaftyUser(User user) {if(user null) {return null;}User safetyuser new User();safetyuser.setId(user.getId());safetyuser.setUsername(user.getUsername());safetyuser.setUserAccount(user.getUserAccount());safetyuser.setAvatarUrl(user.getAvatarUrl());safetyuser.setGender(user.getGender());safetyuser.setPhone(user.getPhone());safetyuser.setEmail(user.getEmail());safetyuser.setUserStatus(user.getUserStatus());safetyuser.setCreateTime(user.getCreateTime());safetyuser.setRole(user.getRole());safetyuser.setPlanetCode(user.getPlanetCode());return safetyuser;}
整体的代码逻辑
对密码和用户名进行一些校验从数据库中查询是否有这个用户用户脱敏设置当前的用户登录态 HttpServletRequest对象的getSession()方法用于获取与当前请求关联的HttpSession对象即获取会话对象。HttpSession对象代表了用户和服务器之间的一个会话用于存储用户的信息并保持用户的状态在同一个会话中可以通过HttpSession对象在不同的请求之间共享数据。 通过调用getSession()方法我们可以获得用户的会话对象可用于存储和检索与用户会话相关的信息例如用户的登录状态、购物车信息等。 调用setAttribute方法可以在当前会话对象中设置一个属性并将其与指定的值关联起来。这样做可以在当前会话中保存数据方便在整个会话周期内进行数据的传递和共享。 Mapper层
Mapper
public interface UserMapper extends BaseMapperUser {}
用来Mybatis-plus框架查询操作非常简单