2014年工作中遇到的20个问题:141-160
141.日期转换。 //输入的时间为毫秒的准确时间 //firstTime:1417139867916,lastTime:1419731867916 public static int getDayBetweenTwoDate(long firstTime,long lastTime){ //当天的0点:1417104000000 long firstCalendaStartTime = getTheDayStartTime(firstTime); //当天的0点:1419696000000 long lastCalendaStartTime = getTheDayStartTime(lastTime); //0点相减结果为⑵592000000,转int(1702967296),再除,致使结果不对 int days = (int)(firstCalendaStartTime - lastCalendaStartTime) / 86400000; return days;//结果为⑴9 }
问题缘由:firstCalendaStartTime - lastCalendaStartTime 是比较大的负数,强迫转换成int,变成了正数。 应当是溢出或long强迫转换成int致使的。 不改变代码结构,只调剂优先级,先履行 除法,再履行 强迫转换: public static int getDayBetweenTwoDate(long firstTime,sans-serif; font-size: 14px; line-height: 20px;"> int days = (int)((firstCalendaStartTime - lastCalendaStartTime) / 86400000); return days;//⑶0 2014年11月28日履行,两月相差确切是30天 这段代码还有个“有歧义”的地方,通常betweenTwoDate应当返回正数,表明后面的比前面的大几天。 但,我们的代码想实现的是,前面的时间是不是比后面的时间大,如果小于,就表明过期了。 public static void main(String[] args) { Date now = new Date(); Date d2 = DateUtil.addMonth(now,1); System.out.println(now.toString()); System.out.println(d2.toString()); int days = DateUtil.getDayBetweenTwoDate(now.getTime(),d2.getTime()); System.out.println(days); 142.分类循环,都加上“编辑”事件。 可行方法1:只有1个地方使用el表达式,使用ready方法,页面加载完成,再渲染 <#list categoryRows as category> <!-- 循环进程中,js的变量相加‘"#cms_editor"+categoryId’不会生效,所有地方都直接使用${category.id}--> <script type="text/javascript"> $(document).ready( function(){ var id=${category.id}; $("#cms_editor"+id).bind("click",function(){ $("#editor_name"+id).toggle(); $("#category_name"+id).toggle(); }); </script> </#list> 可行方法2:每一个地方都直接使用el表达式 $("#cms_editor${category.id}").bind("click",sans-serif; font-size: 14px; line-height: 20px;">$("#editor_name${category.id}").toggle(); $("#category_name${category.id}").toggle(); </#list> 不可行方法3:只有最后1个分类,绑定了事件 注意事项: 先履行For循环,Freemarker模版渲染完成以后,返回前端Html,才可能履行js调用。 循环进程中,js的变量相加‘"#cms_editor"+categoryId’不会立即生效。 143. SpringMVC配置了异常处理器,通过实现HandlerExceptionResolver接口。 //解决异常 public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response,Object handler,Exception ex) { logger.error("error:",ex); ModelAndView view = new ModelAndView(exceptionPage); view.addObject("err",sans-serif; font-size: 14px; line-height: 20px;">//ex.printStackTrace(); return view; } 没有在控制台打印异常,错在哪都不知道,略显坑爹啊~ 144.Tomcat中配置了404页面。 <error-page> <error-code>500</error-code> <location>/error/500.html</location> </error-page> <error-page> <error-code>404</error-code> <location>/error/404.html</location> 访问1个不存在的页面,结果总是提示/error/404.html找不到。 加上SpringMVC配置<mvc:default-servlet-handler/>,就行了。 145.修改SiteMesh的Decorator.xml配置文件,需要重启利用服务器。 146.URL辨别大小写。 http://localhost:8080/jsgame/flappypig/flappyPig.html URL中的字母辨别大小写,最好统1成小写。 147.Javascript严格模式。 var flappy = (function (self) { 'use strict'; }); 设立"严格模式"的目的,主要有以下几个: - 消除Javascript语法的1些不公道、不严谨的地方,减少1些奇异行动; - 消除代码运行的1些不安全的地方,保证代码运行的安全; - 提高编译器效力,增加运行速度; - 为未来新版本的Javascript做好铺垫。 参考资料:http://www.ruanyifeng.com/blog/2013/01/javascript_strict_mode.html 148.数据库表的字段不能是关键字,比如“key”。 CREATE TABLE `briefcms_setting` ( `id` int(11) NOT NULL AUTO_INCREMENT,sans-serif; font-size: 14px; line-height: 20px;"> `key` varchar(255) DEFAULT NULL COMMENT 'key是关键字',sans-serif; font-size: 14px; line-height: 20px;"> `value` varchar(255) DEFAULT NULL,sans-serif; font-size: 14px; line-height: 20px;"> PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8; 数据库的字段名称key,在写update语句的时候,会报错。 update briefcms_setting set value='' where key =''; 把key改成name就能够了,太坑了。 149.Web服务器响应静态要求。 线上配置Nginx代理。 本地开发配置Tomcat <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>/static/*</url-pattern> </servlet-mapping> SpringMVC的也加上,<mvc:default-servlet-handler/> 150.SpringMVC的Controller与Struts2的Action,单例Singleton与多例Prototype。 Struts接收参数,是在Action类定义1个字段,比如Person,接收参数,是类作用域的变量。如果是单例,会同享。 所以,必须配置@Prototype SpringMVC接收参数,是在Controller的某个方法定义1个参数,比如Person,接收参数,是局部变量。 151.Mybatis的in查询。 方法1:参数list是个集合 <select id="batchList" resultType="java.util.Map"> select * from p2p_loan_info where lid in <foreach item="item" index="index" collection="list" open="(" separator="," close=")"> #{item.lid} </foreach> </select> 方法2:参数idList是"a,b,c"这类格式 @Select("select count(*) from p2p_post where category_id in (#{idList}) and status= 0") Integer getCountIn(String idList); 不可行的方法: category_id in #{idList},category_id in ${idList},idList是"(a,c)"。 #{}提示'' 字符串不对 ${}提示,找不到变量的getter方法 152.dao和mapper在同1个目录不需要??? <mapper class="com.p2p.user.dal.dao.IdCardDao"/> <mapper resource="mybatis/IdCardInfoMapper.xml"/> 不需要在mybatis-config.xml引入,只配置Dao根据接口Mapper扫描就能够了。 153. Java和Freemarker对“%”和“-”的支持不好。 Freemarker显示变量,不支持“-”和“%”,params.like-lid或params.%lid不可以,貌似对"%"和“-”不能正常辨认。 <input type="text" class="i-inp" id="search_lid" name="params[like_lid]" <#if page.params.like_lid> value="${page.params.like_lid}" </#if> /> Java的变量定义,不能以“-”结尾,比如“like-”不行。 //可行 String flagLike = "like_"; 154.对第123个问题的修正。 第123.Git Push毛病“Error writing request body to server”,解决方法可能会有问题。
我是在“User Setting”中增加的配置,而不是在“System Setting”里。 System Setting是不可写的,提示配置文件“Unknown”。 Boss也遇到了这个问题,他想通过设置“System Setting”,但是总是被谢绝,报NTFile相干的权限异常。 在“User Setting”里设置,就Ok了。 155.Eclipse日志文件寄存在何处 。 工程目录,比如J:JavaWebfansunion.metadata.log 156. 日期比较between and不够灵活。 where time between ${startDate} and ${endDate} 输入的可能只有startDate或endDate. <if test="startDate != null"> and time >= startDate </if>
<if test="endDate != null"> and time >= endDate 157. Mybatis解决“大于等于号”的问题。 > 大于 或使用 CDATA <![CDATA[ when min(starttime)<='12:00' and max(endtime)<='12:00' ]]>
158.遇到2个很像的单词,意思也类似。 totle:信息总数;资讯总数;全部;周遍 total:总计的(金额等); 全部的; 完全的; 绝对的 n.总计,总数; 全部数量 159.网上有HTML在线编辑器格式化功能,会把FTL的表达式,弄坏。 <#list list as item> </#list> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |