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

微山建设局网站自媒体培训

微山建设局网站,自媒体培训,wordpress 后台错乱,自学考试网站建设与管理本文总结苍穹外卖项目中可复用的通用设计 sky-common constant存放常量类&#xff0c;包括消息常量&#xff0c;状态常量 context是上下文对象&#xff0c;封装了threadlocal package com.sky.context;public class BaseContext {public static ThreadLocal<Long> thre…

本文总结苍穹外卖项目中可复用的通用设计

sky-common

在这里插入图片描述
constant存放常量类,包括消息常量,状态常量
context是上下文对象,封装了threadlocal

package com.sky.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();}}

enumeration存放枚举类
exception存放自定义异常类,用于抛出自定义异常

/*** 业务异常*/
public class BaseException extends RuntimeException {public BaseException() {}public BaseException(String msg) {super(msg);}}
/*** 账号被锁定异常*/
public class AccountLockedException extends BaseException {public AccountLockedException() {}public AccountLockedException(String msg) {super(msg);}}

properties用于配置工具类的属性,@ConfigurationProperties(prefix = “sky.alioss”)读取application.yml中以sky.alioss为前缀的具体值

@Component
@ConfigurationProperties(prefix = "sky.alioss")
@Data
public class AliOssProperties {private String endpoint;private String accessKeyId;private String accessKeySecret;private String bucketName;
}

utils封装具体的工具类
result封装返回给前端的响应类
json封装对象映射器(基于jackson将Java对象转为json,或者将json转为Java对象),定制 JSON 与 Java 对象之间的序列化(对象转JSON)和反序列化(JSON转对象)规则

sky-pojo

在这里插入图片描述

entity封装实体类,dto封装前端向后端传递数据的对象,通常是entity中某个类的部分数据,vo封装后端向前端返回数据的对象,按照前端需要的数据格式进行设计

sky-server

在这里插入图片描述
annotationaspect负责springboot的aop切面编程
config用于注册Bean

WebMvcConfiguration

/*** 配置类,注册web层相关组件*/
@Configuration
@Slf4j
public class WebMvcConfiguration extends WebMvcConfigurationSupport {@Autowiredprivate JwtTokenAdminInterceptor jwtTokenAdminInterceptor;@Autowiredprivate JwtTokenUserInterceptor jwtTokenUserInterceptor;/*** 注册自定义拦截器** @param registry*/protected void addInterceptors(InterceptorRegistry registry) {log.info("开始注册自定义拦截器...");registry.addInterceptor(jwtTokenAdminInterceptor).addPathPatterns("/admin/**").excludePathPatterns("/admin/employee/login");registry.addInterceptor(jwtTokenUserInterceptor).addPathPatterns("/user/**").excludePathPatterns("/user/user/login").excludePathPatterns("/user/shop/status");}/*** 通过knife4j生成接口文档* @return*/@Beanpublic Docket docket1() {ApiInfo apiInfo = new ApiInfoBuilder().title("苍穹外卖项目接口文档").version("2.0").description("苍穹外卖项目接口文档").build();Docket docket = new Docket(DocumentationType.SWAGGER_2).groupName("管理端接口").apiInfo(apiInfo).select().apis(RequestHandlerSelectors.basePackage("com.sky.controller.admin")).paths(PathSelectors.any()).build();return docket;}@Beanpublic Docket docket2() {ApiInfo apiInfo = new ApiInfoBuilder().title("苍穹外卖项目接口文档").version("2.0").description("苍穹外卖项目接口文档").build();Docket docket = new Docket(DocumentationType.SWAGGER_2).groupName("用户端接口").apiInfo(apiInfo).select().apis(RequestHandlerSelectors.basePackage("com.sky.controller.user")).paths(PathSelectors.any()).build();return docket;}/*** 设置静态资源映射* @param registry*/protected void addResourceHandlers(ResourceHandlerRegistry registry) {registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");}/*** 扩展spring mvc 的消息转换器* @param converters*/@Overrideprotected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {log.info("扩展消息转换器");//创建一个消息转换器对象MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();//为消息转换器设置一个对象转换器,对象转换器可将java对象序列化converter.setObjectMapper(new JacksonObjectMapper());//将消息转换器添加到convertersconverters.add(0,converter);}}

z

public class OssConfiguration {@Bean@ConditionalOnMissingBeanpublic AliOssUtil aliOssUtil(AliOssProperties aliOssProperties) {log.info("开始创建阿里云上传文件工具类对象",aliOssProperties);return new AliOssUtil(aliOssProperties.getEndpoint(),aliOssProperties.getAccessKeyId(),aliOssProperties.getAccessKeySecret(),aliOssProperties.getBucketName());}
}

这里用到前面common中提到的AliOssProperties来创建AliOssUtil类
handle用于定义全局异常处理器,处理各个地方抛出的异常

/*** 全局异常处理器,处理项目中抛出的业务异常*/
@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){String msg=ex.getMessage();if(msg.contains("Duplicate entry")){String[] msgs=msg.split(" ");String username=msgs[2];return Result.error(username+MessageConstant.ALREADY_EXISTS);}else{return Result.error(MessageConstant.UNKNOWN_ERROR);}}}

@RestControllerAdvice:表示这是一个全局异常处理类,会拦截所有 @RestController 或 @Controller 抛出的异常,并将处理结果以 JSON 格式返回给前端。
@ExceptionHandler :是 Spring 框架中用于集中处理异常的核心注解,它的核心作用是捕获并处理控制器(Controller)中抛出的特定异常,返回统一的错误响应。
interceptor用于定义拦截器
task定义定时任务类,与websocket配合使用

http://www.dtcms.com/wzjs/54105.html

相关文章:

  • 找建站公司百度一下百度网站
  • CSS3网站开发59软文网
  • 做壁画在哪个网站建设网站公司
  • 大连网站制作培训优秀网站网页设计图片
  • 怎样用jsp做网站百度指数如何分析
  • 台州模板建站代理全网品牌推广
  • 阿里巴巴的免费b2b网站我想在百度上做广告怎么做
  • 麻辣烫配方教授网站怎么做怎样注册自己网站的域名
  • 襄阳做网站的前端性能优化
  • 网站建设设计设计烘焙甜点培训学校
  • 如何做网站授权矿泉水软文广告500字
  • 政府网站平台建设与管理福州seo快速排名软件
  • 专题网站怎么做seo视频教程百度云
  • 社区源码appseo顾问服务咨询
  • 常州自助建站我的百度账号登录
  • 西安公司网站如何建设中国局势最新消息今天
  • 如何做网站活动封面站长工具推荐
  • 网站建设代码seo网站推广多少钱
  • 猎头公司网站建设大数据营销
  • php 企业网站百度一下进入首页
  • 什么网站可以做任务领赏金品牌推广和品牌营销
  • 护士公共课在哪个网站做谷歌seo外链平台
  • 网站开发没有完成 需要赔偿多少网站建设公司企业网站
  • 广东省住建局官网关键词排名优化软件
  • cms网站群查询网站信息
  • 杭州网站建设icp备刚刚北京传来重大消息
  • 达美网站建设seo智能优化软件
  • 怎样设计app软件厦门网站seo哪家好
  • wordpress qq邮箱留言济南公司网站推广优化最大的
  • 百度广告多少钱百度seo优化推广公司