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

网站开发成本如何入账建站小程序

网站开发成本如何入账,建站小程序,wordpress在线客服,网站改版方案原则完成登录且优化: 未优化做简单的判断: 全部异常抓捕 优化:返回的是json的格式 BusinessException:所有的错误放到这个容器中,全局异常从这个类中调用 BusinessException: package com.lya.lyaspshop.exce…

完成登录且优化:

未优化做简单的判断:

全部异常抓捕

优化:返回的是json的格式

BusinessException:所有的错误放到这个容器中,全局异常从这个类中调用

BusinessException:
package com.lya.lyaspshop.exception;import com.lya.lyaspshop.resp.JsonResponseStatus;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;@EqualsAndHashCode(callSuper = true)//自动生成equals和hashCode方法
@AllArgsConstructor//自动生成全参构造函数
@NoArgsConstructor//自动生成无参构造函数
@Data//自动生成getters、setters、toString
public class BusinessException extends RuntimeException {//    所有的错误放到这个容器中,全局异常从这个类中调用private JsonResponseStatus jsonResponseStatus;}

GlobalExceptionHandler

package com.lya.lyaspshop.exception;import com.lya.lyaspshop.resp.JsonResponseBody;
import com.lya.lyaspshop.resp.JsonResponseStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;@RestControllerAdvice//用于声明这个类是一个全局异常处理器
@Slf4j
public class GlobalExceptionHandler {//    已知错误@ExceptionHandler(BusinessException.class)//声明这是一个异常处理方法public JsonResponseBody<?> exceptionBusinessException(BusinessException e) {JsonResponseStatus status = e.getJsonResponseStatus();log.info(status.getMsg());//使用日志打印异常的消息。return JsonResponseBody.other(status);}//    未知错误@ExceptionHandler(Throwable.class)public JsonResponseBody<?> exceptionThrowable(Throwable e) {log.info(e.getMessage());//使用日志打印异常的消息。return JsonResponseBody.other(JsonResponseStatus.UN_KNOWN);}
}

这里为啥要写这两个类:

理解:编写 GlobalExceptionHandler 类可以集中处理应用程序中的各种异常,提高代码的可维护性,同时简化了代码

jsr303

//这里体现了为啥要建这个类:1.降低代码耦合度:VO 实体类可以将数据从数据库实体类中解耦           2.用户进行权限校验等操作,业务逻辑与数据访问层分离开来,提高代码的可读性和可维护性
如果我直接在数据库的实体类中去

<!-- jsr303 -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-validation</artifactId>
</dependency>

实体:使用注解

@NotBlank

抛一个异常:

报错信息:

这个是时候错误已经该变:

连接日志查看:

遇到一个问题:这里就是异常就是使用的303自己带的异常,不要写其他的

前后台的加密过程:

从前台发送请求来:

引入加密js

