Java开发笔记
Java  /  管理员 发布于 3年前   282
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]
路人 在
php中使用hyperf框架调用讯飞星火大模型实现国内版chatgpt功能示例中评论 教程很详细,如果加个前端chatgpt对话页面就完美了..博主 在
科学上网翻墙之v2rayN-Core客户端免费公益节点使用教程中评论 @ mashrdn 多切换几个节点测试,免费ssr是没那么稳..mashrdn 在
科学上网翻墙之v2rayN-Core客户端免费公益节点使用教程中评论 V2rayn免费节点添加上去了,youtobe无法打开网页,是怎么回事..张伟 在
科学上网翻墙之v2rayN-Core客户端免费公益节点使用教程中评论 3q!有用,不过免费节点隔天就要去git上复制新的导进去..博主 在
科学上网翻墙访问Google , 上外网神器佛跳墙VPN(永久免费)使用流程步骤中评论 该篇教程已不能用了,告知大家,免的老有老铁问我!..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号