1、替换文件后缀名
@Test
public void test5() {
String url = "http://www.baidu.com/aaa.pdf";
String fileTyle=url.substring(url.lastIndexOf("."));
System.out.println("文件后缀名为:" + fileTyle);
String newPath = url.substring(0, url.lastIndexOf(".")) + ".jpeg";
System.out.println("新路径:" + newPath);
}
打印结果:
2、使用s%占位符拼接字符串
@Test
public void test8() {
String url = "https://www.baidu.com?str1=%s&str2=002&str3=%s&str5=%s";
String str1 = "001";
String str3 = "003";
Integer str5 = 555;
String pushUrl = String.format(url, str1, str3, str5);
System.out.println("转换后推送的链接为:" + pushUrl);
}
打印结果
3、对日期的一些操作
@Test
public void test10() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
String today = sdf.format(calendar.getTime());
String startTime = today.substring(0, 10) + " 00:00:00";
calendar.add(Calendar.DAY_OF_MONTH, -1);
String beforeOneDay = sdf.format(calendar.getTime());
calendar.add(Calendar.HOUR_OF_DAY, -1);
String beforeTwentyFiveHours = sdf.format(calendar.getTime());
System.out.println("当天的零点时间:" + startTime);
System.out.println("当前时间:" + today);
System.out.println("一天前的时间:" + beforeOneDay);
System.out.println("25小时前的时间:" + beforeTwentyFiveHours);
}
运行结果:
4、mybatisplus使用模糊查询
EntityWrapper<Question> entityWrapper = new EntityWrapper();
entityWrapper.like(StringUtil.isNotEmpty(questionName),"name", questionName);
entityWrapper.orderBy("created_at",false);
return selectPage(page, entityWrapper);
|