		<script src="http://www.gongjuji.net/Content/files/jquery.md5.js" type="text/javascript"></script>

加密成功:

加密后数据库的原密码肯定是不对的了。这我们使用debug给截取到密码存入数据库中。

集成redis

<!--        redis--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency>

RedisServiceImpl 

package com.lya.lyaspshop.service.impl;import com.lya.lyaspshop.pojo.User;
import com.lya.lyaspshop.service.IRedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;import java.util.concurrent.TimeUnit;@Service
public class RedisServiceImpl implements IRedisService {@Autowiredprivate RedisTemplate<String, Object> redisTemplate;//    往redis设置@Overridepublic void setUserToRedis(String token, User user) {redisTemplate.opsForValue().set("user:" + token, user, 7200, TimeUnit.SECONDS);}@Overridepublic User getUserByToken(String token) {return (User) redisTemplate.opsForValue().get("user:" + token);}}

IRedisService

package com.lya.lyaspshop.service;import com.lya.lyaspshop.pojo.User;public interface IRedisService {/*** 将登陆User对象保存到Redis中,并以Token为键*/void setUserToRedis(String token, User user);/*** 根据token令牌获取redis中存储的user对象*/User getUserByToken(String token);}

redisService.setUserToRedis(token, one);

加入cookie

使用CookieUtils类:

package com.lya.lyaspshop.utils;import lombok.extern.slf4j.Slf4j;import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;@Slf4j
public class CookieUtils {/*** @Description: 得到Cookie的值, 不编码*/public static String getCookieValue(HttpServletRequest request, String cookieName) {return getCookieValue(request, cookieName, false);}/*** @Description: 得到Cookie的值*/public static String getCookieValue(HttpServletRequest request, String cookieName, boolean isDecoder) {Cookie[] cookieList = request.getCookies();if (cookieList == null || cookieName == null) {return null;}String retValue = null;try {for (int i = 0; i < cookieList.length; i++) {if (cookieList[i].getName().equals(cookieName)) {if (isDecoder) {retValue = URLDecoder.decode(cookieList[i].getValue(), "UTF-8");} else {retValue = cookieList[i].getValue();}break;}}} catch (UnsupportedEncodingException e) {e.printStackTrace();}return retValue;}/*** @Description: 得到Cookie的值*/public static String getCookieValue(HttpServletRequest request, String cookieName, String encodeString) {Cookie[] cookieList = request.getCookies();if (cookieList == null || cookieName == null) {return null;}String retValue = null;try {for (int i = 0; i < cookieList.length; i++) {if (cookieList[i].getName().equals(cookieName)) {retValue = URLDecoder.decode(cookieList[i].getValue(), encodeString);break;}}} catch (UnsupportedEncodingException e) {e.printStackTrace();}return retValue;}/*** @Description: 设置Cookie的值 不设置生效时间默认浏览器关闭即失效,也不编码*/public static void setCookie(HttpServletRequest request, HttpServletResponse response, String cookieName,String cookieValue) {setCookie(request, response, cookieName, cookieValue, -1);}/*** @param request* @param response* @param cookieName* @param cookieValue* @param cookieMaxage* @Description: 设置Cookie的值 在指定时间内生效,但不编码*/public static void setCookie(HttpServletRequest request, HttpServletResponse response, String cookieName,String cookieValue, int cookieMaxage) {setCookie(request, response, cookieName, cookieValue, cookieMaxage, false);}/*** @Description: 设置Cookie的值 不设置生效时间,但编码* 在服务器被创建,返回给客户端,并且保存客户端* 如果设置了SETMAXAGE(int seconds),会把cookie保存在客户端的硬盘中* 如果没有设置,会默认把cookie保存在浏览器的内存中* 一旦设置setPath():只能通过设置的路径才能获取到当前的cookie信息*/public static void setCookie(HttpServletRequest request, HttpServletResponse response, String cookieName,String cookieValue, boolean isEncode) {setCookie(request, response, cookieName, cookieValue, -1, isEncode);}/*** @Description: 设置Cookie的值 在指定时间内生效, 编码参数*/public static void setCookie(HttpServletRequest request, HttpServletResponse response, String cookieName,String cookieValue, int cookieMaxage, boolean isEncode) {doSetCookie(request, response, cookieName, cookieValue, cookieMaxage, isEncode);}/*** @Description: 设置Cookie的值 在指定时间内生效, 编码参数(指定编码)*/public static void setCookie(HttpServletRequest request, HttpServletResponse response, String cookieName,String cookieValue, int cookieMaxage, String encodeString) {doSetCookie(request, response, cookieName, cookieValue, cookieMaxage, encodeString);}/*** @Description: 删除Cookie带cookie域名*/public static void deleteCookie(HttpServletRequest request, HttpServletResponse response,String cookieName) {doSetCookie(request, response, cookieName, null, -1, false);}/*** @Description: 设置Cookie的值,并使其在指定时间内生效*/private static final void doSetCookie(HttpServletRequest request, HttpServletResponse response,String cookieName, String cookieValue, int cookieMaxage, boolean isEncode) {try {if (cookieValue == null) {cookieValue = "";} else if (isEncode) {cookieValue = URLEncoder.encode(cookieValue, "utf-8");}Cookie cookie = new Cookie(cookieName, cookieValue);if (cookieMaxage > 0)cookie.setMaxAge(cookieMaxage);if (null != request) {// 设置域名的cookieString domainName = getDomainName(request);log.info("========== domainName: {} ==========", domainName);if (!"localhost".equals(domainName)) {cookie.setDomain(domainName);}}cookie.setPath("/");response.addCookie(cookie);} catch (Exception e) {e.printStackTrace();}}/*** @Description: 设置Cookie的值,并使其在指定时间内生效*/private static void doSetCookie(HttpServletRequest request, HttpServletResponse response,String cookieName, String cookieValue, int cookieMaxage, String encodeString) {try {if (cookieValue == null) {cookieValue = "";} else {cookieValue = URLEncoder.encode(cookieValue, encodeString);}Cookie cookie = new Cookie(cookieName, cookieValue);if (cookieMaxage > 0)cookie.setMaxAge(cookieMaxage);if (null != request) {// 设置域名的cookieString domainName = getDomainName(request);log.info("========== domainName: {} ==========", domainName);if (!"localhost".equals(domainName)) {cookie.setDomain(domainName);}}cookie.setPath("/");response.addCookie(cookie);} catch (Exception e) {e.printStackTrace();}}/*** @Description: 得到cookie的域名*/private static String getDomainName(HttpServletRequest request) {String domainName = null;String serverName = request.getRequestURL().toString();if (serverName == null || serverName.equals("")) {domainName = "";} else {serverName = serverName.toLowerCase();serverName = serverName.substring(7);final int end = serverName.indexOf("/");serverName = serverName.substring(0, end);if (serverName.indexOf(":") > 0) {String[] ary = serverName.split("\\:");serverName = ary[0];}final String[] domains = serverName.split("\\.");int len = domains.length;if (len > 3 && !isIp(serverName)) {// www.xxx.com.cndomainName = "." + domains[len - 3] + "." + domains[len - 2] + "." + domains[len - 1];} else if (len <= 3 && len > 1) {// xxx.com or xxx.cndomainName = "." + domains[len - 2] + "." + domains[len - 1];} else {domainName = serverName;}}return domainName;}public static String trimSpaces(String IP) {//去掉IP字符串前后所有的空格while (IP.startsWith(" ")) {IP = IP.substring(1, IP.length()).trim();}while (IP.endsWith(" ")) {IP = IP.substring(0, IP.length() - 1).trim();}return IP;}public static boolean isIp(String IP) {//判断是否是一个IPboolean b = false;IP = trimSpaces(IP);if (IP.matches("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}")) {String s[] = IP.split("\\.");if (Integer.parseInt(s[0]) < 255)if (Integer.parseInt(s[1]) < 255)if (Integer.parseInt(s[2]) < 255)if (Integer.parseInt(s[3]) < 255)b = true;}return b;}}

自定义注解

根据@isNoblank去写:

这三行代码必须写的:

