当前位置: 首页 > news >正文

网站维护开发合同做二手网站赚钱不

网站维护开发合同,做二手网站赚钱不,seo成都,自建网站 备案实现学生管理 新增学生 接口设计 请求路径:/admin/student 请求方法:POST 请求参数:请求头:Headers:"Content-Type": "application/json" 请求体:Body: id 学生id …

实现学生管理

新增学生

接口设计

请求路径:/admin/student

请求方法:POST

请求参数:请求头:Headers:"Content-Type": "application/json"

请求体:Body:

id 学生id

idNumber 学生身份证

name 名字

phone 电话号码

sex 性别

username 用户名

返回数据:Result

student表设计

字段名

数据类型

说明

备注

id

bigint

主键

自增

name

varchar(32)

姓名

username

varchar(32)

用户名

唯一

password

varchar(64)

密码

phone

varchar(11)

手机号

sex

varchar(2)

性别

id_number

varchar(18)

身份证号

status

Int

账号状态

1正常 0锁定

create_time

Datetime

创建时间

update_time

datetime

最后修改时间

create_user

bigint

创建人id

update_user

bigint

最后修改人id

代码开发

设计DTO类接收前端传来的参数

sems-pojo/src/main/java/com/ljc/dto/StudentDTO.java

package com.ljc.dto;import lombok.Data;import java.io.Serializable;@Data
public class StudentDTO implements Serializable {//学生idprivate Long id;//用户名private String username;//姓名private String name;//电话private String phone;//性别private String sex;//身份证号private String idNumber;}

controller层

sems-server/src/main/java/com/ljc/controller/student/StudentController.java

package com.ljc.controller.student;import com.ljc.constant.JwtClaimsConstant;
import com.ljc.dto.StudentDTO;
import com.ljc.dto.StudentLoginDTO;
import com.ljc.entity.Student;
import com.ljc.properties.JwtProperties;
import com.ljc.result.Result;
import com.ljc.service.StudentService;
import com.ljc.utils.JwtUtil;
import com.ljc.vo.StudentLoginVO;import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import java.util.HashMap;
import java.util.Map;@RestController
@RequestMapping("/admin/student")
@Slf4j
public class StudentController {@Autowiredprivate StudentService studentService;@Autowiredprivate JwtProperties jwtProperties;/*** 登录** @param studentLoginDTO* @return*/@ApiOperation("用户登录")@PostMapping("/login")public Result<StudentLoginVO> login(@RequestBody StudentLoginDTO studentLoginDTO) {log.info("学生登录:{}", studentLoginDTO);Student student = studentService.login(studentLoginDTO);//登录成功后,生成jwt令牌Map<String, Object> claims = new HashMap<>();claims.put(JwtClaimsConstant.EMP_ID, student.getId());String token = JwtUtil.createJWT(jwtProperties.getAdminSecretKey(),jwtProperties.getAdminTtl(),claims);StudentLoginVO studentLoginVO = StudentLoginVO.builder().id(student.getId()).userName(student.getUsername()).name(student.getName()).token(token).build();return Result.success(studentLoginVO);}/*** 退出** @return*/@ApiOperation("用户退出")@PostMapping("/logout")public Result<String> logout() {return Result.success();}/*** 新增学生* @param studentDTO* @return*/@PostMapping@ApiOperation("新增学生")public Result save(@RequestBody StudentDTO studentDTO){//日志,现在进行的是新增学生功能log.info("新增学生:{}", studentDTO);//调用service层(处理层)的方法进行新增studentService.save(studentDTO);return Result.success();}}

Service层

sems-server/src/main/java/com/ljc/service/StudentService.java

package com.ljc.service;import com.ljc.dto.StudentDTO;
import com.ljc.dto.StudentLoginDTO;
import com.ljc.entity.Student;public interface StudentService {/*** 学生登录* @param studentLoginDTO* @return*/Student login(StudentLoginDTO studentLoginDTO);/*** 新增学生* @param studentDTO*/void save(StudentDTO studentDTO);
}

ServiceImpl层

sems-server/src/main/java/com/ljc/service/impl/StudentServiceImpl.java

package com.ljc.service.impl;import com.ljc.constant.MessageConstant;
import com.ljc.constant.PasswordConstant;
import com.ljc.constant.StatusConstant;
import com.ljc.context.BaseContext;
import com.ljc.dto.StudentDTO;
import com.ljc.dto.StudentLoginDTO;
import com.ljc.entity.Student;
import com.ljc.exception.AccountLockedException;
import com.ljc.exception.AccountNotFoundException;
import com.ljc.exception.PasswordErrorException;
import com.ljc.mapper.StudentMapper;
import com.ljc.service.StudentService;import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;import java.time.LocalDateTime;@Service
public class StudentServiceImpl implements StudentService {@Autowiredprivate StudentMapper studentMapper;/*** 学生登录** @param studentLoginDTO* @return*/public Student login(StudentLoginDTO studentLoginDTO) {String username = studentLoginDTO.getUsername();String password = studentLoginDTO.getPassword();//1、根据用户名查询数据库中的数据Student student = studentMapper.getByUsername(username);//2、处理各种异常情况(用户名不存在、密码不对、账号被锁定)if (student == null) {//账号不存在throw new AccountNotFoundException(MessageConstant.ACCOUNT_NOT_FOUND);}//密码比对// 进行md5加密,然后再进行比对password = DigestUtils.md5DigestAsHex(password.getBytes());if (!password.equals(student.getPassword())) {//密码错误throw new PasswordErrorException(MessageConstant.PASSWORD_ERROR);}if (student.getStatus() == StatusConstant.DISABLE) {//账号被锁定throw new AccountLockedException(MessageConstant.ACCOUNT_LOCKED);}//3、返回实体对象return student;}/**** 新增学生* @param studentDTO*/@Overridepublic void save(StudentDTO studentDTO) {//1. 创建一个学生对象Student student = new Student();//2. 将前端传后来的参数,即就是封装在DTO里面的数据转移到学生对象中//调用对象属性拷贝,括号里面参数,前面的是需要传递的数据,后面的是接收的数据BeanUtils.copyProperties(studentDTO,student);//3. 补充student里面的数据,前端没有传递回来的//3.1 前端没有传递账号状态,现在给设置账号状态:默认为正常,正常为1,异常为0;//由于1太不美观了,创建一个常量类/*student.setStatus(1);*/student.setStatus(StatusConstant.ENABLE);//3.2 设置密码:默认为123456,进行MD5加密//密码也设置一个常量:PasswordConstant.DEFAULT_PASSWORD/*student.setPassword(DigestUtils.md5DigestAsHex("123456".getBytes()));*/student.setPassword(DigestUtils.md5DigestAsHex(PasswordConstant.DEFAULT_PASSWORD.getBytes()));//3.3 设置创建时间和修改时间: 为当前时间student.setCreateTime(LocalDateTime.now());student.setUpdateTime(LocalDateTime.now());//3.4 设置创建人的idstudent.setCreateUser(BaseContext.getCurrentId());student.setUpdateUser(BaseContext.getCurrentId());//4 调用mapper层数据,连接数据库,对数据库进行操作studentMapper.insert(student);}}

mapper层

sems-server/src/main/java/com/ljc/mapper/StudentMapper.java

package com.ljc.mapper;import com.ljc.entity.Student;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;@Mapper
public interface StudentMapper {/*** 根据用户名查询学生* @param username* @return*/@Select("select * from student where username = #{username}")Student getByUsername(String username);/*** 新增学生* @param student*/@Insert("insert into student (name, username, password, phone, sex, id_number, create_time, update_time, create_user, update_user,status) " +"values " +"(#{name},#{username},#{password},#{phone},#{sex},#{idNumber},#{createTime},#{updateTime},#{createUser},#{updateUser},#{status})")void insert(Student student);
}

补充代码

这里面有几个常量值,和一个ThreadLocal来获取jwt令牌里面的用户名

封装了 ThreadLocal 操作的工具类:

sems-common/src/main/java/com/ljc/context/BaseContext.java

package com.ljc.context;public class BaseContext {public static ThreadLocal<Long> threadLocal = new ThreadLocal<>();public static void setCurrentId(Long id) {threadLocal.set(id);}public static Long getCurrentId() {return threadLocal.get();}public static void removeCurrentId() {threadLocal.remove();}}

常量类

密码

sems-common/src/main/java/com/ljc/constant/PasswordConstant.java

package com.ljc.constant;/*** 密码常量*/
public class PasswordConstant {public static final String DEFAULT_PASSWORD = "123456";}

补充用户名重复常量

sems-common/src/main/java/com/ljc/constant/MessageConstant.java

package com.ljc.constant;/*** 信息提示常量类*/
public class MessageConstant {public static final String PASSWORD_ERROR = "密码错误";public static final String ACCOUNT_NOT_FOUND = "账号不存在";public static final String ACCOUNT_LOCKED = "账号被锁定";public static final String UNKNOWN_ERROR = "未知错误";public static final String USER_NOT_LOGIN = "用户未登录";public static final String CATEGORY_BE_RELATED_BY_SETMEAL = "当前分类关联了套餐,不能删除";public static final String CATEGORY_BE_RELATED_BY_DISH = "当前分类关联了菜品,不能删除";public static final String SHOPPING_CART_IS_NULL = "购物车数据为空,不能下单";public static final String ADDRESS_BOOK_IS_NULL = "用户地址为空,不能下单";public static final String LOGIN_FAILED = "登录失败";public static final String UPLOAD_FAILED = "文件上传失败";public static final String SETMEAL_ENABLE_FAILED = "套餐内包含未启售菜品,无法启售";public static final String PASSWORD_EDIT_FAILED = "密码修改失败";public static final String DISH_ON_SALE = "起售中的菜品不能删除";public static final String SETMEAL_ON_SALE = "起售中的套餐不能删除";public static final String DISH_BE_RELATED_BY_SETMEAL = "当前菜品关联了套餐,不能删除";public static final String ORDER_STATUS_ERROR = "订单状态错误";public static final String ORDER_NOT_FOUND = "订单不存在";public static final String ALREADY_EXISTS = "已存在";
}

处理用户名重复的异常

sems-server/src/main/java/com/ljc/handler/GlobalExceptionHandler.java

package com.ljc.handler;import com.ljc.constant.MessageConstant;
import com.ljc.exception.BaseException;
import com.ljc.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;import java.sql.SQLIntegrityConstraintViolationException;/*** 全局异常处理器,处理项目中抛出的业务异常*/
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {/*** 捕获业务异常* @param ex* @return*/@ExceptionHandlerpublic Result exceptionHandler(BaseException ex){log.error("异常信息:{}", ex.getMessage());return Result.error(ex.getMessage());}/*** 捕获用户名重复* */@ExceptionHandlerpublic Result exceptionHandler(SQLIntegrityConstraintViolationException ex){//Duplicate entry 'zhangsan' for key 'employee.idx_username'//获取异常信息String massage = ex.getMessage();//以” “分割异常信息;if (massage.contains("Duplicate entry")){String[] split = massage.split(" ");String name = split[2];String msg = name+ MessageConstant.ALREADY_EXISTS;//已存在已有常量,尽量避免字符串return Result.error(msg);}else {return Result.error(MessageConstant.UNKNOWN_ERROR);}}}

测试

完成后进入swagger界面测试一下

因为需要进行jwt令牌检测,所以

使用admin用户登录获取令牌

将合法的JWT令牌添加到全局参数中

检查一下添加上了没

然后开始测试

检查数据库添加上了没

学生分页查询

开发到这里我发现还得先开发前端,前端明确后,后端才有针对性,所以先完成前端代码。

麻了,前端一点不会啊,工期有点长了.....................

http://www.yayakq.cn/news/146109/

相关文章:

  • 做网站销售提成怎么算龙华网站 建设龙华信科
  • 松江做网站的公司如何运营电商平台
  • 定远县建设小学网站开发app怎么赚钱
  • 微信小程序怎么做网页北京网站优化方法
  • 制作系部网站首页莆田百度seo公司
  • 如何制作淘宝客网站wordpress 一键分享
  • dedecms 生成网站地图快递建站收费标准
  • seo案例网站网站改版 方案
  • 昆山制造网站的地方免费移动版wordpress
  • 包头网站 建设海南最新消息新闻
  • 网站开发石家庄个人网站做cpa
  • 制作网站要多少钱网页制作外包
  • 金华专业做网站公司wordpress搬家后需要重新安装
  • 西安企业模板网站建设国内做外贸的平台有哪些
  • 公司企业如何做网站织梦网站建设案例
  • 贵州城市和城乡建设官方网站微信官网登陆
  • wordpress如何获取会员字段简述网站内容如何优化
  • 做公众号可以看的网站可以直接用php做网站吗
  • ps制作个人网站首页子域名网址查询
  • ppt做书模板下载网站有哪些内容郑州网站建设开发
  • 网站开发所需能力东莞寮步搬家公司
  • 网站推广应该怎么做树品短视频营销拓客平台
  • 中小型企业查询网站wordpress 页码显示
  • 安徽省建设工程安全协会网站开发网站需要注意
  • 上海医疗网站备案表wordpress怎么修改首页
  • 郑州经纬网络做网站吗急招一对夫妻门卫6500元
  • 制作一个专门浏览图片的网站网站是陕西省城乡建设综合服务中心
  • 淘宝客网站建设任务柳州 网站推广
  • 网站企业建设开发一个手机app多少钱
  • 网站设计厂站长工具pr值查询