Skip to content

Instantly share code, notes, and snippets.

//url解码--javascript
var codeVal = encodeURIComponent('?code=20180711#abc');//%3Fcode%3D20180711%23abc
//url编码--javascript
var codeVal = decodeURIComponent("%3Fcode%3D20180711%23abc");//?code=20180711#abc
注意:
JS的decodeURI(URIstring)、encodeURI(URIString)对特殊字符无法转码、解码!不要使用!!
避免使用JS的escape()和unescape()方法。也有问题!!
反射获得protected、private变量
public class EsService {
private static List spellList = new ArrayList();
}
EsService service = new EsService();
Field spellListField = service.getClass().getDeclaredField("spellList");
spellListField.setAccessible(true);
List spellList = (List) spellListField.get(service);
如何设置spring boot集成 mybatis 然后sql语句打印到控制台,方便调试:
设置方法:
在application.properties文件中添加:
logging.level.com.zhangshitong.springbootModel.demo.mapper=DEBUG
'com.zhangshitong.springbootModel.demo.mapper'部分替换成自己项目XXXMapper.java(Dao)层所在的位置(包名)
//PostConstruct注解用于方法上,该方法在初始化的依赖注入操作之后被执行。
//这个方法必须在class被放到service之后被执行,这个注解所在的类必须支持依赖注入
@PostConstruct
public void init(){
//todo 业务逻辑
}
//Springboot 项目启动后执行某些自定义代码
@Component
public class MyApplicationRunner implements ApplicationRunner {
@zbo2018
zbo2018 / jdbc
Last active March 1, 2019 13:26
jdbc获取的时间是java.sql.Date、java.sql.Timestamp。不是java程序中使用的java.util.Date
java.sql.Date只包含年月日信息,时分秒毫秒都会清零。格式类似:YYYY-MM-DD
jdbc时间读取 vs 数据库表字段关系:
1: 如果数据库中是datetime类型,那么如果应用getString("writerDate") 有小时,分钟,秒
2: 如果数据库中是datetime类型,那么如果应用getDate("writerDate") 没有小时,分钟,秒
3: 如果数据库中是datetime类型,那么如果应用getTimestamp("writerDate") 有小时,分钟,秒
4: 如果数据库中是String类型,那么如果应用getTimestamp("writerDate") 报错
5: 如果数据库中是String类型,那么如果应用getString("writerDate") 有小时,分钟,秒
6: 如果数据库中是String类型,那么如果应用getDate("writerDate") 报错
getResource路径包含‘中文or空格’,读取文件提示找不到
String path_resource = this.getClass().getClassLoader().getResource("").getPath();
输出结果:
/E:/ideaProjects/esDemo/target/test-classes/
String path = this.getClass().getResource("/demo-files/智能研发办公部张波-201903话费发票.pdf").getFile();
输出结果:
/E:/ideaProjects/esDemo/target/test-classes/demo-files/%e6%99%ba%e8%83%bd%e7%a0%94%e5%8f%91%e5%8a%9e%e5%85%ac%e9%83%a8%e5%bc%a0%e6%b3%a2-201903%e8%af%9d%e8%b4%b9%e5%8f%91%e7%a5%a8.pdf
读取文件流,提示文件找不到
We couldn’t find that file to show.
//将2019-02-19T06:11:40.433Z 时间格式转换成Date类型格式
/*
备注:这个是UTC通用标准时格式,以z来标识。Z是和时区相关的。
我们当前的时区是+8区,06+8代表下午14点,即2019-02-19 14:11:40
例:2016-08-15T16:00:00.000Z 16+8正好是第二天0点,即2016:08:16 00:00:00
*/
String time = "2019-02-19T06:11:40.433Z";
time = time.replace("Z", " UTC");
System.out.println(time);//输出:2019-02-19T06:11:40.433 UTC
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS Z");
字符串转输入流
new ByteArrayInputStream("abcd".getBytes());
文件获取输入流
file.getInputStream();
代码获取web部署后resources目录资源文件内容
InputStream in = this.getClass().getResourceAsStream("/customer_faq");
String --> InputStream
@zbo2018
zbo2018 / getSession
Last active January 31, 2019 10:45
设置session超时时间、getSession用法
getSession用法
需求原因:
现实中经常会遇到以下3中用法:
HttpSession session = request.getSession();
HttpSession session = request.getSession(true);
HttpSession session = request.getSession(false);
概括:
request.getSession(true) 等同 request.getSession():若存在会话则返回该会话,否则新建一个会话。