每一个人在工做中遇到的问题,不少都是相似的。了解别人遇到的问题,本身遇到的时候就能够很快地解决它。 不少人不屑于这种“细节问题”,但我想说,掌握这些细节问题一次可能只能帮你节省1s的时间,可是这个细节使用频率很是高, 1年能够节省很多时间的。若是按1秒*20次*300天=100分钟。css
181.MySQL数据库是否区分大小写。html
方法1:设置字符集校对collate 经过查询资料发现须要设置collate(校对) 。 collate规则:java
*_bin: binary case sensitive collation,也就是说是区分大小写的 *_cs: case sensitive collation,区分大小写 *_ci: case insensitive collation,不区分大小写
方法2:设置字段的字符集校对 mysql
1.能够将查询条件用binary()括起来。 好比: select * from TableA where columnA like binary('aaa'); 算法
2.能够修改该字段的collation 为 binary spring
好比: sql
ALTER TABLE User MODIFY COLUMN name VARCHAR(255) COLLATE utf8_general_ci DEFAULT NULL; 数据库
方法3:使用MySQL的lowwer函数和Java的toLowerCase方法。 apache
Java变量myname = myname.toLowerCase() SQL语句 select * from user where lower(name) like '%myname%'; 浏览器
参考资料:http://my.oschina.net/xiangtao/blog/33983 http://blog.csdn.net/lawmansoft/article/details/7217712
182.整数相加的溢出问题。 我原本想写一个通用求和方法sum(int… array); 想到可能会发生溢出,因此我须要判断是否溢出。
参考资料:http://blog.csdn.net/ljg888/article/details/8035276
方法1 19./*Determine whether arguments can be added without overflow */ 20.int taddOK(int x, int y){ 21. int sum = x + y; 22. int negOverflow = x < 0 && y < 0 && sum >= 0; 23. int posOverflow = x >= 0 && y >= 0 && sum <= 0; 24. 25. return !negOverflow && !posOverflow; 26.}
方法2 Goolge-Guava库/guava-libraries/guava/src/com/google/common/math/IntMath.java有以下方法
public static int checkedAdd(int a, int b) { long result = (long) a + b; checkNoOverflow(result == (int) result); return (int) result; }
用long保存int相加的临时结果,再强制转换为int,判断2个int是否相等。
183.jQuery在项目中最好只使用1个版本的,好比1.9。 jQueryUI版本要一致,不要搞2套主题,麻烦死了。 使用jQueryUI时,最好把全部相关的js、css、image都放进项目中。 若是每使用1个组件,就增长相关资源,容易出现问题。维护麻烦。
184.浮点数等符合类型进行运算。 Float one; Float two;
if(one != null && two != null){ result = one – two; }
在调试这个问题的过程当中,遇到了另外2个问题。
A.服务器端安装了2个安全补丁,致使我这边的Eclipse不能远程调试程序了,端口没法访问。巨坑啊!
B.Eclipse定位异常信息的具体位置。
Exception in thread "main" java.lang.NullPointerException at com.miaozhen.cms.controller.CampaignGroupController.ttt(CampaignGroupController.java:254) at com.miaozhen.cms.controller.CampaignGroupController.main(CampaignGroupController.java:248)
应该是上面的“ttt”的位置,这些细节很重要。
185.使用jQueryUI 对话框组件的时候,div最好设置为隐藏。 要否则可能会出现浏览器兼容性问题。
<div id="dialog-confirm" title="Delete the campaign group?" style="display:none;"> <p> <span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span> Are you sure? </p> </div>
186.jQueryUI datepicker日历组件。 为了给该组件增长1个“clear”按钮,咱们修改close的文本为clear,而后给它增长事件。 遇到的问题是,最小值和最大值 范围 选择时,遇到了bug,很差解决。
换成My97Datepicker.
仍是专业的更好啊!!!
187.JUnit单元测试的参数顺序问题。 void junit.framework.Assert.assertEquals(String expected, String actual) Asserts that two Strings are equal.
第1个参数是“期待的”,第2个参数才是 实际的值。 很长时间以来,我都搞错了顺序,今天才发现。
188.Spring 读取属性配置文件。 <!– Properties文件读取配置,*.properties –> < context:property-placeholder location="classpath*:*.properties" />
老是提示"${jdbc.url}"没法解析。
不起做用的配置 <context:property-placeholder location="classpath:*.properties" />
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:*.properties</value> </list> </property> </bean>
正确的方法,把上面的2种的“classpath:*.properties”改成"classpath*:*.properties"就能够了。
说明我弄的是maven项目,分红src/main/java和src/main/resource 2个Source Folder。
个人理解是:2个Source Folder都在classpath下,classpath*能够包含2个,这样就能找到 src/main/resource路径下的jdbc.properties等属性配置文件了 classpath*相关参考:http://blog.csdn.net/kkdelta/article/details/5507799
189.多个产品同步用户的问题。 User有2个标识字段 isChanged是否已经变动 updateTime,更新时间
增量同步:同步某个时间点后变动的。 全量同步:若是指“同步全部变动的”,是有问题的。一个产品同步user后,isChanged已经被修改了。 其它产品就不能同步了。
最终的定义:不要isChanged字段,只保留updateTime
其它产品同步用户时,带1个时间戳,或者带1个特殊标志,则同步全部的。 (再也不存在用户是否变动这一说法)
190.数据同步接口的主动同步与被动同步。
主动同步:程序定时,发送URL请求,同步另一个系统的数据。 被动同步:拥有数据的系统,当数据发生了变化时,回调须要同步数据的项目的接口。
191.Commons Fileupload组件能够用来方便地实现文件上传。 功能还挺多的。 http://commons.apache.org/proper/commons-fileupload/
今天才知道,SpringMVC上传文件,底层使用的是commons-fileupload。 SpringMVC也会偷懒,避免了重复造轮子。
192.英语词汇要统一。 StartTime和BeginTime都表示开始,StopTime和EndTime均可以表示结束时间。
要么都用StartTime和StopTime,要么都用BeginTime和EndTime。 相似的还有增长,使用Add或者Create,修改Modify或者Update。
193.表格的排序和图形标志要一致。 表格初始化的时候,结果集是按照id降序排列的,而图形标志却为非排序状态。
194.将My97Datepicker接收的日期是'2013-08-22'这种格式,后台须要转化为java.util.Date。 一不当心,日期的格式设置成了“YYYY-MM-HH”。
public static Date parseDate(String date) { if(StringUtils.isEmpty(date)){ return null; }
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date d = null; try { d = format.parse(date); } catch (ParseException e) { e.printStackTrace(); } return d; }
结论:从新实现一次很基本的功能,也可能出错。 使用之前的代码,通过检验的代码仍是比较靠谱的。 单元测试仍然颇有必要。
195.笔记本的Win7系统大半年没有更新了,比较卡,重装了系统。 遇到几个问题,网卡驱动没有安装,只好使用之前下载的惠普驱动。 发现不起做用。
最终:在惠普官网上,下载了好几个驱动,某一个成功了。
备份驱动、资料、数据库数据 都很必要。
196.更改eclipse中maven默认本地库repository的位置。 更换系统前,我把Maven的配置 .m2文件夹备份到了非系统盘目录, 如今要把Eclipse中Maven的位置修改成如今的位置,避免之后换系统再次备份, 避免如今从新下载库和影响到如今的项目。
Perferences-Maven-UserSetting,先设置maven的settings.xml 的位置,而后reindex。(首先修改settings.xml的文件)
<settings xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <localRepository> E:MavenRepository </localRepository> < /settings>
参考资料:http://blog.sina.com.cn/s/blog_52ef937201019waa.html
http://blog.chinaunix.net/uid-714081-id-2678568.html
197.Mybatis SQL语句优化,使用子查询代替联表。 <!– 性能很低,已经废弃 –> <!– 超级管理员 没有权限限制,普通用户有2种状况 –> < select id="list2" parameterType="campaign" resultType="campaign"> select distinct mc.*,mp.startTime,mp.endTime from st_monitor_campaign mc <if test="userId != null">,st_monitor_campaign_permission mcp </if> ,st_media_plan mp where … <!– 用户有权限,或者是本身或子用户建立的 –> < if test="userId != null"> and ( ( mc.MCampaignId = mcp.MCampaignId and permission = 1 and userId = #{userId} ) or (mc.CreatedUserId in (${userIdList}) )) </if>
(3种权限状况,只有1种状况须要链接st_monitor_campaign_permission表) 优化后(mc.CreatedUserId in (${userIdList})这个地方避免了链接permission表,并且是全表扫描) 使用mysql explain命令查看sql语句的各类详细细节,对sql优化颇有帮助
select distinct mc.*,mp.startTime,mp.endTime from st_monitor_campaign mc,st_media_plan mp where … <!– 用户有权限,或者是本身或子用户建立的 –> < if test="userId != null"> and ( ( mc.MCampaignId in (select mcp.MCampaignId from st_monitor_campaign_permission mcp where permission = 1 and userId = #{userId}) ) or (mc.CreatedUserId in (${userIdList}) )) </if>
从这个例子,能够看出Mybatis的好处。sql优化比较方便,不须要从新编译,不须要修改接口。
198.Window系统的电脑链接投影仪。 Win+P,快捷键,直接出现链接到投影仪 选项–仅计算机、复制、扩展、仅投影仪。 或者 在桌面->右键 屏幕分辨率->链接到投影仪->仅计算机、复制、扩展、仅投影仪。
复制 是最好的选择,电脑和投影仪画面彻底一致,即投影仪的界面是 电脑的“副本”。 而扩展则须要把电脑中的画面 拖进某个地方,投影仪才能看到。具体很差描述。
建议:优先使用复制,其次才是投影仪。
199.java -Dfile.encoding设置解决程序运行乱码问题。 Java默认使用的是系统的编码,好比 Win7中文系统默认就使用GBK,读文件时默认按照GBK格式读取。 经过设置java -Dfile.encoding,能够按照本身定义的编码来读取文件。
200.慎用全局变量。 Spring中的Service,单例的。 class UserService{
@Autowired private CampaignGroupDAO campaignGroupDAO;
private List<Integer> allSonUserIds = new ArrayList<Integer>();
//得到1个用户的全部子用户 public List<Integer> getSonUserIds(int userId) { List<Integer> userIds = userDAO.getSonUserIds(userId); if(!userIds.isEmpty()){ for (Integer id : userIds) { allSonUserIds.add(id); getSonUserIds(id); } } return allSonUserIds; } }
错误的写法2 public List<Integer> getSonUserIds(int userId) { //记录全部的子用户的Id List<Integer> allSonUserIds = new ArrayList<Integer>(); List<Integer> userIds = userDAO.getSonUserIds(userId); if(!userIds.isEmpty()){ for (Integer id : userIds) { allSonUserIds.add(id); getSonUserIds(id); } } return allSonUserIds; } 说明:这段代码不是我写的啊,别喷我。o(︶︿︶)o
我的见解:使用迭代 public List<Integer> getSonUserIds(int userId) { //维护全部的 List<Integer> allList = new ArrayList<Integer>();
//维护一个“队列” List<Integer> allSonUserIds = new ArrayList<Integer>(); allSonUserIds.add(userId); allList.add(userId);
for(Integer userId :allSonUserIds){ List list= userDAO.getSonUserIds(userId); //修改当前队列 allSonUserIds.addAll(list); //删除已经遍历过的元素 allSonUserIds.remove(userId);
//维护全部的用户id allList.addAll(list); }
return allList; }
使用迭代的代码彷佛也存在这个问题,即迭代中删除元素致使的问题, 我在“2013年工做中遇到的20个问题:1-20”第16个有描述,使用 for(Iterator iterator =p.iterator();iterator.next();){ if(){ iterator.remove(); } } 这种方式不会有问题,而for循环有问题 ###################################################### for(int index=0;index<p.size();index++){—再也不正确,由于index也发生了变化
} 。
如今的问题是for-each循环是否正确呢?? allSonUserIds.remove(userId); 这种方式删除元素,效率也比较地。
最好仍是使用Iterator进行遍历和删除。
另一个问题: //维护一个“队列” List<Integer> allSonUserIds = new ArrayList<Integer>();
维护队列仍是使用Queue比较好,push和pop也很合适。
和公司大牛谈到这个问题,让我想起了大二写遍历二叉树算法,使用迭代而非递归实现时, 当时用的就是队列。
问题故而知新!!!