Java开发笔记
Java  /  管理员 发布于 2年前   143
1、Map<key,value>的remove方法只能识别相同类型的key值
Map<Integer,String> map = new HashMap<Integer,String>();map.put(1,"a");map.put(2,"b");map.put(3,"c");Short one = 1;map.remove(one);int two = 2;map.remove(two);
以上代码最后Map中剩余的值为:1=a,3=c,只有key为2的map被删除掉了。所以如果要删除short one的话必须修改代码为:map.remove(one.intValue())
2、Hibernate的HQL不支持原生INSERT操作“INSERT INTO table (xx,xxx) VALUES(?,?)”,只支持“INSERT INTO table (xx,xxx) SELECT aa,bb FROM otherTable ...”,所以如果是向一张表新增数据就只能使用session.save(object)
3、两个Date类型的变量可以通过compareTo方法来比较。此方法的描述是这样的:如果参数 Date 等于此 Date,则返回值 0;如果此 Date 在 Date 参数之前,则返回小于 0 的值;如果此 Date 在 Date 参数之后,则返回大于 0 的值。
Date dateTime1 = dateFormat.parse(DateStr1);Date dateTime2 = dateFormat.parse(DateStr2);int i = dateTime1.compareTo(dateTime2);
4、对象数据类型比较的是内存地址而不是值,如下代码
Long id1 = Long.valueOf("123");Long id2 = Long.valueOf("123");if(id1 == id2){true;}else{false;}
上面代码返回的结果为false,而如果要想比较id1和id2的值必须这样写:
if(id1.longValue() == id2.longValue()){}
5、循环删除List内的数据
Iterator<Integer> iterator = ints.iterator(); while (iterator.hasNext()) { Integer temp = iterator.next(); if (temp % 3 != 0) { iterator.remove(); } }
7、JSTL格式化时间
<fmt:formatDate value="${result}" type="both" dateStyle="full" pattern="yyyy-MM-dd hh:mm" var="createTime"/>JSP读取:${createTime }
8.HttpServletRequest对象
/***假如一个请求路径为:http://localhost:8080/demo/apps/demo.jhtml**///返回/demo/apps/demo.jhtmlSystem.out.println("requestURI="+request.getRequestURI());//返回http://localhost:8080/demo/apps/demo.jhtmlSystem.out.println("requestURL="+request.getRequestURL());//返回/apps/demo.jhtmlSystem.out.println("servletPath="+request.getServletPath());
9.java的split方法,如下格式的字符串,将字符串split转换为数组之后,数组的长度为3而不是4,原因是最后一个@符号后如果是空则不会被计入数组中。
String d = "@2@3@";String[] s = d.split("@");System.out.println(s.length); //输出:3System.out.println(s.toString()); //输出:[,2,3]
阿凡达123 在
golang 怎么做热更新中评论 也可以看看这个:https://github.com/edwingeng/hot..博主 在
hyperf框架常用命令-在centos7中退出命令及在docker容器中退出命令中评论 @路过的靓仔:cdn静态资源被墙,已修复..GGGGGGGGG 在
layui框架常用输入框介绍中评论 写的很好解决问题..路过的靓仔 在
hyperf框架常用命令-在centos7中退出命令及在docker容器中退出命令中评论 剩下好多 wait 状态的..激光豆芽 在
为什么你不能安逸?国内996为什么没有国外955香?中评论 国内现在无意义的内卷太多了..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号