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

有的网站网速慢哪个网站建设平台支持花呗分期

有的网站网速慢,哪个网站建设平台支持花呗分期,乐清做网站建设公司哪家好,个人优秀网站如何去开发一个springboot starter 我们在平时用 Java 开发的时候#xff0c;在 pom.xml 文件中引入一个依赖就可以很方便的使用了#xff0c;但是你们知道这是如何实现的吗。 现在我们就来解决这一个问题#xff01; 创建 SpringBoot 项目 首先我们要做的就是把你想要给别…如何去开发一个springboot starter 我们在平时用 Java 开发的时候在 pom.xml 文件中引入一个依赖就可以很方便的使用了但是你们知道这是如何实现的吗。 现在我们就来解决这一个问题 创建 SpringBoot 项目 首先我们要做的就是把你想要给别人方便使用的内容自己的写好 我这里直接另外创建了一个 springboot 的 web 项目在这个 web 项目中我用 controller 写了几个简单的接口用于后面的调用然后再创建一个 springboot 项目这个新的 springboot 项目就是用来开发 starter 的方便使用者更好、更方便使用。 现在是具体流程 springboot 的 web 项目创建 用 IDEA 快速创建一个 springboot 项目创建方法如下 选择 spring Initializer自己写一个项目的名称语言选择 Java包管理工具选择 Maven组这个可以自己写 例如我的昵称 xwhking 就可以写 com.xwkhingjdk 选择1.8Java 选择8然后就是下一步 进入下一步后 选择 springboot 的版本我一般选择2.7左右的 然后选择开发工具 Spring Boot DevtoolsSpring COnfiguration Processor 主要用于后面我们在工程中使用的使用在 yml 中写配置时能够自动提示配置Lombok 通过使用 annotation 快速的生成主要的 getter 和 setterSpring Web 加上也没事 然后就是创建了。 创建好了以后就进入写代码环节写一个简单的 web 请求的 Demo 我这里的目录结构如下 UserController的代码如下 package com.xwhking.interface_test.controller;import com.xwhking.interface_test.entity.User; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController;import javax.servlet.http.HttpServletRequest; import java.util.Date;import static com.xwhking.interface_test.utils.GenSign.genSign;RestController RequestMapping(/user) public class UserController {GetMapping(/name)public String getName(RequestParam String name , HttpServletRequest request){System.out.println(请求参数名字为 name);return GET 请求参数名字为 name;}GetMapping(/getOne)public User getUser(HttpServletRequest request){User user new User();user.setId(123l);user.setUsername(xwhking);user.setPassword(admin123);System.out.println(user);return user ;} }User代码 package com.xwhking.interface_test.entity;import lombok.Data;Data public class User {private Long id;private String username;private String password;Overridepublic String toString(){return User { id: id , name: username ,password: password };} }这些完成以后就可以启动这一个项目了。 可以用浏览器试试 starter开发 以同样的方式创建一个springboot项目需要特别注意的就是我们需要把 pom.xml 文件中的 build 部分代码全部去掉。 pom.xml 文件 注意这里引入了 Hutool 工具库用于后面开发并且文件里面是没有 build 模块的这里还需要注意把版本的snapshot去掉 ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.7.10/versionrelativePath/ !-- lookup parent from repository --/parentgroupIdcom.xwhking/groupIdartifactIdInterfaceStarter/artifactIdversion0.0.1/versionnameInterfaceStarter/namedescriptionInterfaceStarter/descriptionpropertiesjava.version8/java.version/propertiesdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-devtools/artifactIdscoperuntime/scopeoptionaltrue/optional/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-configuration-processor/artifactIdoptionaltrue/optional/dependencydependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdoptionaltrue/optional/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependencydependencygroupIdcn.hutool/groupIdartifactIdhutool-all/artifactIdversion5.8.16/version/dependency/dependencies /project 目录结构 client 目录 这里就是真正使用的类对对应的功能进行了封装。config 目录 这里对 client 进行配置并且把 client 包装成一个 Bean 返回utils 工具类这里用来生成签名的工具META-INF.spring.factories 这个非常重要用于别人调用的时候在写配置的之后能够进行提示与自动装配 client 代码 package com.xwhking.interfacestarter.client;import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpUtil; import lombok.Data;import java.time.LocalDateTime; import java.util.Date; import java.util.HashMap;import static com.xwhking.interfacestarter.utils.GenSign.genSign;/*** 发起请求时候一定要注意不要把secretKey直接传送只需要进行一个签名传送就好了然后后端通过同样的方式进行签名* 的生成进行对比验证身份。*/ Data public class XWHKINGClient {private String accessKey;private String secretKey;private Long userId;public XWHKINGClient(String accessKey,String secretKey,Long userId){this.userId userId;this.accessKey accessKey;this.secretKey secretKey;}public String getName(String name){//可以单独传入http参数这样参数会自动做URL编码拼接在URL中HashMapString, Object paramMap new HashMap();paramMap.put(name, name);HashMapString,String headerMap new HashMap();headerMap.put(accessKey,accessKey);headerMap.put(userId,userId.toString());headerMap.put(sign, genSign(accessKey,secretKey,userId));headerMap.put(timestamp,Long.toString(new Date().getTime()));String result1 HttpRequest.get(http://localhost:8080/user/name).addHeaders(headerMap).form(paramMap).execute().body();System.out.println(result1);return result1;}public String GetUser(){HashMapString,String headerMap new HashMap();headerMap.put(accessKey,accessKey);headerMap.put(userId,userId.toString());headerMap.put(sign, genSign(accessKey,secretKey,userId));headerMap.put(timestamp,Long.toString(new Date().getTime()));String result1 HttpRequest.get(http://localhost:8080/user/getOne).addHeaders(headerMap).execute().body();System.out.println(result1);return result1;}public static void main(String[] args) {new XWHKINGClient(xwhking,admin123,123123l).getName(XWHKING);} } 这里都加了请求头加请求头的目的是为了进行签名认证。 为什么要进行签名认证 保证安全性一个人不能随便调用如果随便调用的话自己的服务器资源会收到压迫以及资源的损失。适用于无需保存登录态。只认签名不关注用户登录态。 如何进行签名认证 通过 http request header 头传递参数 这里主要传递的参数 accessKey 调用的标识 需要复杂、 无序、无规律这里我没有实现只是简单的模拟如果需要实现的话可以使用现成的签名实现工具包例如 hutoolsecretKey 调用的密钥需要复杂、 无序、无规律该参数一定一定不能放到请求头中不然可能会被别人抓包以及可能造成泄露。用户请求的参数sign 签名由 accessKey 和 secretKey 以及 userId 等信息生成用于传递信息。然后后端通过同样的方式进行生成对比验证权限。上述问题满足了可能还抵挡不了别人的攻击例如别人用重放就可以再次调用 API 了限制重放的方法 加随机数只能使用一次服务端要保存使用过的随机数加 timestamp 时间戳检验时间戳是否过期我这里就是通过时间戳超过10s就失效。 对web中的UserController进行更新 更新就是为了校验然后如果更新了项目记得重启 package com.xwhking.interface_test.controller;import com.xwhking.interface_test.entity.User; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController;import javax.servlet.http.HttpServletRequest; import java.util.Date;import static com.xwhking.interface_test.utils.GenSign.genSign;RestController RequestMapping(/user) public class UserController {/*** 校验签名以及其他信息注意这里的 secretKey 是模拟的一般用户的 secretKey 是需要去从数据库取出来* 然后进行验证。* param request*/private void verifyRequest(HttpServletRequest request){String sign request.getHeader(sign);String accessKey request.getHeader(accessKey);String secretKey admin123;String userId request.getHeader(userId);String requestTime request.getHeader(timestamp);long oldTime Long.parseLong(requestTime);long newTime new Date().getTime();if(newTime - oldTime 10000){throw new RuntimeException(检测到请求异常);}String newSign genSign(accessKey,secretKey,Long.parseLong(userId));if(!newSign.equals(sign)){throw new RuntimeException(签名错误);}}GetMapping(/name)public String getName(RequestParam String name , HttpServletRequest request){verifyRequest(request);System.out.println(请求参数名字为 name);return GET 请求参数名字为 name;}GetMapping(/getOne)public User getUser(HttpServletRequest request){verifyRequest(request);User user new User();user.setId(123l);user.setUsername(xwhking);user.setPassword(admin123);System.out.println(user);return user ;} } config 代码 要注意其中的注解 package com.xwhking.interfacestarter.config;import com.xwhking.interfacestarter.client.XWHKINGClient; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; Configuration ConfigurationProperties(prefix xwhking.client) Data ComponentScan public class XWHKINGClientConfig {private String accessKey;private String secretKey;private String userId;Beanpublic XWHKINGClient xwhkingClient(){return new XWHKINGClient(accessKey,secretKey,Long.parseLong(userId));} } 生成签名代码 这里直接使用了 Hutool 工具库中的 sh256 的生成方法 package com.xwhking.interfacestarter.utils;import cn.hutool.crypto.SecureUtil; import lombok.Data;Data public class GenSign {public static String genSign(String accessKey,String secretKey,Long userId){String key xwhking . accessKey . secretKey . userId;return SecureUtil.sha256(key);} } META-INF 中文件的内容 通过看内容就可以看出你需要把后面的内容进行替换写入你的地址。 org.springframework.boot.autoconfigure.EnableAutoConfiguration com.xwhking.interfacestarter.XWHKINGClientConfig到这里 Starter 就完了然后使用 maven 进行打包调用install。这里的打包会把包直接放入你的 maven 仓库打包成功就会出现 BUILD SUCCESS 在其他项目中使用 首先复制这段代码 groupIdcom.xwhking/groupId artifactIdInterfaceStarter/artifactId version0.0.1/version然后在你的其他项目中添加进依赖 dependencygroupIdcom.xwhking/groupIdartifactIdInterfaceStarter/artifactIdversion0.0.1/version /dependency刷新 maven 仓库 然后再 yml 配置中加入配置 在 config中的prefix 可以设置前缀也就是可以更改xwhking.client 然后在你的代码中使用 Test 进行测试 SpringBootTest class MainApplicationTests {Resourceprivate XWHKINGClient xwhkingClient;Testvoid testClient(){xwhkingClient.getName(xwhking) ;}}调用结果 出来了 xwhking 结果成功。 这样开发一个starter 就结束了
http://wiki.neutronadmin.com/news/399512/

