均来自网络,验证通过
Spring中的component
普通pojo实例化到spring容器,当我们的类不属于各种归类的时候
正则提取数字:
String a="liu847yan064zhao370";
String regEx="[^0-9]";
//方法一(需要导入regex类)
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(a);
System.out.println(m.replaceAll(""));//847064370
//方法二、
System.out.println(a.replaceAll(regEx, ""));//847064370
-------------------------------------------------------------------------------------------------------------------------------------类型String与int互转
Int转string:num+“”费时、String.valueOf(num)、Integer.toString(num)
valueOf采用 Object#toString()不需要担心null,当为null时返回“null”
toString()采用同上,不能null,抛出nullpointerexception
Integer.parseInt()与Integer.valueOf(str).intValue()
第二string包装成integer再转基本类型
--------------------------------------------------------------------------------------------------------------------------------------
阿拉伯数字转中文数字: 如:333 三百三十三
public class Test { public static void test(int d) {// String[] str = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" }; // String[] str = { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" }; // String ss[] = new String[] { "元", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿" }; String ss[] = new String[] { "个", "十", "百", "千", "万", "十", "百", "千", "亿" }; String s = String.valueOf(d); System.out.println(s); StringBuffer sb = new StringBuffer(); for (int i = 0; i < s.length(); i++) { String index = String.valueOf(s.charAt(i)); sb = sb.append(str[Integer.parseInt(index)]); } String sss = String.valueOf(sb); int i = 0; for (int j = sss.length(); j > 0; j--) { sb = sb.insert(j, ss[i++]); } System.out.println(sb); } public static void main(String[] args) { test(3213); test(912321321); }} |
--------------------------------------------------------------------------------------------
List排序
Collections.sort(list);
Lambda:java8
teachers.sort((s1, s2) -> s1.getAge().compareTo(s2.getAge()));根据年龄
Collections.sort(teachers, Comparator.comparing(Teacher::getAge));
倒序:
Comparator<Teacher> comparator = (t1, t2) -> t1.getAge().compareTo(t2.getAge());
teachers.sort(comparator.reversed());
组合排序:
teachers.sort(Comparator.comparing(Teacher::getAge).thenComparing(Teacher::getName));
---------------------------------------------------------------------------------------------------------------------------------------
List去重:
两个for遍历list,if判断是否equals,是则list.remove(j) return
通过hashSet:重复的自剔除
List放到hashset的构造函数中,list.clear()、list.add(h)、return
list = list.stream().distinct().collect(Collectors.toList());(推荐java8)
Hashset:实现set接口,哈希表(hashmap实例)支持,容许null
元素存HashMap的key上、遍历时遍历的key,使用map保存元素,map值为由虚拟object承担
public Iterator<E> iterator() {
return map.keySet().iterator();
}
插入时底层map判断key是否存在,不存插否不插,删同map
Linkedhashset:
继承自hashset、底层实现linkedhashmap,初始化super()
Treeset:
元素有序(关键字大小)不重,底层实现treemap
比较器:元素互相比较
-------------------------------------------------------------------------------------------------------------------------------------
时间:
计算相差分钟:
SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date begin=dfs.parse("2004-01-02 11:30:24");
Date end = dfs.parse("2004-03-26 13:31:40");
//除以1000是为了转换成秒
long between=(end.getTime()-begin.getTime())/1000; long min=between/60;
---------------------------------------------------------------------------------------------------------------------------------------Mysql:
某天数据:https://blog.csdn.net/mayunyun1987100/article/details/38664931
select * from tab where FROM_UNIXTIME(fabutime, '%Y%m%d') = 20121217;
select * from 表名 where to_days(时间字段名) = to_days(now());//now今天的数据
昨天、7天、近30天、本月、上一月、字段名、本季度、上季度、本年、去年
----------------------------------------------------------------------------------------------------------------------------------
Springboot定时器:
pom文件引jar
入口类添加@EnableScheduling,需要定时执行的方法上添加:
@Scheduled(cron = "0/2 * * * * *") 后面为Cron表达式
Xml方式:新建类文件
添加注解:
@Configuration //证明这个类是一个配置文件
@EnableScheduling //打开quartz定时器总开关
方法中同上
------------------------------------------------------------------------------------------------------------------------------
文件File转mutipartFile:
mutipartFile是spring定义接口,封装用户上传时包含的信息
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.12.RELEASE</version>
<scope>test</scope>
</dependency>
FileInputStream inputStream = new FileInputStream(file);
MultipartFile multipartFile = new MockMultipartFile(file.getName(), inputStream);
感谢分享:如侵犯您的权利,请与我联系,立马删除
https://blog.csdn.net/liu_yanzhao/article/details/70849039
String与int互转的时间:
https://blog.csdn.net/u012050154/article/details/51320638
阿拉伯数字转中文数字:
https://zhidao.baidu.com/question/2053114379256640187.html
分词查询,排序:
https://blog.csdn.net/u013821825/article/details/61202287
当天数据:
select count(*) from t_user_behavior WHERE user_id = '1' and to_days(enter_time) = to_days(now())
https://blog.csdn.net/mayunyun1987100/article/details/38664931
重复元素list
https://www.cnblogs.com/cainiao-Shun666/p/7911142.html
hashMap
https://blog.csdn.net/sugar_rainbow/article/details/68257208
相差时间分钟:
https://zhidao.baidu.com/question/521382815575743245.html
添加定时器:
https://blog.csdn.net/liboyang71/article/details/72781526
File转multipartFile
https://blog.csdn.net/Altoin/article/details/78275164
Oss文件的url
https://www.alibabacloud.com/help/zh/faq-detail/39607.htm
整除、取余
https://blog.csdn.net/xlll5211314/article/details/44492043
Mybatis中的 ${ } 和 #{ }的区别
https://www.cnblogs.com/dato/p/7027949.html
四舍五入:
https://blog.csdn.net/lizhenmingdirk/article/details/7335285
int占32位的时候,最大可以赋值为:2147483647