1. ssh 或 ssm 架構中,若自定義 filter 中 須要 調用 spring 容器中的對象,能夠在filter 中 直接 使用 spring 註解 將 屬性注入進來嗎?爲何?javascript
答: (1): 不能夠,由於 filter 是在web.xml中聲明的,屬於服務器的,不在spring容器中,因此不能從spring容器中調用bean。java
具體作法是: 使用 request對象獲得 ServletContext (整個web應用上下文), 再用 ServletContext 獲得 spring 容器,例如:node
WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext()); PermissionCheck pc = (PermissionCheck)applicationContext.getBean("permissionCheck");
實例爲: 稅務系統(itcastTax)中 LoginFilter.javaweb
2. 開發一個web應用時,若是數據庫的配置文件是統一放在pc某一個位置,此時如何 鏈接 數據庫,就像在蘭州電信同樣。ajax
3. 要實現用戶註冊功能,服務須要發佈 註冊 功能,還須要發佈什麼?spring
答: 還須要發佈 當前 註冊用戶是否已存在 的驗證 功能。數據庫
4. 在實現 導出文件時,在頁面上應該怎麼作?json
答:導出文件 時,應該 使用 window.open(「url」)方法 或者 的 href屬性 向服務端發送連接springboot
例如:服務器
<input type="button" value="導出" class="s_button" onclick="doExportExcel()"/>; function doExportExcel(){ window.open("${basePath}nsfw/user_exportExcel.action"); }
代碼位置: /itcastTax/WebRoot/WEB-INF/jsp/nsfw/user/listUI.jsp
5. 在一個表單中使用富文本編輯器,提交表單以前須要幹什麼?
答: 須要將富文本編輯器中的內容 同步 到 textarea 中,而後調用 form.serialize() 方法,提交。
<div style="padding:10px 10px 10px 10px"> <form id="itemAddForm" class="itemForm" method="post"> <table cellpadding="5"> <tr> <td>商品類目:</td> <td> <a href="javascript:void(0)" class="easyui-linkbutton selectItemCat">選擇類目</a> <input type="hidden" name="cid" style="width: 280px;"></input> </td> </tr> <tr> <td>商品標題:</td> <td><input class="easyui-textbox" type="text" name="title" data-options="required:true" style="width: 280px;"></input></td> </tr> <tr> <td>商品賣點:</td> <td><input class="easyui-textbox" name="sellPoint" data-options="multiline:true,validType:'length[0,150]'" style="height:60px;width: 280px;"></input></td> </tr> <tr> <td>商品價格:</td> <td><input class="easyui-numberbox" type="text" name="priceView" data-options="min:1,max:99999999,precision:2,required:true" /> <input type="hidden" name="price"/> </td> </tr> <tr> <td>庫存數量:</td> <td><input class="easyui-numberbox" type="text" name="num" data-options="min:1,max:99999999,precision:0,required:true" /></td> </tr> <tr> <td>條形碼:</td> <td> <input class="easyui-textbox" type="text" name="barcode" data-options="validType:'length[1,30]'" /> </td> </tr> <tr> <td>商品圖片:</td> <td> <a href="javascript:void(0)" class="easyui-linkbutton picFileUpload">上傳圖片</a> <input type="hidden" name="image"/> </td> </tr> <tr> <td>商品描述:</td> <td> <textarea style="width:800px;height:300px;visibility:hidden;" name="desc"></textarea> </td> </tr> <tr class="params hide"> <td>商品規格:</td> <td> </td> </tr> </table> <input type="hidden" name="itemParams"/> </form> <div style="padding:5px"> <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()">提交</a> <a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()">重置</a> </div> </div> <script type="text/javascript"> var itemAddEditor ; //頁面初始化完畢後執行此方法 $(function(){ //建立富文本編輯器 //itemAddEditor = TAOTAO.createEditor("#itemAddForm [name=desc]"); itemAddEditor = KindEditor.create("#itemAddForm [name=desc]", TT.kingEditorParams); //初始化類目選擇和圖片上傳器 TAOTAO.init({fun:function(node){ //根據商品的分類id取商品 的規格模板,生成規格信息。第四天內容。 TAOTAO.changeItemParam(node, "itemAddForm"); }}); }); //提交表單 function submitForm(){ //有效性驗證 if(!$('#itemAddForm').form('validate')){ $.messager.alert('提示','表單還未填寫完成!'); return ; } //取商品價格,單位爲「分」 $("#itemAddForm [name=price]").val(eval($("#itemAddForm [name=priceView]").val()) * 100); //同步文本框中的商品描述 itemAddEditor.sync(); //取商品的規格 var paramJson = []; $("#itemAddForm .params li").each(function(i,e){ var trs = $(e).find("tr"); var group = trs.eq(0).text(); var ps = []; for(var i = 1;i<trs.length;i++){ var tr = trs.eq(i); ps.push({ "k" : $.trim(tr.find("td").eq(0).find("span").text()), "v" : $.trim(tr.find("input").val()) }); } paramJson.push({ "group" : group, "params": ps }); }); //把json對象轉換成字符串 paramJson = JSON.stringify(paramJson); $("#itemAddForm [name=itemParams]").val(paramJson); //ajax的post方式提交表單 //$("#itemAddForm").serialize()將表單序列號爲key-value形式的字符串 $.post("/item/save",$("#itemAddForm").serialize(), function(data){ if(data.status == 200){ $.messager.alert('提示','新增商品成功!'); } }); }
5. springboot 項目中 啓動器 是否能夠和 cotroller 位於 同一包中?
答: 能夠 啓動類 必須與cotroller 在 同一包或 上級包 不能 在 平級或者 下級目錄