随笔分类 - Java相关
摘要:package com.ksource.common.util; import java.io.File; import java.math.BigDecimal; /** * @Author dxy * @Date 2022/7/21 10:13 * @Description */ public
阅读全文
摘要:最后总结两者区别: 【1】json转换json对象 net.sf.json使用:JSONObject object = JSONObject.fromObject(body); com.alibaba.fastjson: JSONObject object = JSONObject.parseObj
阅读全文
摘要:如果要实现转换前的数据顺序与转换后的数据顺序一致,可以使用如下方式: String array2 = "{'i':'2','b':'3'}"; JSONObject parseObject = JSON.parseObject(array2, Feature.OrderedField); 此时会使用
阅读全文
摘要:使用 JSONTokener,JSONTokener.nextValue() 会给出一个对象,然后可以动态的转换为适当的类型。 String jsonStr = "...."; //json字符串 Object json = new JSONTokener(jsonStr).nextValue();
阅读全文
摘要:Collectors.groupingBy根据一个或多个属性对集合中的项目进行分组 数据准备: public Product(Long id, Integer num, BigDecimal price, String name, String category) { this.id = id; t
阅读全文
摘要:SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式 Calendar cld = Calendar.getInstance(Locale.CHINA); cld.setFirstDayOfWeek(Calendar.MO
阅读全文
摘要:/** * 获取当前时间所在周的周一和周日的日期时间 * @return */ public static Map<String,String> getWeekDate() { Map<String,String> map = new HashMap(); SimpleDateFormat sdf
阅读全文
摘要:获取本周一时间,然后+/-1就是下周/上周一的时间 import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class DateTest { public static D
阅读全文
摘要:import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBExc
阅读全文
摘要:分析Boolean.getBoolean()方法的真实返回值 Boolean.getBoolean()解析 String s = "true"; System.out.println(Boolean.getBoolean(s)); 猜猜这个输出结果是什么?我当然觉得是true,但事实是很残酷的,输出
阅读全文
摘要:dealDateFormat("2021-04-05T13:08:22+08:00"); public static Date dealDateFormat(String oldDateStr) { DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T
阅读全文
摘要:public static File multipartFileToFile(MultipartFile file) throws Exception { File toFile = null; if (file.equals("") || file.getSize() <= 0) { file =
阅读全文
摘要:使用alibaba的fastjson: import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; @Autowired privat
阅读全文
摘要:最简单的做法是: // 假如这是前台传来的Date时间 Date dt; // 1天的毫秒数 long oneDayTime = 1000*3600*24; // 这个now就是减1天的时间了 Date nowTime = new Date(dt.getTime() - oneDayTime); 原
阅读全文
摘要:public String delHTMLTag(String htmlStr) { String regEx_style = "<style[^>]*?>[\\s\\S]*?<\\/style>"; //定义style的正则表达式 String regEx_html = "<[^>]+>"; //
阅读全文
摘要:File file = new File(dirPath); if (!file.exists()) { file.mkdirs(); }
阅读全文
摘要:注意: 1. String filename = new String(“xx.zip”.getBytes(“UTF-8”), “ISO8859-1”);包装zip文件名不发生乱码。 2.一定要注意,否则会发生下载下来的压缩包无法解压。在给OutputStream 传值之前,一定要先把ZipOutp
阅读全文
摘要:indexOf(String s)的使用,如果包含,返回的值是包含该子字符串在父类字符串中起始位置;如果不包含必定全部返回值为-1
阅读全文
摘要:TxT转PDF可以直接使用IText就可以了,IText在pdf领域可以说暂时是最好的方案了。通过直接读取txt文件,然后生成pdf,再添加文本就可以了。 代码如下: simhei.ttf字体可从网上进行下载 项目中使用:
阅读全文