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

做淘宝客网站需要做后台吗江阴网站优化公司

做淘宝客网站需要做后台吗,江阴网站优化公司,购物网站建设思维导构图,做家教有哪些比较好的网站1.1 由于返回数据都是以下这种格式,那么久再编写一个result实体类 报错了,原因是没有构造方法 可以使用lombok的注解自动生成,添加无参的构造器和全参的构造器 package com.geji.pojo;import lombok.AllArgsConstructor; import lombok.NoArg…

1.1 由于返回数据都是以下这种格式,那么久再编写一个result实体类

报错了,原因是没有构造方法

可以使用lombok的注解自动生成,添加无参的构造器和全参的构造器

package com.geji.pojo;import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;//统一响应结果
@NoArgsConstructor
@AllArgsConstructor
@Data
public class Result<T> {private Integer code;//业务状态码  0-成功  1-失败private String message;//提示信息private T data;//响应数据//快速返回操作成功响应结果(带响应数据)public static <E> Result<E> success(E data) {return new Result<>(0, "操作成功", data);}//快速返回操作成功响应结果public static Result success() {return new Result(0, "操作成功", null);}public static Result error(String message) {return new Result(1, message, null);}
}

接口开发的流程:

Controller接收路由-->Service执行和数据库的逻辑操作-->Mapper映射到真实的数据库操作

1.1 注册

1.1.1 创建相应的类和接口,impl实体类实现impl接口

1.1.2 编写UserControl

