8月19
最近公司的项目,配置nginx反向代理时遇到一个问题,当设置nginx监听80端口时转发请求没有问题。但一旦设置为监听其他端口,就一直跳转不正常;如访问欢迎页面时应该是重定向到登录页面,在这个重定向的过程中端口丢失了变默认变成80了,当然就访问不到了。
这里给出一个简短的解决方案,修改nginx的配置文件。
一、配置文件
server {
listen 42112;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host:$server_port; #这里是重点,这样配置才不会丢失端口
location / {
proxy_pass http://127.0.0.1:9001;
}
location = /50x.html {
root html;
}
}
二、产生原因
nginx没有正确的把端口信息传送到后端,没能正确的配置nginx,下面这行是关键
proxy_set_header Host $host:$server_port; 这一行是关键。
或者
proxy_set_header Host $http_host;
这里给出一个简短的解决方案,修改nginx的配置文件。
一、配置文件
server {
listen 42112;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host:$server_port; #这里是重点,这样配置才不会丢失端口
location / {
proxy_pass http://127.0.0.1:9001;
}
location = /50x.html {
root html;
}
}
二、产生原因
nginx没有正确的把端口信息传送到后端,没能正确的配置nginx,下面这行是关键
proxy_set_header Host $host:$server_port; 这一行是关键。
或者
proxy_set_header Host $http_host;
8月12
在使用idea的过程中,遇到其中一个maven模块变成灰色的故障如下所示:

点开查看项目结构发现,文件没有被正确识别。
解决方法:造成这个的原因可能是忽略了maven模块,可以尝试如下解决方法:在file->setting里,搜索maven,然后选择Ignored Filess,看右边的面板中变灰的maven模块是否处于勾选状态。勾选表示忽略了这个模块的pom文件。取消勾选即可解决。


