首页
统计
留言板
直播
更多
壁纸
推荐
Git仓库
Search
1
IntelliJ IDEA激活 - 至2022年10月 (持续更新)
645 阅读
2
GitLab企业版搭建(附生成证书)
626 阅读
3
淘宝 京东秒杀脚本
422 阅读
4
Groovy模板引擎 API 构建动态脚本
324 阅读
5
欢迎使用 Typecho
294 阅读
杂货间
开发
Java
JavaScript
Android
JQuery
MySQL
PHP
Groovy
Git
运维
CentOS
Red Heat
Ubuntu
Debian
运行环境
登录
/
注册
Search
标签搜索
开发
Java
Android
MySQL8
CentOS
CentOS8
Linux
Git
Swing
JavaScript
JQuery
MySQL
临时手机号
IDEA
Steam
YouTube
订阅
激活码
GitLab
nginx
Dotdotmaples
累计撰写
30
篇文章
累计收到
7
条评论
首页
栏目
杂货间
开发
Java
JavaScript
Android
JQuery
MySQL
PHP
Groovy
Git
运维
CentOS
Red Heat
Ubuntu
Debian
运行环境
页面
统计
留言板
直播
壁纸
推荐
Git仓库
搜索到
18
篇与
开发
的结果
Java 工具类
将一个类中的值通过setter和getter传递给另一个类型public static <T> T entityToDto(Object entity, Class<T> dtoType) { T instance; try { instance = dtoType.getDeclaredConstructor().newInstance(); } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException(e); } // 反射entity 获取getter Class<?> entryType = entity.getClass(); Arrays.stream(dtoType.getMethods()).filter( method -> method.getName().startsWith("set") ).forEach(method -> { String methodName = method.getName().replace("set", "get"); try { Object value = entryType.getMethod(methodName).invoke(entity); method.invoke(instance, value); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignore) {} }); return instance; }
2022年05月12日
105 阅读
0 评论
1 点赞
Groovy模板引擎 API 构建动态脚本
Groovy模板引擎 API 构建动态脚本可以利用Groovy提供的模板引擎, 在代码中编写脚本, 来完成一些动态化的需求, 案例如下, 当字符串长度等于4时, 执行打印public class RuleEngine { private static final ConcurrentHashMap<String, Template> SCRIPT_CACHE = new ConcurrentHashMap<>(); private static final SimpleTemplateEngine ENGINE = new SimpleTemplateEngine(); private static final String CONDITION_STR_TEMPLATE = "${%s ? true : false}"; private static final String EXECUTE_STR_TEMPLATE = "${%s}"; public static void main(String[] args) { String request = "data"; String condition = "request.length() == 4"; String execute = "System.out.println(request)"; if (condition(condition, request)) { execute(execute, request); } } public static boolean condition(String condition, String request) { boolean result; String conditionTemplate = String.format(CONDITION_STR_TEMPLATE, condition); Map<String, Object> context = new HashMap<>(); context.put("request", request); try { Template template; if (SCRIPT_CACHE.containsKey(condition)) { template = SCRIPT_CACHE.get(condition); } else { template = ENGINE.createTemplate(conditionTemplate); SCRIPT_CACHE.put(condition, template); } Writer writer = new StringWriter(); template.make(context).writeTo(writer); result = Boolean.parseBoolean(writer.toString()); } catch (Exception e) { throw new RuntimeException("模板解析异常" + conditionTemplate); } return result; } public static void execute(String execute, String request) { String executeTemplate = String.format(EXECUTE_STR_TEMPLATE, execute); Map<String, Object> context = new HashMap<>(); context.put("request", request); Template template; try { if (SCRIPT_CACHE.containsKey(execute)) { template = SCRIPT_CACHE.get(execute); } else { template = ENGINE.createTemplate(executeTemplate); SCRIPT_CACHE.put(execute, template); } template.make(context).writeTo(new StringWriter()); } catch (Exception e) { throw new RuntimeException("模板解析异常" + executeTemplate); } } }Groovy动态对象注册为Spring IOC中的Beangroovy script脚本内容如下, 与Java语法完全兼容package groovy; import com.github.service.GroovyBeanCommand import org.slf4j.Logger import org.slf4j.LoggerFactory import java.lang.invoke.MethodHandles; public class FoobarCommand implements GroovyBeanCommand { private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); @Override String run() { LOGGER.info("foobar command"); return "FoobarCommand Data"; } }约定的脚本所需实现的接口public interface GroovyBeanCommand { String run(); }外部传入script的入口@PostMapping("/command/add") public void addGroovyCommand(@RequestParam String groovyBeanName, @RequestParam String script) { GroovyContextUtils.autowireBean(groovyBeanName, script); } @GetMapping("/command/run") public Object runGroovyCommand(@RequestParam String groovyBeanName) { GroovyBeanCommand command = GroovyContextUtils.getBean(groovyBeanName, GroovyBeanCommand.class); return command.run(); }将script注入到IOC中的工具类@Component public class GroovyContextUtils implements ApplicationContextAware { private static ApplicationContext applicationContext; private static final GroovyClassLoader CLASS_LOADER = new GroovyClassLoader(); @Override public void setApplicationContext(@NonNull ApplicationContext context) { applicationContext = context; } public static void autowireBean(String beanName, String script) { Class<?> clazz = CLASS_LOADER.parseClass(script); BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(clazz); BeanDefinition beanDefinition = beanDefinitionBuilder.getRawBeanDefinition(); beanDefinition.setScope(BeanDefinition.SCOPE_SINGLETON); AutowireCapableBeanFactory autowireCapableBeanFactory = applicationContext.getAutowireCapableBeanFactory(); autowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(beanDefinition, beanName); BeanDefinitionRegistry beanRegistry = (BeanDefinitionRegistry) autowireCapableBeanFactory; if (beanRegistry.containsBeanDefinition(beanName)) { beanRegistry.removeBeanDefinition(beanName); } beanRegistry.registerBeanDefinition(beanName, beanDefinition); } public static <T> T getBean(String beanName, Class<T> clazz) { return applicationContext.getBean(beanName, clazz); } public static <T> T getBean(Class<T> clazz) { return applicationContext.getBean(clazz); } }动态脚本与规则编排自定义一套规则组, 将脚本编号保存, 按照所需要顺序组合起来, 实现规则的编排和可插拔, 并按照流程处理数据流伪代码如下public void process(Data data) { List<Handler> handlers = getHandlers(data.getBizCode()); for(Handler handler : handlers) { handler.run(data); } }
2022年04月07日
324 阅读
0 评论
2 点赞
Git基本操作
假如在dev分支上,刚开发完项目,执行了下列命令:git add . git commit -m '提交的备注信息' git push -u origin dev想将dev分支合并到master分支,操作如下:1、首先切换到master分支上git checkout master如果是多人开发的话 需要把远程master上的代码pull下来git pull origin master //如果是自己一个开发就没有必要了,为了保险期间还是pull3、然后我们把dev分支的代码合并到master上git merge dev4、然后查看状态及执行提交命令git status On branch master Your branch is ahead of 'origin/master' by 12 commits. (use "git push" to publish your local commits) nothing to commit, working tree clean //上面的意思就是你有12个commit,需要push到远程master上 > 最后执行下面提交命令 git push origin master5其他命令更新远程分支列表 git remote update origin --prune 查看所有分支 git branch -a 删除远程分支Chapater6 git push origin --delete Chapater6 删除本地分支 Chapater6 git branch -d Chapater6
2022年04月07日
138 阅读
0 评论
0 点赞
2020-05-28
使用Youtube官方API订阅功能的实现
在开篇之前,请允许我引用并重新组织一位博主的言语:若想实现对一个YouTube频道的订阅功能,目前所知有两种方法。 1. 采用直接而笨重的轮询机制 - 即每隔一段时间去请求频道下的视频接口,根据返回的视频名称判断是否是新视频。这样做的缺点显而易见,一是除非轮询时间间隔特别短,否则基本没法保证时效性。二是频繁的访问查询接口会浪费掉大量的api 配额,因此这不是一种优雅的解决方案。 2. 使用官方的发布订阅系统 - 一种基于Webhooks实现的订阅推送(对于Webhooks机制不清楚的同学可以了解后再去尝试),可以实现几乎实时的更新推送部分内容引用自以下博客,本篇博客也就是对以下文章中第三点(订阅功能实现)的补充说明https://blog.csdn.net/zzz_zjz/article/details/105006921 详细资料参考官方的这篇文档 https://developers.google.com/youtube/v3/guides/push_notifications 其主要流程就是,在下面这个网址中添加订阅频道和回调地址 https://pubsubhubbub.appspot.com/subscribe这样你就会在你的服务器上接收到这样的更新信息<feed xmlns:yt="http://www.youtube.com/xml/schemas/2015" xmlns="http://www.w3.org/2005/Atom"> <link rel="hub" href="https://pubsubhubbub.appspot.com"/> <link rel="self" href="https://www.youtube.com/xml/feeds/videos.xml?channel_id=CHANNEL_ID"/> <title>YouTube video feed</title> <updated>2015-04-01T19:05:24.552394234+00:00</updated> <entry> <id>yt:video:VIDEO_ID</id> <yt:videoId>VIDEO_ID</yt:videoId> <yt:channelId>CHANNEL_ID</yt:channelId> <title>Video title</title> <link rel="alternate" href="http://www.youtube.com/watch?v=VIDEO_ID"/> <author> <name>Channel title</name> <uri>http://www.youtube.com/channel/CHANNEL_ID</uri> </author> <published>2015-03-06T21:40:57+00:00</published> <updated>2015-03-09T19:05:24.552394234+00:00</updated> </entry> </feed>除以上资料外并没有更多像具体怎么实现的信息了,我想看到这像我一样的Java新手来言简直就是一头雾水。 为此我在此贴上我为时两个星期的测试代码(还是因为公司事务较忙,没空去查看日志所致) 以下代码只做测试、研究使用,生产环境勿用import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import java.io.BufferedReader; import java.io.IOException; import java.util.Enumeration; import java.util.Map; /** * @author 枫铃也 * @time 2020-05-14 14:59 * @description YouTube订阅服务接口 https://pubsubhubbub.appspot.com/subscribe */ @RestController @RequestMapping("/system/youtube") @Api(tags = "YouTubePubSubHubbubController") public class YouTubePubSubHubbubController { private static final Logger LOGGER = LoggerFactory.getLogger(YouTubePubSubHubbubController.class); @RequestMapping(value = "subscribe", method = {RequestMethod.GET, RequestMethod.POST}) @ApiOperation(value = "YouTube订阅认证接口", notes = "YouTube订阅认证接口") public String subscribe(HttpServletRequest request, @RequestHeader Map<String, String> headers) { LOGGER.info("----------------打印请求全部消息开始----------------"); Enumeration<String> headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { String name = headerNames.nextElement(); LOGGER.info("{} - {}", name, request.getHeader(name)); } LOGGER.info("----------------打印请求全部消息结束----------------"); LOGGER.info("-----------------打印请求头消息开始-----------------"); headers.forEach((String key, String value) -> LOGGER.info(String.format("Header '%s' = %s", key, value))); LOGGER.info("-----------------打印请求头消息结束-----------------"); Map<String, String[]> parameterMap = request.getParameterMap(); LOGGER.info("------------------打印全部参数开始------------------"); String result = ""; if (parameterMap.isEmpty()) { LOGGER.info("请求参数为空"); }else { parameterMap.forEach((String key, String[] value) -> { for (String s : value) { LOGGER.info("Param '{}' = {}", key, s); } }); result = parameterMap.get("hub.challenge")[0]; } LOGGER.info("------------------打印全部参数结束------------------"); LOGGER.info("-----------------打印Reader数据开始----------------"); StringBuilder buffer = new StringBuilder(); try (BufferedReader reader = request.getReader()){ String line; while ((line = reader.readLine()) != null) { buffer.append(line); } } catch (IOException e) { LOGGER.error(e.getMessage(), e); } LOGGER.info("reader -> {}", buffer); LOGGER.info("-----------------打印Reader数据结束----------------"); return result; } } 请大家忽略以上代码中的日志和API文档生成的辅助类,并附上实践 具体 完装的日志输出09:39:30.330 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - ----------------打印请求全部消息开始---------------- 09:39:30.330 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - host - 这个我不能给你们看,嘿嘿嘿 09:39:30.330 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - link - <https://www.youtube.com/xml/feeds/videos.xml?channel_id=UCXQexglLCaJyTImYLmSO9Ng>; rel=self, <http://pubsubhubbub.appspot.com/>; rel=hub 09:39:30.330 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - content-type - application/atom+xml 09:39:30.330 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - cache-control - no-cache,max-age=0 09:39:30.330 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - pragma - no-cache 09:39:30.330 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - content-length - 943 09:39:30.330 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - connection - keep-alive 09:39:30.330 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - accept - */* 09:39:30.330 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - from - googlebot(at)googlebot.com 09:39:30.330 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - user-agent - FeedFetcher-Google; (+http://www.google.com/feedfetcher.html) 09:39:30.330 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - accept-encoding - gzip,deflate,br 09:39:30.330 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - ----------------打印请求全部消息结束---------------- 09:39:30.330 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - -----------------打印请求头消息开始----------------- 09:39:30.331 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - Header 'host' = 这个我不能给你们看,嘿嘿嘿 09:39:30.331 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - Header 'link' = <https://www.youtube.com/xml/feeds/videos.xml?channel_id=UCXQexglLCaJyTImYLmSO9Ng>; rel=self, <http://pubsubhubbub.appspot.com/>; rel=hub 09:39:30.331 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - Header 'content-type' = application/atom+xml 09:39:30.331 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - Header 'cache-control' = no-cache,max-age=0 09:39:30.331 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - Header 'pragma' = no-cache 09:39:30.331 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - Header 'content-length' = 943 09:39:30.331 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - Header 'connection' = keep-alive 09:39:30.331 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - Header 'accept' = */* 09:39:30.331 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - Header 'from' = googlebot(at)googlebot.com 09:39:30.331 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - Header 'user-agent' = FeedFetcher-Google; (+http://www.google.com/feedfetcher.html) 09:39:30.331 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - Header 'accept-encoding' = gzip,deflate,br 09:39:30.331 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - -----------------打印请求头消息结束----------------- 09:39:30.331 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - ------------------打印全部参数开始------------------ 09:39:30.331 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - 请求参数为空 09:39:30.331 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - ------------------打印全部参数结束------------------ 09:39:30.332 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - -----------------打印Reader数据开始---------------- 09:39:30.332 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - reader -> <?xml version='1.0' encoding='UTF-8'?><feed xmlns:yt="http://www.youtube.com/xml/schemas/2015" xmlns="http://www.w3.org/2005/Atom"><link rel="hub" href="https://pubsubhubbub.appspot.com"/><link rel="self" href="https://www.youtube.com/xml/feeds/videos.xml?channel_id=UCXQexglLCaJyTImYLmSO9Ng"/><title>YouTube video feed</title><updated>2020-05-28T01:39:27.887188153+00:00</updated><entry> <id>yt:video:GRrUhlU34GM</id> <yt:videoId>GRrUhlU34GM</yt:videoId> <yt:channelId>UCXQexglLCaJyTImYLmSO9Ng</yt:channelId> <title>Dota2 - Team Nigma vs. Gambit - Game 3 - ESL One Birmingham 2020 - Group B - EU/CIS</title> <link rel="alternate" href="https://www.youtube.com/watch?v=GRrUhlU34GM"/> <author> <name>ESL Archives</name> <uri>https://www.youtube.com/channel/UCXQexglLCaJyTImYLmSO9Ng</uri> </author> <published>2020-05-28T01:36:33+00:00</published> <updated>2020-05-28T01:39:27.887188153+00:00</updated> </entry></feed> 09:39:30.332 [http-nio-4930-exec-7] INFO o.f.m.i.y.c.s.YouTubePubSubHubbubController - -----------------打印Reader数据结束----------------一行字数太多,若换行显示或不方便查看大家则可以复制到Notpad++或其他编辑器缩放显示 通过以上日志输出可以看出此订阅方式的参数并非是传统的from表单形式。到此,具体的代码实现也就没什么可写的了。
2020年05月28日
271 阅读
4 评论
1 点赞
MySQL8与Java类型对照表
MySQL和Java数据类型之间的可能转换These MySQL Data TypesCan always be converted to these Java typesCHAR, VARCHAR, BLOB, TEXT, ENUM, and SETjava.lang.String, java.io.InputStream, java.io.Reader, java.sql.Blob, java.sql.ClobFLOAT, REAL, DOUBLE PRECISION, NUMERIC, DECIMAL, TINYINT, SMALLINT, MEDIUMINT, INTEGER, BIGINTjava.lang.String, java.lang.Short, java.lang.Integer, java.lang.Long, java.lang.Double, java.math.BigDecimalDATE, TIME, DATETIME, TIMESTAMPjava.lang.String, java.sql.Date, java.sql.TimestampResultSet.getObject()方法使用MySQL和Java类型之间的类型转换,并在适当时遵循JDBC规范。ResultSetMetaData.GetColumnTypeName()和 返回的值 ResultSetMetaData.GetColumnClassName() 如下表所示.有关JDBC类型的更多信息,请参见 java.sql.Types类上的参考 。ResultSetMetaData.GetColumnTypeName() 和 ResultSetMetaData.GetColumnClassName() 的MySQL类型和返回值MySQL Type NameReturn value of GetColumnTypeNameReturn value of GetColumnClassNameBIT(1)BITjava.lang.BooleanBIT( > 1)BITbyte[]TINYINTTINYINTjava.lang.Boolean if the configuration property tinyInt1isBit is set to true (the default) and the storage size is 1, or java.lang.Integer if not.BOOL, BOOLEANTINYINTSee TINYINT, above as these are aliases for TINYINT(1), currently.SMALLINT[(M)] [UNSIGNED]SMALLINT [UNSIGNED]java.lang.Integer (regardless of whether it is UNSIGNED or not)MEDIUMINT[(M)] [UNSIGNED]MEDIUMINT [UNSIGNED]java.lang.Integer (regardless of whether it is UNSIGNED or not)INT,INTEGER[(M)] [UNSIGNED]INTEGER [UNSIGNED]java.lang.Integer, if UNSIGNED java.lang.LongBIGINT[(M)] [UNSIGNED]BIGINT [UNSIGNED]java.lang.Long, if UNSIGNED java.math.BigIntegerFLOAT[(M,D)]FLOATjava.lang.FloatDOUBLE[(M,B)]DOUBLEjava.lang.DoubleDECIMAL[(M[,D])]DECIMALjava.math.BigDecimalDATEDATEjava.sql.DateDATETIMEDATETIMEjava.sql.TimestampTIMESTAMP[(M)]TIMESTAMPjava.sql.TimestampTIMETIMEjava.sql.Time`YEAR[(24)]`YEARIf yearIsDateType configuration property is set to false, then the returned object type is java.sql.Short. If set to true (the default), then the returned object is of type java.sql.Date with the date set to January 1st, at midnight.CHAR(M)CHARjava.lang.String (unless the character set for the column is BINARY, then byte[] is returned.VARCHAR(M) [BINARY]VARCHARjava.lang.String (unless the character set for the column is BINARY, then byte[] is returned.BINARY(M)BINARYbyte[]VARBINARY(M)VARBINARYbyte[]TINYBLOBTINYBLOBbyte[]TINYTEXTVARCHARjava.lang.StringBLOBBLOBbyte[]TEXTVARCHARjava.lang.StringMEDIUMBLOBMEDIUMBLOBbyte[]MEDIUMTEXTVARCHARjava.lang.StringLONGBLOBLONGBLOBbyte[]LONGTEXTVARCHARjava.lang.StringENUM('value1','value2',...)CHARjava.lang.StringSET('value1','value2',...)CHARjava.lang.Stringjava.sql.TypesModifier and TypeField and Descriptionstatic intARRAYThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type ARRAY.static intBIGINTThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type BIGINT.static intBINARYThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type BINARY.static intBITThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type BIT.static intBLOBThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type BLOB.static intBOOLEANThe constant in the Java programming language, somtimes referred to as a type code, that identifies the generic SQL type BOOLEAN.static intCHARThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type CHAR.static intCLOBThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type CLOB.static intDATALINKThe constant in the Java programming language, somtimes referred to as a type code, that identifies the generic SQL type DATALINK.static intDATEThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type DATE.static intDECIMALThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type DECIMAL.static intDISTINCTThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type DISTINCT.static intDOUBLEThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type DOUBLE.static intFLOATThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type FLOAT.static intINTEGERThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type INTEGER.static intJAVA_OBJECTThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type JAVA_OBJECT.static intLONGNVARCHARThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type LONGNVARCHAR.static intLONGVARBINARYThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type LONGVARBINARY.static intLONGVARCHARThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type LONGVARCHAR.static intNCHARThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type NCHARstatic intNCLOBThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type NCLOB.static intNULLThe constant in the Java programming language that identifies the generic SQL value NULL.static intNUMERICThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type NUMERIC.static intNVARCHARThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type NVARCHAR.static intOTHERThe constant in the Java programming language that indicates that the SQL type is database-specific and gets mapped to a Java object that can be accessed via the methods getObject and setObject.static intREALThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type REAL.static intREFThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type REF.static intREF_CURSORThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type REF CURSOR.static intROWIDThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type ROWIDstatic intSMALLINTThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type SMALLINT.static intSQLXMLThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type XML.static intSTRUCTThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type STRUCT.static intTIMEThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type TIME.static intTIME_WITH_TIMEZONEThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type TIME WITH TIMEZONE.static intTIMESTAMPThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type TIMESTAMP.static intTIMESTAMP_WITH_TIMEZONEThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type TIMESTAMP WITH TIMEZONE.static intTINYINTThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type TINYINT.static intVARBINARYThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type VARBINARY.static intVARCHARThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type VARCHAR.
2020年04月16日
138 阅读
0 评论
0 点赞
2020-04-07
Steam第三方登陆
来源申明:https://weibo.com/p/1001603922680121320645生成跳转到Steam登录页面的源码开始//Steam使用openid登录的网址 final static String STEAM_LOGIN = "https://steamcommunity.com/openid/login"; public static String getUrl(String returnTo) throws UnsupportedEncodingException { Map<String, String> params = new HashMap<String, String>(); params = new HashMap<String, String>(); params.put("openid.ns", "//specs.openid.net/auth/2.0"); params.put("openid.mode", "checkid_setup"); //登陆成功后要返回url,值得一说的是这个url是可以携带参数的 params.put("openid.return_to", returnTo); //realm的中文解释是领域与范围,我想大概就是你网站域名,授权用户登录你域名下的应用,我这里默认就用传过来的returnTo了 params.put("openid.realm", returnTo); params.put("openid.identity", "//specs.openid.net/auth/2.0/identifier_select"); params.put("openid.claimed_id", "//specs.openid.net/auth/2.0/identifier_select"); return STEAM_LOGIN + "?" + SteamLoginUtil.getUrlParamsByMap(params); } /** * 将url中传递参数转化为map 其中值进行encode * * @param param * aa=11&bb=22&cc=33 * @return * @throws UnsupportedEncodingException */ public static Map<String, String> getUrlParams(String param) throws UnsupportedEncodingException { Map<String, String> map = new HashMap<String, String>(0); if (StringUtils.isBlank(param)) { return map; } String[] params = param.split("&"); for (int i = 0; i < params.length; i++) { String[] p = params[ i ].split("="); if (p.length == 2) { map.put(p[0], URLDecoder.decode(p[ 1 ],"UTF-8")); } } return map; }生成跳转到Steam登录页面的源码结束OK,用上述的代码,传入一个returnTo的参数,就生成一串URL。浏览器打开这个URL就能看见类似如下的画面 表明Steam可以授权给你登录,只要用户登录成功,steam就会跳转到你设置的returnTo地址,并且携带一大波参数。 虽然返回给你了这些参数,用户还不能立即得到登录授权,为什么呢(如果我现在直接给你授权,我返回给你的参数都是明文的,那岂不是任何一个人都能伪造出这么一串参数来登录你的系统,你咋能放心呢)。其实这个时候openid的机制已经记住了这个用户要登录你的系统,但是你的系统还要确认一下,跟openID说这个用户确实是从我这里发出来的登录请求,我请求你允许他登录我的系统。 怎样“请求你~允许他~登录我的系统”呢? 这里用了HttpClient去请求openid的提供者。这个过程用户是看不到的,透明的。 就相当于你的网站和openid提供者说了句悄悄话。说的就是“请求你~允许他~登录我的系统”。而openid的提供者一查,这用户刚才亮出了身份,确实跟我过说要登录你的系统,OK给你俩授权。你俩自己聊去吧! 过程是这样,代码在这里。HttpClient授权验证代码/** * 将steam返回的request参数再次提交steam进行授权,检查是否成功登录,返回steamid算成功,返回空字符串为不成功 * * @param request * @return boolean * @throws ClientProtocolException * @throws IOException */ public static String validate(Map<String,String> request) throws ClientProtocolException, IOException{ //openid.signed这里面的参数用是“,”号隔开的,是提示你返回了哪些参数 Object signed = request.get("openid.signed"); //如果没有openid.signed,那肯定这个请求是不正确的直接跳出即可 if(signed ==null || "".equals(signed)){ return ""; } //此处开始构造HttpClient对象,配置参数,设置访问方法,获取返回值等,进行一次完整访问 HttpClient httpclient = HttpClients.createDefault(); HttpPost httppost = new HttpPost(STEAM_LOGIN+"?"+SteamLoginUtil.getUrlParamsByMap(request)); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); String[] signeds = signed.toString().split(","); for(int i=0;i<signeds.length;i++){ String val = request.get("openid."+signeds[ i ]); nvps.add(new BasicNameValuePair("openid."+signeds[ i ], val==null?"":val)); } nvps.add(new BasicNameValuePair("openid.mode", "check_authentication")); httppost.setEntity(new UrlEncodedFormEntity(nvps)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); if (entity == null) { return ""; } InputStream instreams = entity.getContent(); String result = SteamLoginUtil.convertStreamToString(instreams); //System.out.println("Do something"); System.out.println(result); // Do not need the rest httppost.abort(); //此处是为了将steamid截取出来 String steamid = ""; steamid = request.get("openid.claimed_id"); steamid = steamid.replace("//steamcommunity.com/openid/id/",""); //虽然steamid能从上一次请求参数中截取出来,我们还是要判断HttpClient返回来的消息是否授权了,判断方式是看字符串中是否含有“is_valid:true”,有就是授权成功了,如果没有,就是“is_valid:false”。 if(!result.contains("is_valid:true")){ return ""; } return steamid; } /** * 将输入流读取为一串字符串 * @param is * @return */ public static String convertStreamToString(InputStream is) { BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line = null; try { while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } } catch (IOException e) { e.printStackTrace(); } finally { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } return sb.toString(); }HttpClient授权验证代码结束验证成功消息如下图源码总结如下import java.util.HashMap; import java.util.Iterator; import java.util.Map.Entry; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; public class StringUtils { public static String parseWhereString (HashMap<String, Object> params,String alias){ StringBuffer buffer = new StringBuffer(); if(params == null || params.isEmpty()){ return ""; }else{ buffer.append(" where "); Set<Entry<String, Object>> set = params.entrySet(); Iterator<Entry<String, Object>> iterator = set.iterator(); Entry<String, Object> entry = null; while(iterator.hasNext()){ buffer.append(" and "); entry = iterator.next(); buffer.append(alias); if (!alias.equals("")) { buffer.append("."); } buffer.append(entry.getKey()); buffer.append("="); buffer.append(" ? "); entry = null; } iterator = null; String temp = buffer.toString(); int location = temp.indexOf("and"); buffer = new StringBuffer(); buffer.append(temp.substring(0, location)); buffer.append(temp.substring(location+4)); temp = null; return buffer.toString(); } } /** * 去掉开头结尾制定字符串 * @param stream * @param trimstr * @return */ public static String sideTrim(String stream, String trimstr) { // null或者空字符串的时候不处理 if (stream == null || stream.length() == 0 || trimstr == null || trimstr.length() == 0) { return stream; } // 结束位置 int epos = 0; // 正规表达式 String regpattern = "[" + trimstr + "]*+"; Pattern pattern = Pattern.compile(regpattern, Pattern.CASE_INSENSITIVE); // 去掉结尾的指定字符 StringBuffer buffer = new StringBuffer(stream).reverse(); Matcher matcher = pattern.matcher(buffer); if (matcher.lookingAt()) { epos = matcher.end(); stream = new StringBuffer(buffer.substring(epos)).reverse().toString(); } // 去掉开头的指定字符 matcher = pattern.matcher(stream); if (matcher.lookingAt()) { epos = matcher.end(); stream = stream.substring(epos); } // 返回处理后的字符串 return stream; } /** * <p>Checks if a String is whitespace, empty ("") or null.</p> * * <pre> * StringUtils.isBlank(null) = true * StringUtils.isBlank("") = true * StringUtils.isBlank(" ") = true * StringUtils.isBlank("bob") = false * StringUtils.isBlank(" bob ") = false * </pre> * * @param str the String to check, may be null * @return <code>true</code> if the String is null, empty or whitespace * @since 2.0 */ public static boolean isBlank(String str) { int strLen; if (str == null || (strLen = str.length()) == 0) { return true; } for (int i = 0; i < strLen; i++) { if ((Character.isWhitespace(str.charAt(i)) == false)) { return false; } } return true; } /** * <p>Gets the substring before the last occurrence of a separator. * The separator is not returned.</p> * * <p>A <code>null</code> string input will return <code>null</code>. * An empty ("") string input will return the empty string. * An empty or <code>null</code> separator will return the input string.</p> * * <pre> * StringUtils.substringBeforeLast(null, *) = null * StringUtils.substringBeforeLast("", *) = "" * StringUtils.substringBeforeLast("abcba", "b") = "abc" * StringUtils.substringBeforeLast("abc", "c") = "ab" * StringUtils.substringBeforeLast("a", "a") = "" * StringUtils.substringBeforeLast("a", "z") = "a" * StringUtils.substringBeforeLast("a", null) = "a" * StringUtils.substringBeforeLast("a", "") = "a" * </pre> * * @param str the String to get a substring from, may be null * @param separator the String to search for, may be null * @return the substring before the last occurrence of the separator, * <code>null</code> if null String input * @since 2.0 */ public static String substringBeforeLast(String str, String separator) { if (isEmpty(str) || isEmpty(separator)) { return str; } int pos = str.lastIndexOf(separator); if (pos == -1) { return str; } return str.substring(0, pos); } // Empty checks //----------------------------------------------------------------------- /** * <p>Checks if a String is empty ("") or null.</p> * * <pre> * StringUtils.isEmpty(null) = true * StringUtils.isEmpty("") = true * StringUtils.isEmpty(" ") = false * StringUtils.isEmpty("bob") = false * StringUtils.isEmpty(" bob ") = false * </pre> * * <p>NOTE: This method changed in Lang version 2.0. * It no longer trims the String. * That functionality is available in isBlank().</p> * * @param str the String to check, may be null * @return <code>true</code> if the String is empty or null */ public static boolean isEmpty(String str) { return str == null || str.length() == 0; } }import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.net.URLEncoder; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.message.BasicNameValuePair; public class SteamLoginUtil { final static String STEAM_LOGIN = "https://steamcommunity.com/openid/login"; /** * 接入steam登录url * * @param returnTo * @param request * @return * @throws UnsupportedEncodingException */ public static String getUrl(String returnTo) throws UnsupportedEncodingException { Map<String, String> params = new HashMap<String, String>(); params = new HashMap<String, String>(); // String loginTicket = request.getAttribute("loginTicket")==null ? "" : // "?lt="+ request.getAttribute("loginTicket").toString(); // params.put("lt", request.getAttribute("loginTicket")==null // ?"":request.getAttribute("loginTicket").toString()); params.put("openid.ns", "http://specs.openid.net/auth/2.0"); params.put("openid.mode", "checkid_setup"); params.put("openid.return_to", returnTo); params.put("openid.realm", returnTo); params.put("openid.identity", "http://specs.openid.net/auth/2.0/identifier_select"); params.put("openid.claimed_id", "http://specs.openid.net/auth/2.0/identifier_select"); return STEAM_LOGIN + "?" + SteamLoginUtil.getUrlParamsByMap(params); } /** * 将数据提交steam进行验证,是否成功登录 * * @param request * @return boolean * @throws ClientProtocolException * @throws IOException */ public static String validate(Map<String, String> request){ RequestConfig defaultRequestConfig = RequestConfig.custom() .setSocketTimeout(5000) .setConnectTimeout(5000) .setConnectionRequestTimeout(5000) .build(); CloseableHttpClient httpclient = null; HttpPost httppost = null; try { Object signed = request.get("openid.signed"); if (signed == null || "".equals(signed)) { return ""; } httpclient = HttpClients.createDefault(); httppost = new HttpPost(STEAM_LOGIN + "?" + SteamLoginUtil.getUrlParamsByMap(request)); httppost.setConfig(defaultRequestConfig); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); String[] signeds = signed.toString().split(","); for (int i = 0; i < signeds.length; i++) { String val = request.get("openid." + signeds[i]); nvps.add(new BasicNameValuePair("openid." + signeds[i], val == null ? "" : val)); } nvps.add(new BasicNameValuePair("openid.mode", "check_authentication")); httppost.setEntity(new UrlEncodedFormEntity(nvps)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); if (entity == null) { return ""; } InputStream instreams = entity.getContent(); String result = SteamLoginUtil.convertStreamToString(instreams); // Do not need the rest httppost.abort(); String steamid = ""; steamid = request.get("openid.claimed_id"); steamid = steamid.replace("https://steamcommunity.com/openid/id/", ""); if (!result.contains("is_valid:true")) { return ""; } return steamid; } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }finally{ if(httppost != null){ httppost.releaseConnection(); } if(httpclient != null){ try { httpclient.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return ""; } /** * 将url中传递参数转化为map 其中值进行encode * * @param param * aa=11&bb=22&cc=33 * @return * @throws UnsupportedEncodingException */ public static Map<String, String> getUrlParams(String param) throws UnsupportedEncodingException { Map<String, String> map = new HashMap<String, String>(0); if (StringUtils.isBlank(param)) { return map; } String[] params = param.split("&"); for (int i = 0; i < params.length; i++) { String[] p = params[i].split("="); if (p.length == 2) { map.put(p[0], URLDecoder.decode(p[1], "UTF-8")); } } return map; } /** * 将map转化为url可携带的参数字符串 * * @param map * @return * @throws UnsupportedEncodingException */ public static String getUrlParamsByMap(Map<String, String> map) throws UnsupportedEncodingException { if (map == null) { return ""; } StringBuffer sb = new StringBuffer(); for (Map.Entry<String, String> entry : map.entrySet()) { // 解码 sb.append(entry.getKey() + "=" + URLEncoder.encode(entry == null ? "" : entry.getValue(), "UTF-8")); sb.append("&"); } String s = sb.toString(); if (s.endsWith("&")) { s = StringUtils.substringBeforeLast(s, "&"); } return s; } public static String convertStreamToString(InputStream is) { BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line = null; try { while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } } catch (IOException e) { e.printStackTrace(); } finally { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } return sb.toString(); } }
2020年04月07日
209 阅读
0 评论
0 点赞
CentOS8在线安装MySQL8
清理环境1.检查是否安装了MySQLrpm -qa | grep mysql ## 卸载已经安装的MySQL yum remove mysql-xxx-xxx ## 检查并删除MySQL的配置文件 find / -name mysql rm -rf xxxxxxxxxx2. 删除MariaDB的文件rpm -pa | grep mariadb ## 可能出现 mariadb-libs-5.5.56-2.el7.x86_64 yum -y remove mariadb-libs.x86_64安装MySQL1.下载 MySQL源前往官方网站复制yum源链接,CentOS8是属于Red Hat再编译版本,所以选择Red Hat Enterprise Linux 8 / Oracle Linux 8 (Architecture Independent), RPM Package 点击Download按钮进入如下界面## 鼠标放在这个 No thanks, just start my download.上 鼠标右键 --> 复制链接地址(wget + 复制的链接地址进行下载) wget https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm ## 安装MySQL源 rpm -ivh mysql80-community-release-el8-1.noarch.rpm ## 卸载使用 rpm -Uvh mysql80-community-release-el8-1.noarch2.安装yum -y install mysql-server ## 注意:这里的MySQL8不是mysql-community-server ## 启动MySQL systemctl start mysqld ## 重启MySQL systemctl restart mysqld ## 停止MySQL systemctl stop mysqld 默认配置文件路径: 配置文件:/etc/my.cnf 日志文件:/var/log/var/log/mysqld.log 服务启动脚本:/usr/lib/systemd/system/mysqld.service socket文件:/var/run/mysqld/mysqld.pid登陆并配置MySQL1.登陆mysql -u root ## 第一次登陆没有密码,如果需要密码可以使用下面的命令查询初始密码 cat /var/log/mysqld.log | grep password2.配置-- 设置Root密码 alter user 'root'@'localhost' identified by 'mysql123456'; -- 切换到MySQL库 use mysql; -- 设置登陆权限 update user set Host = '%' where User = 'root'; -- 要想设置简单密码要先修改安全等级 MySQL8的修改命令如下 -- 用于控制validate_password的验证策略 0 --> low 1 --> MEDIUM 2 --> strong set global validate_password.policy = 0; -- 密码长度的最小值 set global validate_password.length = 1; -- 大小写的最小个数 set global validate_password.mixed_case_count = 2; -- 总之8的密码策略就是将validate_password后的‘_’变成‘.’
2019年11月07日
46 阅读
0 评论
0 点赞
计算Map初始容量算法
在实际开发中经常需要使用到Map,但给Map一个怎样的初始容量比较合理?众所周知是最接近(要大于)数据长度的2的N次方那么,如何计算?欢迎指出错误/** * 计算Map初始容量 * @author 枫铃也 * @since 2019-10-09 15:51 */ public class CapacityUtil { private static final double MODULE = 2; public static int getCapacityFactor(int size) { int n = size; int power = 0; while (n > 1) { power++; n >>>= 1; } int capacity = (int) Math.pow(MODULE, power); if (capacity < size || capacity % MODULE != 0) { capacity *= MODULE; } return capacity; } }欢迎指出错误
2019年10月11日
116 阅读
0 评论
1 点赞
1
2
3