    boolean require() default false;String expr() default "";String message() default "";

IsMobile
package com.lya.lyaspshop.core;import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;@Documented
@Constraint(validatedBy = {IsMobileConstraintValidator.class})
@Target({FIELD})
@Retention(RUNTIME)
public @interface IsMobile {boolean require() default false;String expr() default "";String message() default "";Class<?>[] groups() default {};Class<? extends Payload>[] payload() default {};}

IsMobileConstraintValidator 

package com.lya.lyaspshop.core;import com.baomidou.mybatisplus.core.toolkit.StringUtils;import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;/*** @author CloudJun*/
public class IsMobileConstraintValidator implements ConstraintValidator<IsMobile, String> {private boolean require;private String expr;@Overridepublic void initialize(IsMobile isMobile) {expr = isMobile.expr();require = isMobile.require();}@Overridepublic boolean isValid(String value, ConstraintValidatorContext context) {if (!require) return true;if (StringUtils.isEmpty(value)) return false;return value.matches(expr);}}

优化:定义一个常量类(使用的定值往这里调用就行)

package com.lya.lyaspshop.core;public abstract class Constants {//    常类public static final String EXPR_MOBILE = "(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}";public static final String EXPR_PASSWORD = "[a-zA-Z0-9]{32}";public static final String USER_TOKEN_PREFIX = "user:";}


文章转载自:
http://flippant.Lnnc.cn
http://chugalug.Lnnc.cn
http://dryad.Lnnc.cn
http://vesuvianite.Lnnc.cn
http://pesticide.Lnnc.cn
http://barnaby.Lnnc.cn
http://falernian.Lnnc.cn
http://landmine.Lnnc.cn
http://megabuck.Lnnc.cn
http://ascender.Lnnc.cn
http://turboshaft.Lnnc.cn
http://mogo.Lnnc.cn
http://cowlstaff.Lnnc.cn
http://inning.Lnnc.cn
http://monophagous.Lnnc.cn
http://violetta.Lnnc.cn
http://miniver.Lnnc.cn
http://nonrepudiation.Lnnc.cn
http://footwall.Lnnc.cn
http://philhellenist.Lnnc.cn
http://legatine.Lnnc.cn
http://doggone.Lnnc.cn
http://dornick.Lnnc.cn
http://pantoum.Lnnc.cn
http://hz.Lnnc.cn
http://generatrix.Lnnc.cn
http://staghound.Lnnc.cn
http://ecstasy.Lnnc.cn
http://menservants.Lnnc.cn
http://incomprehension.Lnnc.cn
http://unalloyed.Lnnc.cn
http://recusation.Lnnc.cn
http://sepoy.Lnnc.cn
http://finch.Lnnc.cn
http://warren.Lnnc.cn
http://doggy.Lnnc.cn
http://missend.Lnnc.cn
http://superplasticity.Lnnc.cn
http://isoagglutination.Lnnc.cn
http://heparin.Lnnc.cn
http://supraconscious.Lnnc.cn
http://unfamed.Lnnc.cn
http://livable.Lnnc.cn
http://smew.Lnnc.cn
http://atypical.Lnnc.cn
http://joneses.Lnnc.cn
http://isohyet.Lnnc.cn
http://glycyrrhiza.Lnnc.cn
http://nounal.Lnnc.cn
http://stockyard.Lnnc.cn
http://sabbatarian.Lnnc.cn
http://abbatial.Lnnc.cn
http://wax.Lnnc.cn
http://impending.Lnnc.cn
http://metainfective.Lnnc.cn
http://cent.Lnnc.cn
http://bimolecular.Lnnc.cn
http://tovarish.Lnnc.cn
http://phoenicaceous.Lnnc.cn
http://douma.Lnnc.cn
http://nonutility.Lnnc.cn
http://tripersonal.Lnnc.cn
http://zoolite.Lnnc.cn
http://coatroom.Lnnc.cn
http://hallux.Lnnc.cn
http://wayworn.Lnnc.cn
http://bazoom.Lnnc.cn
http://fluridizer.Lnnc.cn
http://jurat.Lnnc.cn
http://geometrise.Lnnc.cn
http://lytta.Lnnc.cn
http://ningsia.Lnnc.cn
http://subagency.Lnnc.cn
http://reticulation.Lnnc.cn
http://yester.Lnnc.cn
http://dirt.Lnnc.cn
http://dandriff.Lnnc.cn
http://despiritualize.Lnnc.cn
http://retorsion.Lnnc.cn
http://veejay.Lnnc.cn
http://microlitre.Lnnc.cn
http://preadapted.Lnnc.cn
http://quietive.Lnnc.cn
http://markdown.Lnnc.cn
http://abbreviatory.Lnnc.cn
http://vulcanite.Lnnc.cn
http://amperage.Lnnc.cn
http://eurobank.Lnnc.cn
http://myeloproliferative.Lnnc.cn
http://candidature.Lnnc.cn
http://pickaninny.Lnnc.cn
http://platinous.Lnnc.cn
http://proustite.Lnnc.cn
http://safen.Lnnc.cn
http://filbert.Lnnc.cn
http://innoxious.Lnnc.cn
http://alecost.Lnnc.cn
http://detestable.Lnnc.cn
http://appeal.Lnnc.cn
http://perchlorinate.Lnnc.cn
http://www.dt0577.cn/news/113509.html

相关文章:

  • 中山网站建设优化百度快速收录权限
  • 做网站 然后百度推广100种宣传方式
  • 怎么做微网站推广谷歌竞价排名推广公司
  • 百度做的网站百度认证是什么
  • 棋牌游戏wordpressseo网络营销是什么意思
  • 黄山市建设工程造价管理站网站有没有免费的crm系统软件
  • 深深深视频在线观看成都最好的网站推广优化公司
  • 鸡西市城乡建设局网站seo合作
  • 学做日本菜的网站好aso优化app推广
  • 巴中建设银行网站电商推广和网络推广的策略
  • 建设网站对于电商的作用是?百度识图找原图
  • 怎么建设一个国外的网站b站视频推广网站400
  • 如何自己做外贸网站seo网站编辑是做什么的
  • 复兴专业做网站seo监控系统
  • 长春疫情最新消息今天封城了seo服务公司上海
  • 国内著名网站建设公司百度邮箱注册入口
  • 网页后台常用设计尺寸seo在哪学
  • 网站建设需要怎么做微信搜一搜seo优化
  • 网站 毕业设计代做seo零基础入门教程
  • 企业如何申请网站北京搜索优化推广公司
  • asp网站漏洞修复插件seo外包优化服务商
  • 手机网站 分辨率网站统计器
  • 福田网站制作比较好的app推广赚钱
  • 微信网站apiseo 技术优化
  • 门户网站建设哪家便宜搜狗推广登录平台
  • 注册软件开发公司需要什么条件seochan是什么意思
  • 成都市城乡建设网站百度网页游戏大厅
  • wordpress时间标签苏州网站关键字优化
  • 苹果手机推广网站制作婚恋网站排名前三
  • 做海报那个网站好网站播放视频速度优化