1. 程式人生 > >知識點總結-2018.05.23

知識點總結-2018.05.23

1.jstl 引入其他jsp頁面

   <a data-toggle="tab" id="tap11" href="#tab1">建模</a>
   <div id="tab1" class="tab-pane in active"><c:import url="project_work_1.jsp"></c:import></div>

2. 得到tomcat專案釋出路徑(不知道(2)什麼意思)

     (1)httpServletRequest.getRealPath("/")
	 (2)public static String getClasspath(){
			String path = (String.valueOf(Thread.currentThread().getContextClassLoader().getResource(""))+"../../").replaceAll("file:/", "").replaceAll("%20", " ").trim();	
			if(path.indexOf(":") != 1){
				path = File.separator + path;
			}
			return path;
		}

3.陣列轉List

 Arrays.asList()

4.diaglog的基本用法

    function addPeriod(Id){
			 var diag = new top.Dialog();
			 diag.Drag=true;
			 diag.Title ="編輯";
			 diag.URL ='<%=basePath%>period/goAdd.do?tab=${pd.period_type}&OID='+Id;
			 diag.Width = 400;
			 diag.Height= 300;
			 diag.CancelEvent = function(){ //關閉事件
				 if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
						
					 	setTimeout("self.location.reload()",100);
						top.jzts();
						
				}
				diag.close();
			 };
			 diag.show();
	}

5.jquery juqery 遮罩

    top.jzts();   //如果網頁出錯遮蔽網頁的操作
    $(top.hangge());   //清除遮蔽網頁的動作

6.你猜是什麼

    ModelAndView mv = this.getModelAndView();
    mv.addObject("varlist", list);
	mv.addObject("varlistworker", listworker);
	mv.addObject("varlist1", list1);
	mv.addObject("varlistworker1", listworker1);
	mv.addObject("varlist2", list2);
	mv.addObject("varlistworker2", listworker2);
	mv.addObject("varlist3", list3);
	mv.addObject("varlistworker3", listworker3);
			
			
	<c:forEach begin="1" end="3" step="1" varStatus="status">
		<c:set var="varIndex" scope="page" value="varlist${status.index}"/>
		<c:set var="varIndex1" scope="page" value="varlistworker${status.index}"/>
		<c:set var="dataList" scope="request" value="${requestScope[varIndex]}"/>
		<c:set var="dataList1" scope="request" value="${requestScope[varIndex1]}"/>
		
		<div id="tab${status.index}" class="tab-pane <c:if test="${status.index == 1}">in active</c:if>">
			<c:import url="project_work.jsp">
				<c:param name="periodType" value="${status.index}"></c:param>
			</c:import> 
		</div>
	</c:forEach>

7.controller方法之間相互跳轉

    return new ModelAndView("redirect:/project/goView.do?OID="+projectOID+"&titleProjectWork="+titleProjectWork);	

8.帶引數的請求轉發

@RequestMapping(value="/redirect",method=RequestMethod.GET)  
public String testRedirect(RedirectAttributes attr){  
     attr.addAttribute("a", "a");  
     attr.addFlashAttribute("b", "b");  
     return "redirect:/index.action";  
}  

9.sprng < form:check > 使用
這裡寫連結內容

10.模糊查詢

