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

网站建设经验大总结wordpress海报功能

网站建设经验大总结,wordpress海报功能,中国4a广告公司100强,网站建设属于哪一类商标前言#xff1a; 在我们上一篇博客中#xff0c;实现Freemarke的增删改查#xff0c;今天分享的是关于SpringBoot Starter机制-- 1.SpringBoot Starter 1.1.什么是SpringBoot Starter SpringBoot中的starter是一种非常重要的机制(自动化配置)#xff0c;能够抛弃以前繁杂… 前言 在我们上一篇博客中实现Freemarke的增删改查今天分享的是关于SpringBoot Starter机制-- 1.SpringBoot Starter 1.1.什么是SpringBoot Starter SpringBoot中的starter是一种非常重要的机制(自动化配置)能够抛弃以前繁杂的配置将其统一集成进starter应用者只需要在maven中引入starter依赖SpringBoot就能自动扫描到要加载的信息并启动相应的默认配置。starter让我们摆脱了各种依赖库的处理需要配置各种信息的困扰。 SpringBoot会自动通过classpath路径下的类发现需要的Bean并注册进IOC容器。SpringBoot提供了针对日常企业应用研发各种场景的spring-boot-starter依赖模块。 所有这些依赖模块都遵循着约定成俗的默认配置并允许我们调整这些配置即遵循“约定大于配置”的理念。 1.2.为什么要使用SpringBoot Starter 在我们的日常开发工作中经常会有一些独立于业务之外的配置模块我们经常将其放到一个特定的包下然后如果另一个工程需要复用这块功能的时候需要将代码硬拷贝到另一个工程重新集成一遍麻烦至极。如果我们将这些可独立于业务代码之外的功能配置模块封装成一个个starter复用的时候只需要将其在pom中引用依赖即可 SpringBoot为我们完成自动装配简直不要太爽。 1.3.应用场景 在我们的日常开发工作中可能会需要开发一个通用模块以供其它工程复用。SpringBoot就为我们提供这样的功能机制我们可以把我们的通用模块封装成一个个starter这样其它工程复用的时候只需要在pom中引用依赖即可由SpringBoot为我们完成自动装配。 常见应用场景 1通用模块-短信发送模块今天案例就以模拟短信发送模块 2基于AOP技术实现日志切面 3分布式雪花IDLong转String解决精度问题 4微服务项目的数据库连接池配置 5微服务项目的每个模块都要访问redis数据库每个模块都要配置redisTemplate 2.综合案例短信发送模块 步骤1通过注解获取到yml定义的值        SmsProperties package com.lya.smsspringbootstart;import lombok.Data; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component;/*** 类名称密钥实体* author 程序猿-小李哥* site www.xiaolige.com* company 猪八戒有限集团* create 2023-12-14-18:48*/Data//注解提供setget Component//定义组件作用交给spring管理 public class SmsProperties{ //应用标识Value(${sms.key})private String key; //应用密钥Value(${sms.secret})private String secret; }步骤2通过接口方式引入 ISmsService package service;public interface ISmsService {/*** 发送短信** param phone 要发送的手机号* param data 要发送的内容*/void send(String phone, String data);}SmsServiceImpl package service;import com.lya.smsspringbootstart.SmsProperties;public class SmsServiceImpl implements ISmsService {private SmsProperties smsProperties; //nullpublic SmsServiceImpl(SmsProperties smsProperties) {this.smsPropertiessmsProperties;}Overridepublic void send(String phone, String data) {String key smsProperties.getKey();String secret smsProperties.getSecret();System.out.println(接入短信系统Key key ,Secret secret);System.out.println(短信发送phone phone data data);}}SmsSpringbootStartApplicationTests package com.lya.smsspringbootstart;import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import service.SmsServiceImpl;SpringBootTest class SmsSpringbootStartApplicationTests {Autowiredprivate SmsProperties smsPropre;Testvoid contextLoads() { // System.out.println(smsPropre);new SmsServiceImpl(smsPropre).send(1521,好久不见望君勿念);}}好了到这里效果已经实现了但是有许多的地方也麻烦很多的地方要自己手填。针对性做了优化 配置注解 ConfigurationProperties(prefix sms) 将写好的配置进行打包(把application.yml中定义的smskeysecretenable给注掉) 2.1其他项目引入步骤 引入依赖 !-- 短信验证--dependencygroupIdcom.zking/groupIdartifactIdsms-spring-boot-start/artifactIdversion0.0.1-SNAPSHOT/version/dependency 这里的groupId 要与启动类中的一致 配置application.yml #短信服务 sms:key: 1001secret: 2002enable: true 创建Junit测试 package com.zking.spboot;import com.zking.smsspringbootstart.SmsSpringBootStartApplication; import com.zking.smsspringbootstart.service.ISmsService; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest;SpringBootTest(classes SmsSpringBootStartApplication.class) class SpbootApplicationTests {Autowiredprivate ISmsService smsService;Testpublic void send() {smsService.send(13199864,好久不见了);}}模拟效果 3.综合案例基于AOP技术实现日志切面模块 3.1准备工作 重新创建一个项目准备步骤与上面类似 3.2 导入pom依赖 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-configuration-processor/artifactIdoptionaltrue/optional /dependency 3.3创建切面配置类Properties WebLogProperties.java package com.lya.aspect.config;import org.springframework.boot.context.properties.ConfigurationProperties;/*** AOP日志配置类*/ ConfigurationProperties(prefix scloud.weblog) public class WebLogProperties {private boolean enabled;//TODO } 3.4 实现基于AOP技术的日志切面功能 WebLogAspect.java package com.lya.aspect.config;import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; import org.springframework.stereotype.Component; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes;import javax.servlet.http.HttpServletRequest; import java.util.Arrays;Aspect Component Slf4j public class WebLogAspect {Pointcut(execution(* *..*Controller.*(..)))public void webLog(){}Before(webLog())public void doBefore(JoinPoint joinPoint) throws Throwable {// 接收到请求记录请求内容ServletRequestAttributes attributes (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();HttpServletRequest request attributes.getRequest();// 记录下请求内容log.info(开始服务:{}, request.getRequestURL().toString());log.info(客户端IP :{} , request.getRemoteAddr());log.info(参数值 :{}, Arrays.toString(joinPoint.getArgs()));}AfterReturning(returning ret, pointcut webLog())public void doAfterReturning(Object ret) throws Throwable {// 处理完请求返回内容log.info(返回值 : {} , ret);}} 3.5 创建自动配置类 WebLogConfig.java package com.lya.aspect.config;import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;/*** ConditionalOnProperty* 配置属性a:* 1:不配置a matchifmissingfalse 不满足 matchifmissingtrue 满足* 2:配置afalse matchifmissingfalse 不满足 matchifmissingtrue 不满足* 3:配置atrue matchifmissingfalse 满足 matchifmissingtrue 满足*/ Configuration EnableConfigurationProperties({WebLogProperties.class}) ConditionalOnProperty(prefix lya.weblog,value enabled,matchIfMissing true) public class WebLogConfig {BeanConditionalOnMissingBeanpublic WebLogAspect webLogAspect(){return new WebLogAspect();} } 编写spring.factories文件 org.springframework.boot.autoconfigure.EnableAutoConfiguration\com.lya.aspect.config.WebLogAspect,\com.lya.aspect.config.WebLogConfig 配置application.yml     路径仅供参考实际路径根据自身的项目路径为主  案例目录 效果
http://www.zqtcl.cn/news/880193/

相关文章:

  • 关于做营销型网站的建议网页小游戏无需登录
  • 网站短期培训能学什么高校网站建设评比标准
  • 做外贸什么网站比较好做dede鲜花网站模板下载
  • 网站广告推广怎么做网站怎么优化关键词排名
  • 怎样做易支付网站数字化校园建设网站
  • 东莞做网站哪里好公司网站维护怎么维护
  • 微信网站界面设计江阴网站开发公司电话
  • 手机制作网站的软件离石做网站的网络公司
  • 贺州住房和城乡建设部网站广州商城网站建设地址
  • 响应式网站报价服务器上的wordpress
  • 做培训的都上哪些网站东莞网站新站排名
  • 济南网站制郑州快速建站公司
  • 网站推广企业网站建设属于什么工作
  • 公司做网站还是做app用土豆做美食的视频网站
  • 做网站除了广告还有什么收入的中国计算机技术职业资格网
  • 陕西建设银行网站查排名的软件有哪些
  • 企业网站备案教程北京专业做网站的
  • 音乐网站如何建设的如何做学校网站
  • 济南比较好的网站开发公司个人注册网站怎么注册
  • 济南高端网站设计策划图书馆网站建设情况汇报
  • 知识付费网站建设做网站源码
  • php网站开发实训报告书怎么做兼职类网站吗
  • 建设银行u盾用网站打不开中企动力值不值得入职
  • 织梦做的网站有点慢商贸网站
  • 海外红酒网站建设wordpress 分类 文章
  • 七星彩网站建设wordpress w3
  • 广州网站建设全包百度怎么优化关键词排名
  • 中山网站制作服务公司做环评的网站
  • 江山市住房和城乡建设局网站iis部署网站 错误400
  • 网站域名如何备案建设厅公积金中心网站