- JavaScript中英文括号转换
function convertBracketsFromZhCn2En(value) {
if(value){
value = value.replace(/(/g,"(");
value = value.replace(/)/g,")");
}
return value;
}
slate
spring mvc controller 参数
ie浏览器用location.hash直接修改hash值的方式来代替history.pushState
IE does not support the http status code 201 Created. Instead, use the standard response for a successful http request, 200 OK.
public ResponseEntity<byte[]> downloadStudentTemplate(HttpServletRequest request,
HttpServletResponse response) throws Exception {
//获取模板地址
String fileName = "学生导入模板.xlsx";
InputStream is = this.getClass().getResourceAsStream("/static/download/student-template.xlsx");
HttpHeaders headers = new HttpHeaders();
//下载显示的文件名,解决中文名称乱码问题
String downloadFielName = java.net.URLEncoder.encode(fileName, "UTF-8");
//通知浏览器以attachment(下载方式)打开图片
headers.setContentDispositionFormData("attachment", downloadFielName);
//application/octet-stream : 二进制流数据(最常见的文件下载)。 “Content-type: application/vnd.ms-excel; name=’Excel'”
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
return new ResponseEntity<byte[]>(this.readStream(is),
headers, HttpStatus.OK);
}
6.spring assert工具-有助于改善Java代码
notNull(Object object, "object is required") - 对象非空 3hf
isTrue(Object object, "object must be true") - 对象必须为true
notEmpty(Collection collection, "collection must not be empty") - 集合非空
hasLength(String text, "text must be specified") - 字符不为null且字符长度不为0
hasText(String text, "text must not be empty") - text 不为null且必须至少包含一个非空格的字符
isInstanceOf(Class clazz, Object obj, "clazz must be of type [clazz]") - obj必须能被正确造型成为clazz 指定的类
spring boot session timeout 设置
spring shiro session
jdbctemplate in 语句传参的问题
@controllerAdvice通知类
filter、servlet的流程顺序
13.http://tutorials.jenkov.com/java-servlets/servlet-filters.html
设置Java全局异常处理Thread.setDefaultUncaughtExceptionHandler()
https://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc
java class转map
public static Map<String, Object> introspect(Object obj) throws Exception {
Map<String, Object> result = new HashMap<String, Object>();
BeanInfo info = Introspector.getBeanInfo(obj.getClass());
for (PropertyDescriptor pd : info.getPropertyDescriptors()) {
Method reader = pd.getReadMethod();
if (reader != null)
result.put(pd.getName(), reader.invoke(obj));
}
return result;
}
- java.lang.IllegalArgumentException: Request header is too large
在server.xml中
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" maxPostSize="0" maxHttpHeaderSize ="102400"/>
Spring Boot中需要的配置:
application.properties:
server.tomcat.max-http-post-size=2147483647
- 前端捕获ajax请求error
//捕获ajax错误
$(document).ajaxError(function (xhr, props) {
log.info(xhr,props);
if (props.readyState !== 4 || props.status !== 200) {
pop.tips("您当前未登录或超时,2秒后将跳转至首页,请重新登录!", function () {
location.href = rootPath;
});
}
});
readyState
| 0
未初始化状态:此时,已经创建了一个XMLHttpRequest对象
1
准备发送状态:此时,已经调用了XMLHttpRequest对象的open方法,并且XMLHttpRequest对象已经准备好将一个请求发送到服务器端
2
已经发送状态:此时,已经通过send方法把一个请求发送到服务器端,但是还没有收到一个响应
3
正在接收状态:此时,已经接收到HTTP响应头部信息,但是消息体部分还没有完全接收到
4
完成响应状态:此时,已经完成了HTTP响应的接收 | | | | —- | —- | | | | | | | | | | | | || | —- | | | | |
status
| 1XX
服务器收到请求,需要继续处理。例如101状态码,表示服务器将通知客户端使用更高版本的HTTP协议。
2XX
请求成功。例如200状态码,表示请求所希望的响应头或数据体将随此响应返回。
3XX
重定向。例如302状态码,表示临时重定向,请求将包含一个新的URL地址,客户端将对新的地址进行GET请求。
4XX
客户端错误。例如404状态码,表示客户端请求的资源不存在。
5XX
服务器错误。例如500状态码,表示服务器遇到了一个未曾预料的情况,导致了它无法完成响应,一般来说,这个问题会在程序代码出错时出现。 | | | | —- | —- | | | | | | | | | | | | || | —- |
Java程序员必备的Intellij插件
dd
利用filter和全局ajax事件实现shiro session过期登录跳转http://www.realfond.cn/2017/05/29/%E5%88%A9%E7%94%A8filter%E5%92%8C%E5%85%A8%E5%B1%80ajax%E4%BA%8B%E4%BB%B6%E5%AE%9E%E7%8E%B0shiro%20session%E8%BF%87%E6%9C%9F%E7%99%BB%E5%BD%95%E8%B7%B3%E8%BD%AC/
jquery 捕获所有的ajax请求结果
//全局ajax事件,处理session过期跳转登录
$.ajaxSetup({
complete:function(XMLHttpRequest,status){
log.info("ajaxSetup.complete",XMLHttpRequest,status);
var sessionStatus = XMLHttpRequest.getResponseHeader("session-status");
if(sessionStatus==="timeout"){
pop.tips("您当前未登录或超时,2秒后将跳转至首页,请重新登录!", function () {
location.href = rootPath;
});
}
}
});
java延迟任务执行时间
https://stackoverflow.com/questions/27628106/java-executor-delay-not-working
linux下如何部署(执行)java jar包,并关闭此jar的进程
```javascript unzip -q suc-u-manage.jar &> /dev/null
nohup java -jar suc-u-manage-dev.jar >suc-u-manage-dev.log 2>&1 &
35. join
36. ![](https://cdn.yuque.com/yuque/0/2018/png/102277/1526537085395-5265f392-458e-460f-848c-327a0509d1cd.png#width=600)<br />37.[https://byoungd.gitbooks.io/english-level-up-tips-for-chinese](https://byoungd.gitbooks.io/english-level-up-tips-for-chinese)
37. java 函数接口
38. [Spring Boot使用Maven打包替换资源文件占位符](https://www.cnblogs.com/funnyboy0128/p/7693834.html)
39. spring boot 单元测试忽略某些类文件
40. profiles,@activeprofiles
41. [http://gik.firetrot.com/index.php/2016/12/02/exclude-beans-from-tests-in-spring-boot/](http://gik.firetrot.com/index.php/2016/12/02/exclude-beans-from-tests-in-spring-boot/)
42. [https://stackoverflow.com/questions/39041542/override-a-single-configuration-class-on-every-spring-boot-test?rq=1](https://stackoverflow.com/questions/39041542/override-a-single-configuration-class-on-every-spring-boot-test?rq=1)
43. spring boot打包 两种方式:打包时确定环境,运行时确定环境
44. [https://blog.csdn.net/lihe2008125/article/details/50443491](https://blog.csdn.net/lihe2008125/article/details/50443491)
45. [https://blog.csdn.net/shumoyin/article/details/77321154](https://blog.csdn.net/shumoyin/article/details/77321154)
46. [https://blog.csdn.net/q397739000/article/details/53037649](https://blog.csdn.net/q397739000/article/details/53037649)
47. [http://www.cnblogs.com/wenbronk/p/6855973.html](http://www.cnblogs.com/wenbronk/p/6855973.html)
48. 拷贝不同环境配置文件 [https://www.cnblogs.com/stark-summer/p/4829825.html](https://www.cnblogs.com/stark-summer/p/4829825.html)
49. 替换配置文件中的占位符${key} 更推荐的方式
```xml
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>xxl-job-admin.properties</exclude>
<exclude>xxl-job-admin-prod.properties</exclude>
<exclude>xxl-job-admin-test.properties</exclude>
<exclude>xxl-job-admin-dev.properties</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>xxl-job-admin-${profile.active}.properties</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<useDefaultDelimiters>true</useDefaultDelimiters>
</configuration>
</plugin>
</plugins>
</build>
- spring boot 启动脚本指定java版本目录
https://blog.csdn.net/jiyingying_up/article/details/51383872
#!/bin/bash
JAVA_HOME=/home/xinli/jdk1.8.0_92
JAVA=$JAVA_HOME/bin/java
nohup $JAVA -jar yunnan-rest-service-0.1.0.jar -Djava.ext.dirs=$JAVA_HOME/lib &
json文件读取
String jsonStr = new String(IOUtils.readFully(addTaskJson.getInputStream(), -1,true));
JSONObject json = JSONObject.parseObject(jsonStr);
调度
spring boot resttemplate http://websystique.com/spring-boot/spring-boot-rest-api-example/
微服务
5000所学校监控任务
数据监控技术选项,restful接口、dubbo服务远程过程调用