forever杨的个人博客

I want to be forever young!


  • 首页

  • 文章202

  • 分类31

  • 标签175

  • 公益

  • 关于

  • 搜索

Redis 使用场景

发表于 2018-07-24 | 更新于 2021-04-09 | 分类于 redis
| 字数: 1.3k | 时长 ≈ 1 分钟
标签 redis

场景一:取最新N条数据

网站最新文章、最新评论等。使用 Redis 列表(List)集合,LPUSH 命令向 list 集合头部插入数据,LTRIM 命令对 list 集合进行修剪(trim)

1
2
3
4
5
6
7
8
9
# 将一个或多个值插入到列表头部
# LPUSH key value1 [value2]
127.0.0.1:6379> LPUSH latest.comments "foo"
(integer) 1

# 对一个列表进行修剪(trim),就是说,让列表只保留指定区间内的元素,不在指定区间之内的元素都将被删除
# LTRIM key start stop
127.0.0.1:6379> LTRIM latest.comments 0 10
OK
阅读全文 »

restful api 规范

发表于 2018-07-24 | 分类于 规范
| 字数: 14k | 时长 ≈ 12 分钟
标签 restful api

RESTful API 设计规范

原文地址:https://github.com/godruoyi/restful-api-specification

关于「能愿动词」的使用

为了避免歧义,文档大量使用了「能愿动词」,对应的解释如下:

  • 必须 (MUST):绝对,严格遵循,请照做,无条件遵守;
  • 一定不可 (MUST NOT):禁令,严令禁止;
  • 应该 (SHOULD) :强烈建议这样做,但是不强求;
  • 不该 (SHOULD NOT):强烈不建议这样做,但是不强求;
  • 可以 (MAY) 和 可选 (OPTIONAL) :选择性高一点,在这个文档内,此词语使用较少;

参见:RFC 2119

阅读全文 »

Linux 查看端口是否被占用

发表于 2018-07-19 | 更新于 2020-06-01 | 分类于 Linux
| 字数: 57 | 时长 ≈ 1 分钟
标签 netstat lsof

查询哪个进程在监听端口

1
2
3
netstat -anop | grep 8080
# 或者
lsof -i:8080

spring cache 常用缓存注解介绍

发表于 2018-07-18 | 更新于 2021-04-09 | 分类于 Java
| 字数: 996 | 时长 ≈ 1 分钟
标签 spring cache

spring-cache 常用缓存注解介绍

包地址 注解名 作用域 作用
org.springframework.cache.annotation CacheConfig 类级别 s设置缓存的公共配置
Cacheable 方法级别 缓存读取操作
CacheEvict 方法级别 缓存失效操作
CachePut 方法级别 缓存更新操作
Caching 方法级别 h混合读取、失效、更新操作
阅读全文 »

spring retry 使用

发表于 2018-07-18 | 分类于 Java
| 字数: 2.5k | 时长 ≈ 2 分钟
标签 spring retry

@Retryable

被注解的方法发生异常时会重试

参数 默认值 说明
value 空 指定发生的异常,进行重试
include 空 指定异常重试。和value一样,默认空,当exclude也为空时,所有异常都重试
exclude 空 指定异常不重试。默认空,当include也为空时,所有异常都重试
maxAttemps 3 重试次数
backoff 空 重试补偿机制
阅读全文 »

Netty Epoll 和 Nio

发表于 2018-07-13 | 更新于 2018-08-20 | 分类于 Java
| 字数: 3.5k | 时长 ≈ 3 分钟
标签 Netty

入门

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslContextBuilder;
import io.netty.handler.ssl.util.SelfSignedCertificate;
import io.netty.util.concurrent.DefaultEventExecutorGroup;
import io.netty.util.concurrent.EventExecutorGroup;

/**
* Netty 启动器,初始化 spring boot 的时候会自动加载
*/
public class Server {
private static final Logger LOG = LoggerFactory.getLogger(Server.class);

/*
* NioEventLoopGroup 默认创建数量为 CPU * 2,类型为 NioEventLoop 的实例。
* 每个 NioEventLoop 实例都持有一个线程,以及一个类型为 LinkedBlockingQueue 的任务队列
*/
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
// 业务线程
EventExecutorGroup eventExecutorGroup = new DefaultEventExecutorGroup(16);
static final boolean isSsl = System.getProperty("ssl") != null;

/**
* 初始化 Netty
*/
public void startNetty() {
try {
final SslContext sslCtx;
if (isSsl) {
SelfSignedCertificate ssc = new SelfSignedCertificate();
sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
} else {
sslCtx = null;
}
// 引导辅助程序
ServerBootstrap bs = new ServerBootstrap();
// 通过NIO方式来接收连接和处理连接
bs.group(bossGroup, workerGroup);
// 设置NIO的Channel
bs.channel(NioServerSocketChannel.class);
bs.childHandler(new HttpChannelInitializer(sslCtx, eventExecutorGroup));

bs.option(ChannelOption.SO_BACKLOG, 1024); // 连接数
// bs.childOption(ChannelOption.SO_KEEPALIVE, true); // 是否长链接
bs.childOption(ChannelOption.TCP_NODELAY, true); // 是否TCP延迟

// 配置完成,开始绑定server,通过调用sync同步方法阻塞直到绑定成功
Channel ch = bs.bind(9999).sync().channel();
LOG.info("Server startup. listen on {}-{}", (isSsl ? "https" : "http"), 9999);
// 应用程序会一直等待,直到Channel关闭
ch.closeFuture().sync();
} catch (Exception e) {
LOG.error("server startup failed. {}", e.getMessage(), e);
} finally {
LOG.info("释放资源...");
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
eventExecutorGroup.shutdownGracefully();
bossGroup = null;
workerGroup = null;
eventExecutorGroup = null;
}
}

public static void main(String[] args) {
new Server().startNetty();
}
}
阅读全文 »

spring-boot 事件监听 ApplicationListener

发表于 2018-07-06 | 更新于 2021-04-09 | 分类于 Java
| 字数: 5.4k | 时长 ≈ 5 分钟
标签 spring-boot

介绍

SpringBoot 为 ApplicationContextEvent 提供了四种事件:

  • ApplicationStartedEvent :spring boot 启动开始时执行的事件
  • ApplicationEnvironmentPreparedEvent:spring boot 对应 Enviroment 已经准备完毕,但此时上下文 context 还没有创建
  • ApplicationPreparedEvent:spring boot 上下文 context 创建完成,但此时 spring 中的 bean 是没有完全加载完成的
  • ApplicationFailedEvent:spring boot启动异常时执行事件
阅读全文 »

返回 JSON 格式数据,Long 前端精准度丢失问题

发表于 2018-06-14 | 更新于 2020-11-24 | 分类于 Java
| 字数: 4.3k | 时长 ≈ 4 分钟

spring-boot 2.0.0 以下版本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
// 返回 JSON,Long 前端精准度丢失问题
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
ObjectMapper mapper = new ObjectMapper();
/*
* 序列换成json时,将所有的long变成string
* 因为js中得数字类型不能包含所有的java long值
*/
SimpleModule module = new SimpleModule();
module.addSerializer(Long.class, ToStringSerializer.instance);
module.addSerializer(Long.TYPE, ToStringSerializer.instance);
mapper.registerModule(module);
converter.setObjectMapper(mapper);
converters.add(converter);
}
}
阅读全文 »

vue-cli 2.x 使用

发表于 2018-06-05 | 更新于 2018-12-06 | 分类于 vuejs
| 字数: 538 | 时长 ≈ 1 分钟
标签 vue nodejs vue-cli

安装 vue-cli

1
2
# 全局安装
npm install -g vue-cli

如果安装失败,可以使用npm cache clean清理缓存,然后再重新安装

生成项目

首先需要在命令行中进入到工作区间,然后输入

1
vue init webpack vue-project

全局安装webpack命令npm install -g webpack

vue-project 是自定义的项目名称,命令执行之后,会在当前目录生成一个以该名称命名的项目文件夹

proxyTable 代理设置

前后端分离项目本地测试,可以使用 proxyTable 代理到后台服务器,方便调试

1
2
3
4
5
6
7
8
9
10
proxyTable: {
'/api': {
targer: 'https:localhost:8080/service/api',
secure: false,
changeOrigin: true,
pathRewrite: {
'^/api': '/'
}
}
}

使用时直接/api/接口名就行了

Oracle 分区

发表于 2018-06-05 | 更新于 2021-04-28 | 分类于 Oracle
| 字数: 2.6k | 时长 ≈ 2 分钟
标签 Oracle

自增分区

numtoyminterval 按年、月分区

numtoyminterval(1, ‘year’)、numtoyminterval(1, ‘month’)

numtodsinterval 按天、时、分、秒分区

numtodsinterval(1, ‘day’)、numtodsinterval(1, ‘hour’)、numtodsinterval(1, ‘minute’)、numtodsinterval(1, ‘second’)

例子

1
2
3
4
5
6
7
create table user (id number, create_dt date)
tablespace users
partition by range (create_dt)
interval(numtoyminterval(1, 'month'))
(
partition p1 values less than (to_date('2018-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss'))
);
阅读全文 »

druid 打印 sql 日志

发表于 2018-06-05 | 更新于 2020-11-03 | 分类于 Java
| 字数: 4.8k | 时长 ≈ 4 分钟
标签 spring-boot alibaba druid

依赖包

1
2
3
4
5
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.10</version>
</dependency>
阅读全文 »

spring-boot cxf 集成

发表于 2018-06-02 | 更新于 2018-10-22 | 分类于 Java
| 字数: 779 | 时长 ≈ 1 分钟
标签 cxf spring-boot

坑一

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
@Bean
public AegisDatabinding aegisDatabinding() {
return new AegisDatabinding();
}

/**
* 这个要配置成多例模式
*/
@Bean
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean jaxWsServiceFactoryBean() {
JaxWsServiceFactoryBean sf = new JaxWsServiceFactoryBean();
sf.setWrapped(true);
sf.setDataBinding(aegisDatabinding());
return sf;
}

@Bean
public Endpoint userEndpoint(UserService userService) {
EndpointImpl endpoint = new EndpointImpl(userService);
endpoint.setServiceFactory(jaxWsServiceFactoryBean());
endpoint.publish("/imCheckRelatedWeixinService.ws");
return endpoint;
}

这里 endpoint.publish 要在最后,否则获取到的 serviceFactory、dataBinding 等参数是空的

Hibernate 函数

发表于 2018-05-30 | 更新于 2021-04-09 | 分类于 Java
| 字数: 1.3k | 时长 ≈ 1 分钟
标签 Hibernate

HQL(Hibernate Query Language) 提供了丰富的、灵活的查询特性,提供了类似标准SQL语句的查询方式,同时也提供了面向对象的封装。以下是HQL的一些常用函数,比如时间函数、字符串函数等。

阅读全文 »

Mysql for Mac 使用

发表于 2018-05-25 | 更新于 2020-04-28 | 分类于 Mysql
| 字数: 306 | 时长 ≈ 1 分钟

配置环境变量

1
2
3
4
5
6
7
$ cd ~
# 如果没有 .bash_profile 文件,可以通过 touch 来创建一个
$ touch .bash_profile
# 编辑已经存在的文件,先打开文件
$ open -e .bash_profile
# 使配置生效
$ source .bash_profile

在 .base_profile 中加入如下内容

1
export PATH=$PATH:/usr/local/mysql/bin
阅读全文 »

Tomcat 使用注意事项

发表于 2018-05-08 | 更新于 2021-07-16 | 分类于 Tomcat
| 字数: 1.6k | 时长 ≈ 1 分钟

setenv.sh

在Tomcat的bin目录下添加setenv.sh文件,在启动Tomcat的时候,该脚本会被自动执行。一般在该脚本配置一些环境变量、JVM参数等

1
2
3
4
5
6
7
8
9
10
11
12
# @Author: YL
# @Date: 2017-12-18 12:15:52
# @Last Modified by: YL
# @Last Modified time: 2017-12-18 12:16:03
# 本文件放到 Tomcat 的 bin 目录下

export LANG=en_US.UTF-8
export JAVA_HOME=/usr/java/jdk1.8.0_144
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$CLASSPATH

JAVA_OPT="$JAVA_OPT -Xss256k"
阅读全文 »
1…8910…14
forever杨

forever杨

开心又过一日,唔开心又过一日

202 文章
31 分类
175 标签
GitHub
友情链接
  • Tidy的个人博客
© 2024 forever杨 | 站点总字数: 706k