<if test="name != '' and name !=null">
         and a.name LIKE CONCAT('%', #{name}, '%')
</if>

11.引入sql

<sql id="systemParamColumns">
        a.id,
        a.name,
        a.code,
        a.value,
        a.unit,
        a.type AS "dict.value",
        b.label AS "dict.label",
        a.remarks,
        a.create_by AS "createBy.id",
        a.create_date,
        a.update_by AS "updateBy.id",
        a.update_date,
        a.del_flag
    </sql>

    <sql id="systemParamJoins">
        LEFT JOIN sys_dict b ON a.type = b.value AND b.type = #{dict.type}
    </sql>

    <select id="get" resultType="KfSystemParam">
        SELECT
          <include refid="systemParamColumns"/>
        FROM kf_system_param a
          <include refid="systemParamJoins"/>
        WHERE a.id = #{id}
    </select>
    
    <select id="findList" resultType="KfSystemParam">
        SELECT
          <include refid="systemParamColumns"/>
        FROM kf_system_param a
        <include refid="systemParamJoins"/>
        WHERE a.del_flag = #{DEL_FLAG_NORMAL}
        <if test="name != null and name != ''">
            AND a.name LIKE CONCAT('%', #{name}, '%')
        </if>
        ORDER BY a.id DESC
    </select>

12.字型庫
http://fontawesome.io/icons/

13.jquery獲取值
https://www.cnblogs.com/xiaolinxi/p/5179086.html
https://www.cnblogs.com/aiqingqing/p/5048854.html

14.未知
http://blog.csdn.net/mrw456/article/details/50408649
https://www.cnblogs.com/ranzige/p/4258549.html
http://www.wufangbo.com/jquery-validation/
https://jqueryvalidation.org/documentation/
https://jqueryvalidation.org/validate/

15.Mustache.js
http://blog.csdn.net/xuemoyao/article/details/17896203
http://blog.sina.com.cn/s/blog_a18312650101iygw.html
基本用法

<script type="text/template" id="collectionTpl">
	{{row.引數}}
	{{#row.引數}}
	有值時顯示
	{{/row.引數}}
	{{^row.引數}}
	無值時顯示
	{{/row.引數}}
</script>

js:

 var tpl = $("#collectionTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");//替換空格和換行
 $.each(response.data,function() {
     $("#work-List").append(Mustache.render(tpl, {
         row: this
     }));
 })

16.獲取最新插入資料的id

<insert id="insert" parameterType="KfCustomerSystem" useGeneratedKeys="true" keyProperty="id">
		<selectKey resultType="string" keyProperty="id" order="AFTER" >
			SELECT LAST_INSERT_ID() AS id
		</selectKey>
		insert into kf_customer_system (
				name
			)values(
				#{name}
			)
	</insert>

或:

<insert id="insert"  useGeneratedKeys="true" keyProperty="id" parameterType="KfNotification"></insesrt>

17.獲取以某字串開頭的id

$("li[id^='customerSystemWater_']").attr("id");

18.獲取包含某字串開頭的id(沒測過)
tr包含cell的id

$('tr[id*="cell"]');

tr以cell開關的id

	$('tr[id^="cell"]');

tr以cell結尾的id

	 $("tr[id$='cell']);

19.模態框關閉事件 模態框id

$('#customer-system-modal').on('hide.bs.modal', function () {
alert('嘿,我聽說您喜歡模態框...');
})
//模態框開啟事件
$('#customer-system-modal').on('show.bs.modal', function () {
alert('嘿,我聽說您喜歡模態框...');
})

20.模態框上加style="z-index:111111"防止被其他模態框覆蓋

21.判斷是不是數字

int id = 0;
Pattern pattern = Pattern.compile("[0-9]*");
Matcher isNum = pattern.matcher(kfWaterAlarm.getId());
if( !isNum.matches() ){
   System.out.print("false");
}else{
   System.out.print("true");
}

22.jsp 定義物件

var content = new Array();content.push(arry);

controller接收:

String jsonStr = pd.getString("content");
JSONArray jsonArray = JSONArray.fromObject(jsonStr);
     for(int i = 0 ; i < jsonArray.size() ; i++){
		  JSONObject obj = (JSONObject) jsonArray.get(i);
		  obj.getString("id")
	 }

23.jstl 陣列大小

${fn:length(viewList)-1}

24.Java讀取properties(請忽略這條,該條錯誤)

@Value("${adminPath}")
protected String adminPath;

25.chosen(select 控制元件)解決ajax 不能賦值問題

$("#subclientSelect").trigger("liszt:updated"); 

26.

$.contains();比較標籤
:contains();判斷包含的指定字串

例如:

//不包含
$("p:not(:contains(is))").css("background-color","yellow");
//包含
$("p:contains(is)").css("background-color","yellow");

27.下載路徑(請忽略這條,該條錯誤)

 httpServletRequest.getRealPath("/")

28.實時監聽input的值變化

$("#search").bind("input propertychange",function(){});

29.mybatis 傳參 重點是@Param(“引數”)

 //java
 Public User selectUser(@param(“userName”)String name,@param(“userArea”)String area);
 //sql
 <select id=" selectUser" resultMap="BaseResultMap">
   select  *  from user_user_t   where user_name = #{userName,jdbcType=VARCHAR} and user_area=#{userArea,jdbcType=VARCHAR}
</select> 

30.jq 獲取整個標籤

//全部獲取(包含該標籤,內部內容)
$(this).prop("outerHTML")
//獲取該標籤內部內容
$(this).prop("innerHTML")

31.jquery on的繫結事件傳引數

var clickEven = [
	{id:"#water-effect-list1",class:".dict-water-effect",list:"#water-effect-list2"},
	{id:"#water-effect-list2",class:".dict-water-effect",list:"#water-effect-list1"},
	{id:"#water-quality-list1",class:".customer-water-quality",list:"#water-quality-list2"},
	{id:"#water-quality-list2",class:".customer-water-quality",list:"#water-quality-list1"},
	{id:"#online-item-list1",class:".customer-online-item",list:"#online-item-list2"},
	{id:"#online-item-list2",class:".customer-online-item",list:"#online-item-list1"},
	{id:"#system-chemical-list1",class:".customer-system-chemical",list:"#system-chemical-list2"},
	{id:"#system-chemical-list2",class:".customer-system-chemical",list:"#system-chemical-list1"}
];
for(var  i = 0 ; i < clickEven.length ; i++){
	$(document).on("click",clickEven[i].id +" "+clickEven[i].class,{list:clickEven[i].list},function(even){
		var str = $(this).prop("outerHTML");
		$(even.data.list).append(str);
		$(this).remove();
	})
}

32.mysql 對時間操作

select 
create_date
from 
kf_alarm_task 
where 
create_date
BETWEEN
date_add(now(), interval -1 day)//的到前一天的時間
AND
now()
//或
select date_add(now(), interval -1 day);

//查詢你某天一天之前
SELECT * FROM employee WHERE hire_date < '2000-1-1 11:11:11'

//距今大於24小時
WHERE 
HOUR(timediff(now(),a.create_date))> 24

//
select
*
from 
(
SELECT
a.id,
a.task_id as taskId,
a.task_status,
a.remarks,
a.create_by AS "createBy.id",
max(a.create_date) as "create_date",
u.name AS "userName",
a.flag,
u.name AS "createBy.name"
FROM kf_task_process a
Left JOIN sys_user u ON u.id = a.create_by
where a.task_status in ('0','1','2')
GROUP BY a.task_id
) as b
where
HOUR(timediff(now(),b.create_date))> 24

33.字串拼接

Java :StringBuffer
jquery :?.concat(?,?)

34.bind 和on的區別
http://blog.csdn.net/aitangyong/article/details/43673535

35.設定點選時間

var time = 0;
$('button').click(function() {
    //判斷計時器是否處於關閉狀態
    if (time == 0) {
        time = 10; //設定間隔時間(秒)
 
        //啟動計時器,倒計時time秒後自動關閉計時器。
        var index = setInterval(function(){
            time--;
            if (time == 0) {
                clearInterval(index);
            }
        }, 1000);
 
        alert('按鈕事件被觸發');
    }else{
        alert('目前按鈕事件不允許被觸發');
    }
});

36.

<!-- 插入使用者和角色關聯表資料 -->
	<insert id="insertUserRole">
		INSERT INTO sys_user_role(user_id, role_id)
		<foreach collection="roleList" item="role" separator=" union all ">
			SELECT #{id}, #{role.id}
			<if test="dbName != 'mssql'">
			FROM dual
			</if>
		</foreach>
	</insert>

37.query 全面不替換
1.例如:var a=‘12,13,14,15’;現在想把字串替換,號為-
我們發現,jquery中的replace方法:a.replace(",","-");只能替換掉第一個,號。即,結果為12-13,14,15
jquery中是沒有對字串進行replaceAll的方法,通常這個時候,全部替換採用正則表示式的方式替換。如下:

var reg = new RegExp(",","g");//g,表示全部替換。
a.replace(reg,"-");
//結果:12-13-14-15
var str='aabbccaa';
var reg=/aa/g;
str=str.replace(reg,'dd');
//結果是 str='ddbbccdd'

38.select 事件

<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("input").select(function(){
    $("input").after(" Text marked!");
  });
});
</script>

<input type="text" name="FirstName" value="Hello World" />
<p>請試著選取輸入域中的文字,看看會發生什麼。</p>

38.mysql in查詢時 賦值時用${},不能用#{}

39.html 快取的用法

(1)這個寫法可能會不對
//賦值
function cl(msg){
	if(window.localStorage){
		localStorage.setItem("usermsg",msg);
	}else{
		Cookie.write("usermsg",msg);
	}
}
//取值
var str = window.localStorage?localStorage.getItem("usermsg"):Cookie.read("usermsg");

(2)這個親測有效

if(window.localStorage){
	localStorage.setItem("usermsg",JSON.stringify(response.data));
}else{
	Cookie.write("usermsg",JSON.stringify(response.data));
}
var str = window.localStorage?localStorage.getItem("usermsg"):Cookie.read("usermsg");
console.log(JSON.parse(str));//轉化成json

40.spring-boot啟動類 讀取配置檔案
https://blog.csdn.net/gaolu/article/details/52708177

41.net.sf.json Maven依賴配置

<dependency>    
    <groupId>net.sf.json-lib</groupId>    
    <artifactId>json-lib</artifactId>    
    <version>2.4</version>    
    <classifier>jdk15</classifier>//不帶這個會報錯    
</dependency>  

42.tomcat 啟動war server.xml < host >< /host>節點下加入

<Context  path ="chapter-05"  reloadable ="false"  docBase ="F:/GS.war"  workDir ="F:/GS"  />

(主意:war包要加副檔名,之前就是因為這個問題搞了兩個鐘頭,網上的都是胡說八道,TNND)
43.MySql開啟遠端訪問
https://blog.csdn.net/bingjianit/article/details/54384299
先說說這個錯誤,其實就是我們的MySQL不允許遠端登入,所以遠端登入失敗了,解決方法如下:

在裝有MySQL的機器上登入MySQL mysql -u root -p密碼
執行use mysql;
執行update user set host = ‘%’ where user = ‘root’;這一句執行完可能會報錯,不用管它。
執行FLUSH PRIVILEGES;

經過上面4步,就可以解決這個問題了。
注: 第四步是重新整理MySQL的許可權相關表,一定不要忘了,我第一次的時候沒有執行第四步,結果一直不成功,最後才找到這個原因。

44.sql 行列互換
https://blog.csdn.net/jackfrued/article/details/45021897

45.springBoot maven 打包jar報錯
出現這個問題主要是因為打包package遇到test會衝突(衝突解釋不準確),在打包的時候跳過test就可以了

mvn package -DskipTests

46

       select
		  	a.kfCustomerSystemWaterName,
			a.kfCustomerSystemWaterQualityId,
		<foreach collection="list" index="index" item="item" open="" separator="," close="">
			(case when a.kfSystemWaterQualityName = #{item} then a.kfcsWaterQualityReal end) as #{item}
		</foreach>
        from
		(select
			b.id,
			d.id as "kfCustomerSystemWaterId",
			d.name as "kfCustomerSystemWaterName",
			c.id as "kfCustomerSystemWaterQualityId",
			f.`name` as "kfSystemWaterQualityName",
			g.real as "kfcsWaterQualityReal"
		from kf_weekly_water_quality a
		left join kf_weekly b on a.weekly_id = b.id
		LEFT join kf_weekly_template_water_quality c on a.weekly_template_water_quality_id = c.id
		left join kf_customer_system_water d on c.customer_system_water_id = d.id
		left join kf_customer_water_quality e on c.customer_system_water_quality_id = e.id
		LEFT JOIN kf_water_quality f on e.water_quality_id = f.id
		left join kfcs_water_quality g on e.id = g.customer_system_water_quality_id) as a

shadowsocket免費賬號分享
地址一: