临时笔记
2019-01-01 00:00:00
### Java
nginx 真实 ip 问题
tomcat 通过 nginx 做反向代理后,获取客户端 ip 时拿到的是 nginx 的 ip,并非真实客户 ip
解决方案:
在 nginx 配置文件中添加下面的一条配置,将真实 ip 加入请求头中
`proxy_set_header X-Forwarded-For $remote_addr;`
再通过 java 代码取出对应的请求头,即可拿到真实 ip
```
public String getIp() {
String requestHeader = "X-Forwarded-For";
// 优先从响应头中取出真实 IP 地址
String ipFromProxy = request.getHeader(requestHeader);
if (StringUtils.isNotNull(ipFromProxy) && !"unknown".equalsIgnoreCase(ipFromProxy)) {
String[] ipArr = ipFromProxy.split(",");
return ipArr[0].trim();
}
String remoteAddr = request.getRemoteAddr();
return remoteAddr;
}
```
Nginx 代理 WebSockets
通过增加 Upgrade 和 Connection 头信息,来支持代理 WebSocket
```
location /websocket/ {
proxy_pass http://websocket;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
```
### SQL
部分内容已迁移
SELECT INTO 和 INSERT INTO SELECT 两种表复制语句
### Oracle 查询被锁定表
```
SELECT
O.OBJECT_NAME,
S.MACHINE,
S.TERMINAL,
S.USERNAME,
S.OSUSER,
S.PROGRAM,
S.SID,
S.SERIAL#
FROM
GV$LOCKED_OBJECT L,
DBA_OBJECTS O,
GV$SESSION S
WHERE
L.OBJECT_ID = O.OBJECT_ID
AND L.SESSION_ID = S.SID;
```
```
-- 杀掉会话
ALTER SYSTEM KILL SESSION 'SID,SERIAL#';
```
### Oracle 其他待学习函数
`OVER()`
```
WITH TEMP AS (
SELECT '01' AS A, '11' AS B, '111' AS C FROM DUAL UNION ALL
SELECT '01' AS A, '12' AS B, '121' AS C FROM DUAL UNION ALL
SELECT '01' AS A, '12' AS B, '122' AS C FROM DUAL UNION ALL
SELECT '02' AS A, '21' AS B, '211' AS C FROM DUAL UNION ALL
SELECT '02' AS A, '22' AS B, '221' AS C FROM DUAL UNION ALL
SELECT '03' AS A, '31' AS B, '311' AS C FROM DUAL
) SELECT * FROM (SELECT A, B, C, MAX(B) OVER (PARTITION BY A ) AS MAXS FROM TEMP) WHERE B = MAXS;
```
`ROW_NUMBER()`
```
SELECT T1.* FROM (
SELECT ROW_NUMBER() OVER(PARTITION BY LYDH ORDER BY RKSJ DESC) RN, SUM(T.SSCS) OVER(PARTITION BY LYDH) SUM, T.LYDH, T.RKSJ, T.RKR FROM T_ERP_SHZTMX T
) T1 WHERE T1.RN = 1;
```
```
SELECT TRUNC(SYSDATE,'dd') FROM DUAL; --2013-01-06 返回当前年月日
```
```
SELECT TO_CHAR('0.8', 'FM99990.00') FROM DUAL;
```
```
-- 创建表同时创建散列分区
CREATE TABLE T_ERP_SMXSLSJLB_TEST
PARTITION BY HASH (KHMC)
PARTITIONS 10
AS SELECT * FROM T_ERP_SMXSLSJLB_BAK WHERE ROWNUM < 100;
-- 散列分区分布
SELECT DBMS_ROWID.ROWID_OBJECT(ROWID) OBJ_ID, COUNT(*) FROM T_ERP_SMXSLSJLB_TEST GROUP BY DBMS_ROWID.ROWID_OBJECT(ROWID);
-- 创建局部索引
CREATE INDEX T_ERP_SMXSLSJLB_TEST_INDEX ON T_ERP_SMXSLSJLB_TEST(KHMC) LOCAL;
-- 删除表
DROP TABLE T_ERP_SMXSLSJLB_TEST;
-- 查询用户表分区
SELECT * FROM USER_TAB_PARTITIONS;
-- 查询用户回收站
SELECT * FROM USER_RECYCLEBIN;
SELECT COUNT(*) FROM USER_RECYCLEBIN;
-- 根据表名恢复表结构
FLASHBACK TABLE T_ERP_SMXSLSJLB_TEST TO BEFORE DROP;
FLASHBACK TABLE "BIN$cd3tXq/iGjngUzgKqMDBqA==$0" TO BEFORE DROP;
-- 清空回收站指定数据
PURGE TABLE "BIN$ceEiEsddHK3gUzgKqMACNA==$0";
```
### SpringBoot
SpringBoot 主动发现
添加 `resources/META-INF/spring.factories` 文件
SpringBoot 配置提示功能
`META-INF/spring-configuration-metadata.json` (自动生成)或
`META-INF/additional-spring-configuration-metadata.json`(手动添加)
相关依赖:
``` xml
org.springframework.boot
spring-boot-configuration-processor
true
```
### 其他技术
分布式事务
多线程
jvm 调优
tomcat 调优
java 爬虫:phantomjs
[阿里 Maven](http://maven.aliyun.com/)
[Echarts](http://echarts.baidu.com/)
[使用Oracle函数索引 提高查询效率](http://database.51cto.com/art/201010/231096.htm)
[阿里面试回来,想和Java程序员谈一谈](https://zhuanlan.zhihu.com/p/26089746)
[多少k的java web程序员应该懂多线程和jvm优化](https://www.zhihu.com/question/59725713/answer/168709945?utm_medium=social&utm_source=qq)
[GitHub 上有哪些优秀的 Java 爬虫项目?](https://www.zhihu.com/question/31427895)
[Java工程师成神之路](http://www.hollischuang.com/archives/489)
[成神之路系列文章](http://www.hollischuang.com/archives/1001)
[互联网 Java 工程师进阶知识完全扫盲](https://github.com/doocs/advanced-java)
[24小时邮箱](http://24mail.chacuo.net/)
[在线发短信](http://www.afreesms.com/freesms/)
[在线收短信](https://www.receive-sms-online.info/)
[在线PS](https://pixlr.com/editor/?loc=zh-cn)
[高精度IP定位_1](https://www.opengps.cn/Data/IP/LocHighAcc.aspx)
[高精度IP定位_2](http://www.chaipip.com)
[高精度IP定位_3](https://www.chaidu.com/App/Web/IP)
[Ubuntu Pastebin 代码片段分享](http://paste.ubuntu.com/)
[图片合成(QQ用)](https://bupt-hjm.github.io/fun-photo-combine/)
[snipaste 截图工具](https://www.snipaste.com)
[在线看PDM文件](http://www.dmanywhere.cn/)
[Scratch](https://beta.scratch.mit.edu/)
[Free Dynamic DNS - dynv6](https://dynv6.com/)
腾讯云开发者平台
https://dev.tencent.com/
https://studio.dev.tencent.com/
高精度IP定位提供商:
[RTBAsia](http://www.rtbasia.com)
[埃文科技](http://www.ipplus360.com)
淘宝UED的前端智勇大闯关
http://ued.taobao.org/quiz/
http://ued.taobao.org/quiz2/
http://ued.taobao.org/quiz3/
免注册网盘
https://letsupload.co/
https://secufiles.com/
https://mirrorace.com/
windows中的符号链接用法:`mklink /d ...`
java 反射捕获的异常类型为 `InvocationTargetException`
**Todo**
```
select trunc(sysdate, 'month') from dual;
```
**springboot 设置默认时区**
```
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import java.util.TimeZone;
@Component
public class CommandRunnerImpl implements CommandLineRunner {
@Override
public void run(String... args) {
// 设置默认时区
TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
}
}
```
**springboot 设置Date参数转换(非 json 传参)**
```
import cn.hutool.core.date.DateUtil;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.Date;
/**
* WebMvc 配置类
*
* @author Null
* @date 2020-11-24
*/
@Configuration
@ConditionalOnClass(WebMvcConfigurer.class)
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addFormatters(FormatterRegistry registry) {
registry.addConverter(new Converter() {
@Override
public Date convert(String source) {
try {
return DateUtil.parse(source);
} catch (Exception e) {
throw new RuntimeException(String.format("Parser %s to Date fail", source));
}
}
});
}
}
```
**springboot Get 请求支持特殊字符传参**
```
import org.apache.catalina.connector.Connector;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.context.annotation.Bean;
/**
* 修改 sringboot 内嵌 tomcat 配置
*
* @author Null
* @date 2019-08-13
*/
@SpringBootConfiguration
@ConditionalOnClass(Connector.class)
public class TomcatConfig {
@Bean
public TomcatServletWebServerFactory tomcatServletWebServerFactory() {
TomcatServletWebServerFactory tomcatServlet = new TomcatServletWebServerFactory();
// 配置 get 请求 Query 参数支持特殊字符 []{}
tomcatServlet.addConnectorCustomizers(connector -> connector.setProperty("relaxedQueryChars", "[]{}"));
return tomcatServlet;
}
}
```
**springboot 开启 websocket 支持**
```
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
/**
* WebSocket 配置类
*
* @author Null
* @date 2020-11-13
*/
@SpringBootConfiguration
@ConditionalOnClass(ServerEndpointExporter.class)
public class WebSocketConfig {
@Bean
public ServerEndpointExporter serverEndpointExporter() {
return new ServerEndpointExporter();
}
}
```
**springboot log 日志输出时间格式化 指定时区**
```
logging:
pattern:
dateformat: yyyy-MM-dd HH:mm:ss,GMT+8
```
**SpringBoot应用监控Actuator使用的安全隐患**
https://xz.aliyun.com/t/2233
**Linux scp 命令用于 Linux 之间复制文件和目录**
scp 是 secure copy 的缩写, scp 是 linux 系统下基于 ssh 登陆进行安全的远程文件拷贝命令。
```
# 一般用法
scp test.log user@fiebug.com:/home/
scp user@fiebug.com:/home/test.log test.log
# 指定端口用法
scp -P 5000 test.log user@fiebug.com:/home/
```
分类:未分类 关键词:临时
评论(0) 浏览(2500)