開發(fā)小記
禁止頁面滾動
js
document.body.style.overflow='hidden';
jquery
$('body').css('overflow','hidden');
監(jiān)聽input的輸入事件
// propertychange 事件是針對ie瀏覽器的,要放到input事件前面
$('#boardlot_num').on('propertychange input',function(){
// do something
}
綁定input事件的時候我發(fā)現(xiàn)以前用的autoNumerbic 跟它 會有沖突:
chrome 和 firefox 支持input事件,綁定autoNumberic插件后丰捷,自定義的input事件失效
于是我做了一點(diǎn)關(guān)于input限制輸入純數(shù)字的解決方案:
html代碼 :
<input id="boardlot_num" value="1" data-pre="1" />
js代碼:
$('#boardlot_num').on('propertychange input',function(){
var value = $(this).val(), preValue = $(this).data('pre');
if(/^\d*$/.test(value)){
// do something
$('#boardlot_num').data('pre',value);
}else{
$('#boardlot_num').val(preValue);
}
});
// 兼容chrome firefox ie8 親測有效
按List中的對象的屬性排序
// 查詢list
List<MallProductTeambattleSignup> ogSigns = mallProductTeambattleSignupServ.list(propsSignup, 1, 8, null);
// 初始化比較器禾嫉,比較器的泛型為list的泛型
Comparator<MallProductTeambattleSignup> comparator = new Comparator<MallProductTeambattleSignup>() {
@Override
public int compare(MallProductTeambattleSignup o1, MallProductTeambattleSignup o2) {
// 按count屬性按降序排
return o2.getCount() - o1.getCount();
}
};
// 調(diào)用Colloctions接口對list排序
Collections.sort(ogSigns, comparator);
Git 配置 path
配置 ...\Git\bin 和 Git\libexec\git-core
sql執(zhí)行順序
- from子句組裝來自不同數(shù)據(jù)源的數(shù)據(jù);
- where子句基于指定的條件對記錄行進(jìn)行篩選科汗;
- group by子句將數(shù)據(jù)劃分為多個分組;
- 使用聚集函數(shù)進(jìn)行計(jì)算;
- 使用having子句篩選分組澳叉;
- 計(jì)算所有的表達(dá)式;
- 使用order by對結(jié)果集進(jìn)行排序
(8)SELECT (9)DISTINCT
(11)<TOP_specification> <select_list>
(1)FROM <left_table>
(3)<join_type> JOIN <right_table>
(2)ON <join_condition>
(4)WHERE <where_condition>
(5)GROUP BY <group_by_list>
(6)WITH {CUBE ROLLUP}
(7)HAVING <having_condition>
(10)ORDER BY <order_by_list>
打亂一個list的順序
應(yīng)用場景:
我要做援購的隨機(jī)取援購碼斩狱,但他們在數(shù)據(jù)庫中是數(shù)據(jù)存在的耳高,于是乎,有多種方法:亂序存順序遍歷
所踊,順序存亂序遍歷
等等泌枪。
這里利用了一個小技巧,順序存秕岛,讀取之后打亂碌燕,再順序取误证,基本代碼如下:
List<?> unusedCodes = xxx.list(****);
// shuffle 是 洗牌的意思
java.util.Collections.shuffle(unusedCodes);
// 遍歷,不贅述
for(...){
// TODO ...
}
java基礎(chǔ)真的很重要修壕。這道題當(dāng)作是一道面試題都行愈捅。
js 獲取url參數(shù)
var mycode = window.location.search.substr(1).split("&")[0];
mycode = mycode.split('=')[1];
數(shù)據(jù)庫類型用的date類型非datetime類型報(bào)batch_update錯誤
RT
mysql group_concat() 陷阱
mysql配置group_concat()函數(shù)最長可接收1024長度,對于某些情景下這個長度是不夠的慈鸠。
查詢語句:
SELECT @@global.group_concat_max_len;
修改語句:
-- 大小請自行斟酌
SET GLOBAL group_concat_max_len=102400;
也可以在文件(my.ini)中后邊追加這一句:
group_concat_max_len = 102400
注:我用的mysql是5.6.20蓝谨,文件在C:\ProgramData\MySQL\MySQL Server 5.6\my.ini
關(guān)于hql查詢和sql查詢
hql查詢用user_id
和userId
這兩種形式都好使(前提是po用的userId
形式,dao層用getCurrentSession青团,如果用openSession是無效的)
關(guān)于轉(zhuǎn)義
經(jīng)過我這段時間的觀察譬巫,有以下幾個地方會出問題:
- 后臺拼接html返回頁面。對于開放輸入的內(nèi)容要用StrUtil.escapeHtml()方法或者StrUtil.textarea2Html()等方法督笆。
- 前臺jsp中的el表達(dá)式芦昔,如
${user.nickname}
,改成struts標(biāo)簽形式<s:property value="user.nickname"/>
- 前臺ajax返回?cái)?shù)據(jù)時進(jìn)行處理娃肿,如
$('#nickname').text(data.nickname)
咕缎,改為$('#nickname').text($('<pre/>').text(data.nickname).html())
如果還有其他情況會繼續(xù)補(bǔ)充
The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory異常
這個異常是servlet執(zhí)行service方法時報(bào)的錯,多半是jdk料扰、tomcat和web.xml之間不匹配出現(xiàn)的凭豪。tomcat8中servlet-api.jar改了很多,在svn項(xiàng)目檢出時记罚,j2ee版本不要定太高墅诡,目前意思網(wǎng)的是2.5,tomcat8的標(biāo)準(zhǔn)是3.1,但我不建議到3.1,容易出現(xiàn)servlet的bug
網(wǎng)友解答:
Get rid of any servletcontainer-specific libraries such as jsp-api.jar in your /WEB-INF/lib folder. This exception indicates that you've put servletcontainer-specific libraries of a container which supports only Servlet 2.4 / JSP 2.0 or older in there (the getJspApplicationContext() method was introduced in Servlet 2.5 / JSP 2.1). This is a major mistake. Those libraries don't belong in the webapp's classpath.
Perhaps you did this to overcome project compilation errors, which is indeed a pretty common beginner's mistake. This should have been solved differently, you should refer the target runtime in your project, not copy some libraries of an arbitraty servletcontainer make/version into your project. It would make your project incompatible with servletcontainers of a different make and/or version.
相關(guān)鏈接1
/相關(guān)鏈接2
關(guān)于html中的target屬性與點(diǎn)擊事件
如果用到target="_blank"
點(diǎn)擊時會新開頁桐智,并且每次點(diǎn)擊展開不同頁面末早。
如果用到target="xxxx"
點(diǎn)擊時會新開頁,但是每次點(diǎn)擊都是刷新同一頁面
在新開的頁中说庭,能夠取到父頁面的元素然磷,如下:
window.opener.$.find('#bgColor')
真正點(diǎn)擊觸發(fā)的事件中,回調(diào)函數(shù)寫window.open
是不會被屏蔽的
ServletContext取資源路徑
舊版本當(dāng)前使用的方法是
String path = ServletContext.getRealPath("WEB-INF/config");
但是網(wǎng)友們說刊驴,這不好姿搜,這是坑,而且tomcat8下不好使捆憎,改進(jìn)代碼如下:
URL url = this.context.getResource("/WEB-INF/config");
path = url.getPath();
關(guān)于ActiveXObject
window.ActiveXObject 這個元素在ie8-10都是存在的舅柜,ie11就沒了
js比較數(shù)字大小
比較大小之前一定要看看變量的類型,如果是String
型躲惰,就得這樣寫
parseInt(arg0) < parseInt(arg1)
否則會出現(xiàn)500>1000的情況(字符串比較大小按單個字符比較)
Hibernate merge和save區(qū)別
merge對對象操作之后致份,持久化會斷開,如果期望執(zhí)行的是save操作础拨,保存之后的自增主鍵是獲得不到的
eclipse啟動時Workspace in use or cannot be created, choose a different one
把workspace.metadata目錄下的.lock文件刪除掉
IE8下的js原生trim報(bào)錯
使用jquery的$.trim()
jQuery給DOM追加元素時氮块,可以簡化
$('body').append($('<li/>');
標(biāo)簽按鈕切換抖動問題
選中狀態(tài)下加了classthis
绍载,this的樣式加了1px的border,如果line-height
跟hight
一樣的話滔蝉,會有抖動問題击儡,修改為line-height = height - 2*border
杜絕連點(diǎn)問題
- 表單提交,如果是struts下可以加<s:token/>
<s:form action="page1" theme="simple">
<s:datetimepicker name="order.date" label="購買日期" toggleType="explode" value="today"/><br/>
<s:token/>
<s:reset/><s:submit/>
</s:form>
另外要配置攔截器蝠引,詳情請戳我
- ajax提交可以這樣做:
$('#submit').on('click', function() {
// 校驗(yàn)表單
if( validateForm() ) return;
// 接觸綁定的點(diǎn)擊事件
$('#submit').off('click');
// 提交表單
// TODO
})
off()
函數(shù)可以解除指定元素上的指定事件
jquery 文檔 :英 中
unbind
方法跟這樣的作用類似
jquery 文檔 :英 中
意思網(wǎng)