相关文章:

  • 门户网站的重要性专门做尿不湿的网站
  • html5 手机网站模版产品营销策略怎么写
  • 刷网站排名怎么刷大学学部网站建设工作
  • 石家庄建站平台线上赚钱正规平台
  • 怎么样优化网站seo搜索引擎营销的分类
  • 网站设计建设维护与更新海南新政策最新消息
  • 昆山建设工程招标网站潍坊网站seo外包
  • 手机营销型网站建设公司wordpress浮窗
  • 西安电子商务网站怎样开一个小贸易公司
  • moodle网站建设网站的优化方法
  • 西安市建设干部学校网站如何使用好wordpress
  • 网站打开wordpresswordpress创始人
  • 做跨境电商如何自建站网站新站整站排名
  • 贵州营销型网站建设电影网站如何盈利
  • 可以做文档赚钱的网站fullpage wow做的网站
  • 中国最好的域名注册网站宁波一网信息技术有限公司
  • 免费域名做网站wordpress更新后图片不显示
  • 衡水专业网站建设公司昭通网站制作
  • 怎么做公益网站discuz绿色带门户手机网站模板
  • 域名里可以建网站aso排名优化知识
  • 网站开发多语言机械加工
  • 怎么做自己的导航网站北京h5网站制作
  • 一个公司备案两个网站如何注册自己的平台
  • 个人论坛类网站图片瀑布流网站模板
  • 公司做公司网站广告京山网站建设
  • 做系统的网站好响应式的网站做优化好吗
  • 微网站搭建费用公司推广业务哪个平台好
  • 百度验证网站wordpress 融资
  • 网站管理网站建设开发公司报价
  • 做网站最好的网络公司wordpress电影下载