取消勾选后依旧没有解决可以尝试点击,reimport重新加载依赖。
刚接触IntellijIDEA遇到的问题,我出现此问题的原因是因为以前创建过一个相同名字的模块,因为一些原因删掉了,重新创建同名模块的时候IntellijIDEA直接把我新模块的pom文件设置成了忽略状态。
点开查看项目结构发现,文件没有被正确识别。
解决方法:造成这个的原因可能是忽略了maven模块,可以尝试如下解决方法:在file->setting里,搜索maven,然后选择Ignored Filess,看右边的面板中变灰的maven模块是否处于勾选状态。勾选表示忽略了这个模块的pom文件。取消勾选即可解决。
取消勾选后依旧没有解决可以尝试点击,reimport重新加载依赖。
刚接触IntellijIDEA遇到的问题,我出现此问题的原因是因为以前创建过一个相同名字的模块,因为一些原因删掉了,重新创建同名模块的时候IntellijIDEA直接把我新模块的pom文件设置成了忽略状态。
8月6
今天有个同事说要我帮他看下怎么把这个定时任务的cron表达式放到配置文件里面去,
1、在类上加注解@Component,交给Spring管理
2、在@PropertySource指定配置文件名称,如下配置,指定放在src/main/resource目录下的application.yml文件
3、配置文件application.yml参考内容如下
application.yml
jobs:
customDictUpdateTime:
corn: "0/5 * * * * ?"
@Configuration
@Component
@Slf4j
@PropertySource(value = "classpath:application.yml")
public class QuartzTask {
@Autowired
private RedisUtil redisUtil;
private static boolean startTask = true;
@PostConstruct
public void startInit() {
excuteBusiness();
}
//定时任务初始化政务宝自定义词库
//如果获取不到, 取冒号后面的默认值
@Scheduled(cron = "${jobs.customDictUpdateTime.corn:0/5 * * * * ?}")
public void excuteTask() {
excuteBusiness();
}
}
上面说的是yml配置文件,有的同学就说了,那么我用的application.properties文件配置呢?
application.properties
jobs.customDictUpdateTime.corn=0/5 * * * *
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Configuration
@Component
@Slf4j
@PropertySource(value = "classpath:application.properties")
public class QuartzTask {
@Autowired
private RedisUtil redisUtil;
private static boolean startTask = true;
@PostConstruct
public void startInit() {
excuteBusiness();
}
//定时任务初始化政务宝自定义词库
//如果获取不到, 取冒号后面的默认值
@Scheduled(cron = "${jobs.customDictUpdateTime.corn:0/5 * * * * ?}")
public void excuteTask() {
excuteBusiness();
}
}
1、在类上加注解@Component,交给Spring管理
2、在@PropertySource指定配置文件名称,如下配置,指定放在src/main/resource目录下的application.yml文件
3、配置文件application.yml参考内容如下
application.yml
jobs:
customDictUpdateTime:
corn: "0/5 * * * * ?"
@Configuration
@Component
@Slf4j
@PropertySource(value = "classpath:application.yml")
public class QuartzTask {
@Autowired
private RedisUtil redisUtil;
private static boolean startTask = true;
@PostConstruct
public void startInit() {
excuteBusiness();
}
//定时任务初始化政务宝自定义词库
//如果获取不到, 取冒号后面的默认值
@Scheduled(cron = "${jobs.customDictUpdateTime.corn:0/5 * * * * ?}")
public void excuteTask() {
excuteBusiness();
}
}
上面说的是yml配置文件,有的同学就说了,那么我用的application.properties文件配置呢?
application.properties
jobs.customDictUpdateTime.corn=0/5 * * * *
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Configuration
@Component
@Slf4j
@PropertySource(value = "classpath:application.properties")
public class QuartzTask {
@Autowired
private RedisUtil redisUtil;
private static boolean startTask = true;
@PostConstruct
public void startInit() {
excuteBusiness();
}
//定时任务初始化政务宝自定义词库
//如果获取不到, 取冒号后面的默认值
@Scheduled(cron = "${jobs.customDictUpdateTime.corn:0/5 * * * * ?}")
public void excuteTask() {
excuteBusiness();
}
}
7月2
#表结构:
1、表一:Test1
Id name age
1
2
2、表二:Test2
Id name age
1 小明 10
2 小红 8
#实现将表Test2的name和age字段数据更新到表Test1中,按照id相等的条件
1、SQLServer多表更新方法:
语法:
UPDATE { table_name WITH ( < table_hint_limited > [ ...n ] ) | view_name | rowset_function_limited }
SET { column_name = { expression | DEFAULT | NULL } | @variable = expression | @variable = column = expression } [ ,...n ]
{ { [ FROM { < table_source > } [ ,...n ] ] [ WHERE < search_condition > ] } | [ WHERE CURRENT OF { { [ GLOBAL ] cursor_name } | cursor_variable_name } ] } [ OPTION ( < query_hint > [ ,...n ] ) ]
例子:
update test1
set test1.name=test2.name,test1.age=test2.age
from test1
inner join test2
on test1.id=test2.id
2、Oracle 多表更新方法:
语法:
UPDATE updatedtable
SET (col_name1[,col_name2...])= (SELECT col_name1,[,col_name2...]
FROM srctable [WHERE where_definition])
例子:
update test1
set (test1.name,test1.age)=
(select test2.name,test2.age from test2 where test2.id=test1.id)
3、MySql多表更新方法:
语法:
UPDATE table_references
SET col_name1=expr1 [, col_name2=expr2 ...] [WHERE where_definition]
例子:
update test1,test2
set test1.name=test2.name,test1.age=test2.age
where test1.id=test2.id
4、通用方法:(*^__^*)
update test1
set name=(select name from test2 where test2.id=test1.id),
age=(select age from test2 where test2.id=test1.id)
1、表一:Test1
Id name age
1
2
2、表二:Test2
Id name age
1 小明 10
2 小红 8
#实现将表Test2的name和age字段数据更新到表Test1中,按照id相等的条件
1、SQLServer多表更新方法:
语法:
UPDATE { table_name WITH ( < table_hint_limited > [ ...n ] ) | view_name | rowset_function_limited }
SET { column_name = { expression | DEFAULT | NULL } | @variable = expression | @variable = column = expression } [ ,...n ]
{ { [ FROM { < table_source > } [ ,...n ] ] [ WHERE < search_condition > ] } | [ WHERE CURRENT OF { { [ GLOBAL ] cursor_name } | cursor_variable_name } ] } [ OPTION ( < query_hint > [ ,...n ] ) ]
例子:
update test1
set test1.name=test2.name,test1.age=test2.age
from test1
inner join test2
on test1.id=test2.id
2、Oracle 多表更新方法:
语法:
UPDATE updatedtable
SET (col_name1[,col_name2...])= (SELECT col_name1,[,col_name2...]
FROM srctable [WHERE where_definition])
例子:
update test1
set (test1.name,test1.age)=
(select test2.name,test2.age from test2 where test2.id=test1.id)
3、MySql多表更新方法:
语法:
UPDATE table_references
SET col_name1=expr1 [, col_name2=expr2 ...] [WHERE where_definition]
例子:
update test1,test2
set test1.name=test2.name,test1.age=test2.age
where test1.id=test2.id
4、通用方法:(*^__^*)
update test1
set name=(select name from test2 where test2.id=test1.id),
age=(select age from test2 where test2.id=test1.id)
7月2
最近有个项目线上运行的时候客户说你们是不是限制了1M的,我说没有啊,原来发现是nginx报的。
从字面上看,说的是请求的实体太大的问题,那么可以联想到是HTTP请求中的Body大小被限制了的原因。
Nginx中的【client_max_body_size】配置属性
通过查资料,发现是Nginx配置中限制了请求的实体大小,因此就可以通过修改Nginx的配置文件来解决这个问题。Nginx的默认配置文件是conf目录下的nginx.conf文件,如果有自行扩展的配置文件可以在nginx.conf文件中查找include关键字去定位到相应的扩展配置文件。
具体的话是有一个【client_max_body_size】属性,这个属性可以配置在http节点下(http全局),可以配置在server节点下(server全局),也可以配置在location节点下(单应用)。要注意的是,这个属性在不配置的情况下默认值是1m,也就是限制了请求实体的大小为1m。
http节点下:
http {
# 将Nginx代理的所有请求实体的大小限制为20m
client_max_body_size 20m;
}
server节点下:
server {
# 将该服务下的所有请求实体的大小限制为20m
client_max_body_size 20m;
}
location节点下:
location /yanggb {
# 将此路由请求的实体大小限制为20m
client_max_body_size 20m;
}
保存之后要记得重启Nginx使修改后的配置生效。
service nginx restart
Tomcat的【maxPostSize】配置属性
另外的,Tomcat下的conf文件夹中的server.xml文件中也有属性配置【maxPostSize】可以限制post请求参数的大小。
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="2000"
redirectPort="8443"
URIEncoding="UTF-8"
maxThreads="3000"
compression="on" compressableMimeType="text/html,text/xml"
maxPostSize="256"/>
<Connection port="8009" enableLookups="false" redirectPort="8443" debug="0" protocol="AJP/1.3" />
要注意的是,在Tomcat7.0.63之前,maxPostSize属性设置为0和负数都可以代表不限制,但是之后的Tomcat版本只能将maxPostSize属性设置为负数才能代表不限制。
从字面上看,说的是请求的实体太大的问题,那么可以联想到是HTTP请求中的Body大小被限制了的原因。
Nginx中的【client_max_body_size】配置属性
通过查资料,发现是Nginx配置中限制了请求的实体大小,因此就可以通过修改Nginx的配置文件来解决这个问题。Nginx的默认配置文件是conf目录下的nginx.conf文件,如果有自行扩展的配置文件可以在nginx.conf文件中查找include关键字去定位到相应的扩展配置文件。
具体的话是有一个【client_max_body_size】属性,这个属性可以配置在http节点下(http全局),可以配置在server节点下(server全局),也可以配置在location节点下(单应用)。要注意的是,这个属性在不配置的情况下默认值是1m,也就是限制了请求实体的大小为1m。
http节点下:
http {
# 将Nginx代理的所有请求实体的大小限制为20m
client_max_body_size 20m;
}
server节点下:
server {
# 将该服务下的所有请求实体的大小限制为20m
client_max_body_size 20m;
}
location节点下:
location /yanggb {
# 将此路由请求的实体大小限制为20m
client_max_body_size 20m;
}
保存之后要记得重启Nginx使修改后的配置生效。
service nginx restart
Tomcat的【maxPostSize】配置属性
另外的,Tomcat下的conf文件夹中的server.xml文件中也有属性配置【maxPostSize】可以限制post请求参数的大小。
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="2000"
redirectPort="8443"
URIEncoding="UTF-8"
maxThreads="3000"
compression="on" compressableMimeType="text/html,text/xml"
maxPostSize="256"/>
<Connection port="8009" enableLookups="false" redirectPort="8443" debug="0" protocol="AJP/1.3" />
要注意的是,在Tomcat7.0.63之前,maxPostSize属性设置为0和负数都可以代表不限制,但是之后的Tomcat版本只能将maxPostSize属性设置为负数才能代表不限制。
5月28
在开发中如果我们遇到这种需要验证的接口应该怎么调用呢?
这里给出一个Basic Authentication 接口调用的工具示例:
package com.heckjj.utils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import org.apache.commons.codec.binary.Base64;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
public class GetAPIResultUtil {
/**
*
*
* @param url
* @param param
* @return
*/
public static String getAPIResult(String url, String param) {
PrintWriter out = null;
BufferedReader in = null;
String result = "";
try {
URL realUrl = new URL(url);
URLConnection conn = realUrl.openConnection();
//conn.setConnectTimeout(5000);
String plainCredentials = "heck:12345";
String base64Credentials = new String(Base64.encodeBase64(plainCredentials.getBytes()));
conn.setRequestProperty("Authorization", "Basic " + base64Credentials);
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("Content-type", "application/json");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
conn.setDoOutput(true);
conn.setDoInput(true);
out = new PrintWriter(conn.getOutputStream());
out.print(param);
out.flush();
in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
out.close();
in.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
return result;
}
}
至此对基本认证(Basic Authentication)的完整过程就基本实现了,希望对大家有所帮助!
这里给出一个Basic Authentication 接口调用的工具示例:
package com.heckjj.utils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import org.apache.commons.codec.binary.Base64;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
public class GetAPIResultUtil {
/**
*
*
* @param url
* @param param
* @return
*/
public static String getAPIResult(String url, String param) {
PrintWriter out = null;
BufferedReader in = null;
String result = "";
try {
URL realUrl = new URL(url);
URLConnection conn = realUrl.openConnection();
//conn.setConnectTimeout(5000);
String plainCredentials = "heck:12345";
String base64Credentials = new String(Base64.encodeBase64(plainCredentials.getBytes()));
conn.setRequestProperty("Authorization", "Basic " + base64Credentials);
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("Content-type", "application/json");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
conn.setDoOutput(true);
conn.setDoInput(true);
out = new PrintWriter(conn.getOutputStream());
out.print(param);
out.flush();
in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
out.close();
in.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
return result;
}
}
至此对基本认证(Basic Authentication)的完整过程就基本实现了,希望对大家有所帮助!
5月7
4月19
我现在是第一次打开抽屉子组件会发生请求,但是关闭抽屉组件,再一次打开就不请求了,数据没有改变,还是上一次的内容,导致我审批时通过的是另外一条的。
现在想要的效果是我每点击一次图标抽屉组件打开,就发送一次请求,请求最新的数据。
解决方法:
1、visible.sync:双向绑定值。
初始情况下通过该值控制 dialog显示。dialog关闭的时候,element自动设置该值为false。
当子组件执行 close 事件的时候,不仅改变了自己内部的 isShow 的值,而且还将 父组件的 visible的状态发生了改变.
2、在子组件 close 方法中,虽然已经将 isShow 改变为 false,但是并没有通知到 父组件,而在父组件中,控制弹出框的现实和隐藏是通过 show 。点击子组件的关闭按钮时,父组件的 show 没有发生改变,这时候需要用visible.sync。

这样就可以每次打开就重新渲染一次子组件;但有一个不好的就是如果一直重复点击,就会重复渲染,会影响效率。
现在想要的效果是我每点击一次图标抽屉组件打开,就发送一次请求,请求最新的数据。
解决方法:
1、visible.sync:双向绑定值。
初始情况下通过该值控制 dialog显示。dialog关闭的时候,element自动设置该值为false。
当子组件执行 close 事件的时候,不仅改变了自己内部的 isShow 的值,而且还将 父组件的 visible的状态发生了改变.
2、在子组件 close 方法中,虽然已经将 isShow 改变为 false,但是并没有通知到 父组件,而在父组件中,控制弹出框的现实和隐藏是通过 show 。点击子组件的关闭按钮时,父组件的 show 没有发生改变,这时候需要用visible.sync。
这样就可以每次打开就重新渲染一次子组件;但有一个不好的就是如果一直重复点击,就会重复渲染,会影响效率。
4月14
数据库中的数据 需要批量的替换 ,替换某个词或特殊符号
sql语句:
update 表名 set 字段名=REPLACE (字段名,'原来的值','要修改的值')
update pmsprojectmember set projectMemberType=REPLACE(projectMemberType,'BusinessOprator','BusinessOperator')
update user_item set addr=REPLACE (addr,'长沙','湘府')
添加条件:
update user_item set addr=REPLACE (addr,'长沙','湘府') where time<'2021-1-5';
sql语句:
update 表名 set 字段名=REPLACE (字段名,'原来的值','要修改的值')
update pmsprojectmember set projectMemberType=REPLACE(projectMemberType,'BusinessOprator','BusinessOperator')
update user_item set addr=REPLACE (addr,'长沙','湘府')
添加条件:
update user_item set addr=REPLACE (addr,'长沙','湘府') where time<'2021-1-5';
2月18
关于Hutool工具类之HttpUtil如何使用可以参考官方文档Hutool之HttpUtil
其实使用Http和Https使用的方式是一样的。
建议大家可以看看HttpUtil的源码,感觉设计的挺不错的。
导入Maven依赖
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>4.1.0</version>
</dependency>
编写测试类(使用Junit单元测试)
@Test
public void testHttps() throws Exception {
JSONObject json = new JSONObject();
json.put("username", "1332788xxxxxx");
json.put("password", "123456.");
String result = HttpRequest.post("https://api.heckjj.com/1/users")
.header("Content-Type", "application/json")
.header("X-heck-Application-Id","2f0419a31f9casdfdsf431f6cd297fdd3e28fds4af")
.header("X-heck-REST-API-Key","1e03efdas82178723afdsafsda4be0f305def6708cc6")
.body(json)
.execute().body();
System.out.println(result);
}
方法解释(上面采用的是一种叫链式编程的方式):
header对应的是请求头。
body对应的是请求体(包含参数和参数值)。
HttpRequest里面包含Post、GET、Delete、Put等常用的RestFul方式。
打印如下:
{"createdAt":"2019-04-30 10:42:07","objectId":"6cfdb77081","sessionToken":"269e433440c9e65b8058d016df703ccb"}
其实使用Http和Https使用的方式是一样的。
建议大家可以看看HttpUtil的源码,感觉设计的挺不错的。
导入Maven依赖
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>4.1.0</version>
</dependency>
编写测试类(使用Junit单元测试)
@Test
public void testHttps() throws Exception {
JSONObject json = new JSONObject();
json.put("username", "1332788xxxxxx");
json.put("password", "123456.");
String result = HttpRequest.post("https://api.heckjj.com/1/users")
.header("Content-Type", "application/json")
.header("X-heck-Application-Id","2f0419a31f9casdfdsf431f6cd297fdd3e28fds4af")
.header("X-heck-REST-API-Key","1e03efdas82178723afdsafsda4be0f305def6708cc6")
.body(json)
.execute().body();
System.out.println(result);
}
方法解释(上面采用的是一种叫链式编程的方式):
header对应的是请求头。
body对应的是请求体(包含参数和参数值)。
HttpRequest里面包含Post、GET、Delete、Put等常用的RestFul方式。
打印如下:
{"createdAt":"2019-04-30 10:42:07","objectId":"6cfdb77081","sessionToken":"269e433440c9e65b8058d016df703ccb"}