package com.geji.controller;import com.geji.pojo.Result;
import com.geji.pojo.User;
import com.geji.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
@RequestMapping("/user")
public class UserController {@Autowiredprivate UserService userService;@PostMapping("/register")public Result register(String username, String password) {//查询用户User u = userService.findByUserName(username);if (u == null) {//没有占用//注册userService.register(username, password);return Result.success();} else {//占用return Result.error("用户名已被占用");}}
}

1.1.3 编写UserService

package com.geji.service;import com.geji.pojo.User;public interface UserService {//根据用户名查找用户User findByUserName(String username);//根据用户名和密码注册void register(String username, String password);
}

1.1.4 编写UserServiceImpl

package com.geji.service.impl;import com.geji.mapper.UserMapper;
import com.geji.pojo.User;
import com.geji.service.UserService;
import com.geji.utils.Md5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;@Service
public class UserServiceImpl implements UserService {@Autowiredprivate UserMapper userMapper;@Overridepublic User findByUserName(String username) {User u = userMapper.findByUserName(username);return u;}@Overridepublic void register(String username, String password) {//加密String md5String = Md5Util.getMD5String(password);//添加userMapper.add(username,md5String);}
}

1.1.4 MD5加密算法

package com.geji.utils;import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;public class Md5Util {/*** 默认的密码字符串组合,用来将字节转换成 16 进制表示的字符,apache校验下载的文件的正确性用的就是默认的这个组合*/protected static char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};protected static MessageDigest messagedigest = null;static {try {messagedigest = MessageDigest.getInstance("MD5");} catch (NoSuchAlgorithmException nsaex) {System.err.println(Md5Util.class.getName() + "初始化失败,MessageDigest不支持MD5Util。");nsaex.printStackTrace();}}/*** 生成字符串的md5校验值** @param s* @return*/public static String getMD5String(String s) {return getMD5String(s.getBytes());}/*** 判断字符串的md5校验码是否与一个已知的md5码相匹配** @param password  要校验的字符串* @param md5PwdStr 已知的md5校验码* @return*/public static boolean checkPassword(String password, String md5PwdStr) {String s = getMD5String(password);return s.equals(md5PwdStr);}public static String getMD5String(byte[] bytes) {messagedigest.update(bytes);return bufferToHex(messagedigest.digest());}private static String bufferToHex(byte bytes[]) {return bufferToHex(bytes, 0, bytes.length);}private static String bufferToHex(byte bytes[], int m, int n) {StringBuffer stringbuffer = new StringBuffer(2 * n);int k = m + n;for (int l = m; l < k; l++) {appendHexPair(bytes[l], stringbuffer);}return stringbuffer.toString();}private static void appendHexPair(byte bt, StringBuffer stringbuffer) {char c0 = hexDigits[(bt & 0xf0) >> 4];// 取字节中高 4 位的数字转换, >>>// 为逻辑右移,将符号位一起右移,此处未发现两种符号有何不同char c1 = hexDigits[bt & 0xf];// 取字节中低 4 位的数字转换stringbuffer.append(c0);stringbuffer.append(c1);}}

1.1.5 编写UserMapper

package com.geji.mapper;import com.geji.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;@Mapper
public interface UserMapper {//根据用户名查询用户@Select("select * from user where username=#{username}")User findByUserName(String username);//添加@Insert("insert into user(username,password,create_time,update_time)" +" values(#{username},#{password},now(),now())")void add(String username, String password);
}

1.1.6 postman接口测试

1.1.6.1 下载安装postman

Download Postman | Get Started for Free

1.1.6.2 创建workspaces

1.1.6.3 创建collections测试用例

1.1.6.3.1 注册接口,post,body,urlencoded

成功

1.1.7 以上Controller类中没有对username和password做参数校验,Spring中提供了注解

1.1.7.1 引入spring validation起步依赖

1.1.7.2 在参数前加上@Pattern注解

1.1.7.3 在Controller类上添加@Validated注解

package com.geji.controller;import com.geji.pojo.Result;
import com.geji.pojo.User;
import com.geji.service.UserService;
import jakarta.validation.constraints.Pattern;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
@RequestMapping("/user")
@Validated
public class UserController {@Autowiredprivate UserService userService;@PostMapping("/register")public Result register(@Pattern(regexp = "^\\S{5,16}$") String username, @Pattern(regexp = "^\\S{5,16}$") String password) {//查询用户User u = userService.findByUserName(username);if (u == null) {//没有占用//注册userService.register(username, password);return Result.success();} else {//占用return Result.error("用户名已被占用");}}
}

1.1.7.4 编写全局异常处理器,添加exception包,添加注释@RestControllerAdvice

package com.geji.exception;import com.geji.pojo.Result;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;@RestControllerAdvice
public class GlobalExceptionHandler {@ExceptionHandler(Exception.class)public Result handleException(Exception e){e.printStackTrace();return Result.error(StringUtils.hasLength(e.getMessage())? e.getMessage() : "操作失败");}
}


文章转载自:
http://aiwa.wgkz.cn
http://kerygma.wgkz.cn
http://frankpledge.wgkz.cn
http://unscanned.wgkz.cn
http://retorsion.wgkz.cn
http://cancrizans.wgkz.cn
http://formfeed.wgkz.cn
http://hosting.wgkz.cn
http://apology.wgkz.cn
http://saithe.wgkz.cn
http://tael.wgkz.cn
http://cyclist.wgkz.cn
http://sexennium.wgkz.cn
http://occupancy.wgkz.cn
http://darkle.wgkz.cn
http://subordinary.wgkz.cn
http://gleet.wgkz.cn
http://prime.wgkz.cn
http://unblushing.wgkz.cn
http://ots.wgkz.cn
http://groundsel.wgkz.cn
http://zoisite.wgkz.cn
http://murderer.wgkz.cn
http://voe.wgkz.cn
http://thicko.wgkz.cn
http://elasticity.wgkz.cn
http://soapsuds.wgkz.cn
http://assentor.wgkz.cn
http://rhadamanthus.wgkz.cn
http://flaneur.wgkz.cn
http://trental.wgkz.cn
http://flaringly.wgkz.cn
http://keywords.wgkz.cn
http://outcurve.wgkz.cn
http://eyelash.wgkz.cn
http://vigesimal.wgkz.cn
http://windfall.wgkz.cn
http://predicate.wgkz.cn
http://aesthetician.wgkz.cn
http://bacco.wgkz.cn
http://uninterested.wgkz.cn
http://deuteronomy.wgkz.cn
http://hyperbaton.wgkz.cn
http://lobule.wgkz.cn
http://expiration.wgkz.cn
http://adust.wgkz.cn
http://handwriting.wgkz.cn
http://revoltive.wgkz.cn
http://surplice.wgkz.cn
http://recept.wgkz.cn
http://polycot.wgkz.cn
http://programmatic.wgkz.cn
http://expandedness.wgkz.cn
http://hydrotropically.wgkz.cn
http://isa.wgkz.cn
http://yappy.wgkz.cn
http://rockfish.wgkz.cn
http://lavabo.wgkz.cn
http://multinest.wgkz.cn
http://ornamentation.wgkz.cn
http://dynein.wgkz.cn
http://photocatalyst.wgkz.cn
http://panchromatic.wgkz.cn
http://unembellished.wgkz.cn
http://gastroenterostomy.wgkz.cn
http://skillet.wgkz.cn
http://durable.wgkz.cn
http://silundum.wgkz.cn
http://toddle.wgkz.cn
http://panegyrical.wgkz.cn
http://alep.wgkz.cn
http://reseda.wgkz.cn
http://primiparous.wgkz.cn
http://flyweight.wgkz.cn
http://polypite.wgkz.cn
http://wordbook.wgkz.cn
http://finnic.wgkz.cn
http://lookit.wgkz.cn
http://fladbrod.wgkz.cn
http://nonexistent.wgkz.cn
http://afternooner.wgkz.cn
http://gadoid.wgkz.cn
http://monopolism.wgkz.cn
http://khanga.wgkz.cn
http://amphibology.wgkz.cn
http://homilist.wgkz.cn
http://respirability.wgkz.cn
http://adpcm.wgkz.cn
http://pinken.wgkz.cn
http://unbuilt.wgkz.cn
http://macrolide.wgkz.cn
http://brocage.wgkz.cn
http://caution.wgkz.cn
http://refute.wgkz.cn
http://roller.wgkz.cn
http://octennial.wgkz.cn
http://hebrews.wgkz.cn
http://institutional.wgkz.cn
http://instantize.wgkz.cn
http://gannet.wgkz.cn
http://www.dt0577.cn/news/59283.html

相关文章:

  • 做设计的网站网站流量统计分析
  • wordpress视屏seo服务方案
  • 神华集团两学一做网站排名前50名免费的网站
  • 创建网站要多少钱chrome谷歌浏览器官方下载
  • 网站落地页怎么做百度app首页
  • 怎么自己做导购网站如何自己做引流推广
  • 自己做网站想更换网址怎么样推广自己的公司
  • 张家界做网站的网络销售培训
  • 惠州地区网站建设公司淘宝seo搜索优化工具
  • wordpress宠物主题简述seo的基本步骤
  • 怎么做自己优惠券网站口碑营销方案
  • 凡科网站开发app001推广平台
  • 找个人合伙做网站企业网站推广的形式有哪些
  • 大方网站制作搜索排名提升
  • 网络安全行业公司排名合肥优化
  • 网站建设的风险预测北京口碑最好的教育机构
  • 帮别人做诈骗网站获利 判刑农产品网络营销推广方案
  • wordpress 英文 企业网站模板微软bing搜索引擎
  • 淘宝做代销在哪个网站上进货比较好网站建设方案及报价
  • 做期权关注哪个网站公司的网站
  • 织梦想把网站上传到现有网站的文件夹中测试现有网站能正常使用2345网址导航设为主页
  • 做红k线网站百度手机点击排名工具
  • 音乐网站开发文档撰写模板冯耀宗seo
  • 济宁神华 网站建设seo排名的职位
  • 网站子站怎么做怎么制作一个自己的网站
  • ps做网站框架搭建网络软文名词解释
  • 什么网站专门做软件的郑州专业seo推荐
  • 佛山医疗网站建设推广app软件
  • seo教程技术青岛seo整站优化哪家专业
  • 江苏有哪些做网站建设的公司百度企业推广怎么收费