<address id="ttjl9"></address>

      <noframes id="ttjl9"><address id="ttjl9"><nobr id="ttjl9"></nobr></address>
      <form id="ttjl9"></form>
        <em id="ttjl9"><span id="ttjl9"></span></em>
        <address id="ttjl9"></address>

          <noframes id="ttjl9"><form id="ttjl9"></form>

          首頁

          PM2托管工具使用詳解

          前端達人

          參考 pm2從入門到精通
          服務器上的項目需要保持穩定,即使發生故障項目也要自動重啟以提供服務,這時需要托管工具對我們的項目進行托管。PM2正是這樣一款工具,可以利用它來簡化很多node應用管理的繁瑣任務,如性能監控、自動重啟、負載均衡等,而且使用非常簡單。

          安裝pm2
          $ npm install -g pm2 
          
          • 1
          啟動應用
          $ pm2 start app.js  (--watch)  # 加上watch參數后可以實時修改代碼 
          
          • 1
          管理進程
          $ pm2 list 
          
          • 1
          停止應用
          $ pm2 stop <app name> 
          
          • 1
          重啟應用
          $ pm2 restart <app name> 
          
          • 1
          刪除應用
          $ pm2 delete <app name> 
          
          • 1
          顯示某個應用程序的日志
          $ pm2 logs <app name> 
          
          • 1
          顯示所有應用程序的日志

          $ pm2 logs


          藍藍設計www.syprn.cn )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 平面設計服務


          文章來源:網絡某處。
          分享此文一切功德,皆悉回向給文章原作者及眾讀者.
          免責聲明:藍藍設計尊重原作者,文章的版權歸原作者。如涉及版權問題,請及時與我們取得聯系,我們立即更正或刪除。


          js 時間戳轉為日期格式

          前端達人

          什么是Unix時間戳(Unix timestamp): Unix時間戳(Unix timestamp),或稱Unix時間(Unix time)、POSIX時間(POSIX time),是一種時間表示方式,定義為從格林威治時間1970年01月01日00時00分00秒起至現在的總秒數。Unix時間戳不僅被使用在Unix系統、類Unix系統中,也在許多其他操作系統中被廣泛采用。

          目前相當一部分操作系統使用32位二進制數字表示時間。此類系統的Unix時間戳最多可以使用到格林威治時間2038年01月19日03時14分07秒(二進制:01111111 11111111 11111111 11111111)。其后一秒,二進制數字會變為10000000 00000000 00000000 00000000,發生溢出錯誤,造成系統將時間誤解為1901年12月13日20時45分52秒。這很可能會引起軟件故障,甚至是系統癱瘓。使用64位二進制數字表示時間的系統(最多可以使用到格林威治時間292,277,026,596年12月04日15時30分08秒)則基本不會遇到這類溢出問題。

          一.js將時間轉換成時間戳

          1.js獲取當前時間戳的方法

          var timestamp1 = Date.parse(new Date());
          var timestamp2 = (new Date()).valueOf();
          var timestamp3 = new Date().getTime();

          第一種:獲取的時間戳是把毫秒改成000顯示,第二種和第三種是獲取了當前毫秒的時間戳。

          2.js獲取制定時間戳的方法

          var oldTime = (new Date("2015/06/23 08:00:20")).getTime()/1000;

          getTime()返回數值的單位是毫秒。

          演示

          二.js把時間戳轉為為普通日期格式

          1.Date toLocaleStdding方法

          function getLocalTime(nS) { return new Date(parseInt(nS) * 1000).toLocaleStdding().replace(/:\d{1,2}$/,' ');     
          }

          parseInt() 函數可解析一個字符串,并返回一個整數。

          js中時間操作單位是毫秒。

          toLocaleStdding() 方法可根據本地時間把 Date 對象轉換為字符串,并返回結果。

          replace() 方法用于在字符串中用一些字符替換另一些字符,或替換一個與正則表達式匹配的子串。

          replace(/:\d{1,2}$/,' ')驗證替換以:開始有一位或二位數字的結束字符串,就是秒;替換為空

          顯示如下:

          image

          演示

          所以我們可以利用正則表達式改變我們想要的日期格式。

          2.Date 屬性方法

          復制代碼
          復制代碼
          function add0(m){return m<10?'0'+m:m } function format(shijianchuo)
          { //shijianchuo是整數,否則要parseInt轉換 var time = new Date(shijianchuo); var y = time.getFullYear(); var m = time.getMonth()+1; var d = time.getddate(); var h = time.getHours(); var mm = time.getMinutes(); var s = time.getSeconds(); return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s);
          }
          復制代碼
          復制代碼

          image

          演示





          藍藍設計www.syprn.cn )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 平面設計服務


          文章來源:網絡某處。
          分享此文一切功德,皆悉回向給文章原作者及眾讀者.
          免責聲明:藍藍設計尊重原作者,文章的版權歸原作者。如涉及版權問題,請及時與我們取得聯系,我們立即更正或刪除。






          用css實現文字抖動特效

          前端達人

          html:<span class="shaky">你在說什么( ,,′?ω?)?"(′っω?`?)</span>

          css:.shaky { display: inline-block; padding: 1px; font-size: 12px; -webkit-transform-origin: center center; -ms-transform-origin: center center; transform-origin: center center; -webkit-animation-name: shaky-slow; -ms-animation-name: shaky-slow; animation-name: shaky-slow; -webkit-animation-duration: 4s; -ms-animation-duration: 4s; animation-duration: 4s; -webkit-animation-iteration-count: infinite; -ms-animation-iteration-count: infinite; animation-iteration-count: infinite; -webkit-animation-timing-function: ease-in-out; -ms-animation-timing-function: ease-in-out; animation-timing-function: ease-in-out; -webkit-animation-delay: 0s; -ms-animation-delay: 0s; animation-delay: 0s; -webkit-animation-play-state: running; -ms-animation-play-state: running; animation-play-state: running; } @-webkit-keyframes shaky-slow { 0% { -webkit-transform: translate(0px, 0px) rotate(0deg) } 2% { -webkit-transform: translate(-1px, 1.5px) rotate(1.5deg) } 4% { -webkit-transform: translate(1.3px, 0px) rotate(-0.5deg) } 6% { -webkit-transform: translate(1.4px, 1.4px) rotate(-2deg) } 8% { -webkit-transform: translate(-1.3px, -1px) rotate(-1.5deg) } 10% { -webkit-transform: translate(1.4px, 0px) rotate(-2deg) } 12% { -webkit-transform: translate(-1.3px, -1px) rotate(-2deg) } 14% { -webkit-transform: translate(1.5px, 1.3px) rotate(1.5deg) } 16% { -webkit-transform: translate(1.5px, -1.5px) rotate(-1.5deg) } 18% { -webkit-transform: translate(1.3px, -1.3px) rotate(-2deg) } 20% { -webkit-transform: translate(1px, 1px) rotate(-0.5deg) } 22% { -webkit-transform: translate(1.3px, 1.5px) rotate(-2deg) } 24% { -webkit-transform: translate(-1.4px, -1px) rotate(2deg) } 26% { -webkit-transform: translate(1.3px, -1.3px) rotate(0.5deg) } 28% { -webkit-transform: translate(1.6px, -1.6px) rotate(-2deg) } 30% { -webkit-transform: translate(-1.3px, -1.3px) rotate(-1.5deg) } 32% { -webkit-transform: translate(-1px, 0px) rotate(2deg) } 34% { -webkit-transform: translate(1.3px, 1.3px) rotate(-0.5deg) } 36% { -webkit-transform: translate(1.3px, 1.6px) rotate(1.5deg) } 38% { -webkit-transform: translate(1.3px, -1.6px) rotate(1.5deg) } 40% { -webkit-transform: translate(-1.4px, -1px) rotate(-0.5deg) } 42% { -webkit-transform: translate(-1.4px, 1.3px) rotate(-0.5deg) } 44% { -webkit-transform: translate(-1.6px, 1.4px) rotate(0.5deg) } 46% { -webkit-transform: translate(-2.1px, -1.3px) rotate(-0.5deg) } 48% { -webkit-transform: translate(1px, 1.6px) rotate(1.5deg) } 50% { -webkit-transform: translate(1.6px, 1.6px) rotate(1.5deg) } 52% { -webkit-transform: translate(-1.4px, 1.6px) rotate(0.5deg) } 54% { -webkit-transform: translate(1.6px, -1px) rotate(-2deg) } 56% { -webkit-transform: translate(1.3px, -1.6px) rotate(-2deg) } 58% { -webkit-transform: translate(-1.3px, -1.6px) rotate(0.5deg) } 60% { -webkit-transform: translate(1.3px, 1.6px) rotate(-0.5deg) } 62% { -webkit-transform: translate(0px, 0px) rotate(-1.5deg) } 64% { -webkit-transform: translate(-1.6px, -1.6px) rotate(-2deg) } 66% { -webkit-transform: translate(1.6px, -1.6px) rotate(0.5deg) } 68% { -webkit-transform: translate(0px, -1.6px) rotate(-2deg) } 70% { -webkit-transform: translate(-1.6px, 1px) rotate(1.5deg) } 72% { -webkit-transform: translate(-1.6px, 1.6px) rotate(2deg) } 74% { -webkit-transform: translate(1.3px, -1.6px) rotate(-0.5deg) } 76% { -webkit-transform: translate(1.4px, 1px) rotate(-0.5deg) } 78% { -webkit-transform: translate(-1px, 1.4px) rotate(2deg) } 80% { -webkit-transform: translate(1.4px, 1.6px) rotate(2deg) } 82% { -webkit-transform: translate(-1.6px, -1.6px) rotate(-0.5deg) } 84% { -webkit-transform: translate(-1.4px, 1.4px) rotate(-2deg) } 86% { -webkit-transform: translate(1px, 1.4px) rotate(-2deg) } 88% { -webkit-transform: translate(-1.4px, 1.4px) rotate(-1.5deg) } 90% { -webkit-transform: translate(-1.6px, -1.6px) rotate(-2deg) } 92% { -webkit-transform: translate(-1.6px, 1.6px) rotate(2deg) } 94% { -webkit-transform: translate(-1.6px, -1.6px) rotate(-2deg) } 96% { -webkit-transform: translate(-1.4px, 1.3px) rotate(-2deg) } 98% { -webkit-transform: translate(1.3px, 1px) rotate(-0.5deg) } } @keyframes shaky-slow { 0% { transform: translate(0px, 0px) rotate(0deg) } 2% { transform: translate(-1px, 1.5px) rotate(1.5deg) } 4% { transform: translate(1.3px, 0px) rotate(-0.5deg) } 6% { transform: translate(1.4px, 1.4px) rotate(-2deg) } 8% { transform: translate(-1.3px, -1px) rotate(-1.5deg) } 10% { transform: translate(1.4px, 0px) rotate(-2deg) } 12% { transform: translate(-1.3px, -1px) rotate(-2deg) } 14% { transform: translate(1.5px, 1.3px) rotate(1.5deg) } 16% { transform: translate(1.5px, -1.5px) rotate(-1.5deg) } 18% { transform: translate(1.3px, -1.3px) rotate(-2deg) } 20% { transform: translate(1px, 1px) rotate(-0.5deg) } 22% { transform: translate(1.3px, 1.5px) rotate(-2deg) } 24% { transform: translate(-1.4px, -1px) rotate(2deg) } 26% { transform: translate(1.3px, -1.3px) rotate(0.5deg) } 28% { transform: translate(1.6px, -1.6px) rotate(-1.5deg) } 30% { transform: translate(-1.3px, -1.3px) rotate(-1.5deg) } 32% { transform: translate(-1px, 0px) rotate(2deg) } 34% { transform: translate(1.3px, 1.3px) rotate(-0.5deg) } 36% { transform: translate(1.3px, 1.6px) rotate(1.5deg) } 38% { transform: translate(1.3px, -1.6px) rotate(1.5deg) } 40% { transform: translate(-1.4px, -1px) rotate(-0.5deg) } 42% { transform: translate(-1.4px, 1.3px) rotate(-0.5deg) } 44% { transform: translate(-1.6px, 1.4px) rotate(0.5deg) } 46% { transform: translate(-2.1px, -1.3px) rotate(-0.5deg) } 48% { transform: translate(1px, 1.6px) rotate(1.5deg) } 50% { transform: translate(1.6px, 1.6px) rotate(1.5deg) } 52% { transform: translate(-1.4px, 1.6px) rotate(0.5deg) } 54% { transform: translate(1.6px, -1px) rotate(-2deg) } 56% { transform: translate(1.3px, -1.6px) rotate(-2deg) } 58% { transform: translate(-1.3px, -1.6px) rotate(0.5deg) } 60% { transform: translate(1.3px, 1.6px) rotate(-0.5deg) } 62% { transform: translate(0px, 0px) rotate(-1.5deg) } 64% { transform: translate(-1.6px, -1.6px) rotate(-2deg) } 66% { transform: translate(1.6px, -1.6px) rotate(0.5deg) } 68% { transform: translate(0px, -1.6px) rotate(-2deg) } 70% { transform: translate(-1.6px, 1px) rotate(1.5deg) } 72% { transform: translate(-1.6px, 1.6px) rotate(2deg) } 74% { transform: translate(1.3px, -1.6px) rotate(-0.5deg) } 76% { transform: translate(1.4px, 1px) rotate(-0.5deg) } 78% { transform: translate(-1px, 1.4px) rotate(2deg) } 80% { transform: translate(1.4px, 1.6px) rotate(2deg) } 82% { transform: translate(-1.6px, -1.6px) rotate(-0.5deg) } 84% { transform: translate(-1.4px, 1.4px) rotate(-2deg) } 86% { transform: translate(1px, 1.4px) rotate(-2deg) } 88% { transform: translate(-1.4px, 1.4px) rotate(-1.5deg) } 90% { transform: translate(-1.6px, -1.6px) rotate(-2deg) } 92% { transform: translate(-1.4px, 1.6px) rotate(2deg) } 94% { transform: translate(-1.6px, -1.6px) rotate(-2deg) } 96% { transform: translate(-1.4px, 1.3px) rotate(-2deg) } 98% { transform: translate(1.3px, 1px) rotate(-0.5deg) } }



          藍藍設計www.syprn.cn )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 、平面設計服務


          文章來源:網絡某處。
          分享此文一切功德,皆悉回向給文章原作者及眾讀者.
          免責聲明:藍藍設計尊重原作者,文章的版權歸原作者。如涉及版權問題,請及時與我們取得聯系,我們立即更正或刪除。



          Linux CentOS + Nodejs + Express部署vue項目

          前端達人

          注:服務器為CentOS 7.3.1611,使用Xshell6 + Xftp6工具完成服務器遠程操作

          一、安裝Node環境

          通過Xshell連接服務器成功之后就可以開始以下工作

          1.清理工作

          如果之前有安裝過nodejs,用自帶的包管理命名先刪除一次
          yum remove nodejs npm -y 
          
          • 1

          然后手動進入以下目錄刪除相關文件
          進入 /usr/local/lib 刪除所有 node 和 node_modules文件夾
          進入 /usr/local/include 刪除所有 node 和 node_modules 文件夾
          進入 /usr/local/bin 刪除 node 的可執行文件

          2.去官網復制node安裝包鏈接

          https://nodejs.org/en/download/在這里插入圖片描述

          3.在Xshell里cd到安裝目錄

          cd /usr/local/ 
          
          • 1

          4.輸入命令鏈接開始下載nodejs安裝包

          wget https://nodejs.org/dist/v10.16.0/node-v10.16.0-linux-x64.tar.xz 
          
          • 1

          5.輸入命令兩步解壓

          xz -d node-v10.16.0-linux-x64.tar.xz
          tar -xvf node-v10.16.0-linux-x64.tar 
          
          • 1
          • 2

          6.重名解壓的文件夾名稱為nodejs

          mv node-v10.16.0-linux-x64 nodejs 
          
          • 1

          7.進入解壓目錄

          cd nodejs 
          
          • 1

          8.創建軟連接

          ln -s /usr/local/nodejs/bin/node /usr/local/bin/node
          ln -s /usr/local/nodejs/bin/npm /usr/local/bin/npm 
          
          • 1
          • 2

          如果不小心輸錯了路徑,重新創建會提示:‘ln: 無法創建符號鏈接"/usr/local/bin/npm": 文件已存在’,輸入rm /usr/local/bin/npm命令清除后可以重新創建

          9.測試

          node -v
          npm -v 
          
          • 1
          • 2

          10.安裝cnpm淘寶鏡像并創建軟鏈接

          npm install -g cnpm
          ln -s /usr/local/nodejs/bin/cnpm /usr/local/bin/cnpm 
          
          • 1
          • 2

          二、用Express搭建web服務

          1.在Xshell里cd到指定目錄

          cd /var/www/ 
          
          • 1

          注:如果沒有www目錄就在var目錄下輸入命令mkdir www手動創建一個,并進入到www目錄

          2.創建web服務項目文件夾

          mkdir demo 
          
          • 1

          3.cd進入項目目錄

          cd demo 
          
          • 1

          4.初始化項目生成package.json

          npm init -y 
          
          • 1

          注:這里的-y意思是省略創建過程中一直輸yes的步驟

          5.安裝express

          cnpm i express -D 
          
          • 1

          6.創建web服務程序文件app.js

          mkdir app.js 
          
          • 1

          7.編寫web服務程序代碼app.js

          const fs = require('fs'); //文件模塊 const path = require('path'); //路徑模塊 const express = require('express'); //express框架模塊 const app = express(); const hostName = '11.22.33.44'; //ip const port = 9999; //端口 app.use(express.static(path.resolve(__dirname, './dist'))); // 設置靜態項目訪問路徑(此處的dist為webpack打包生成的項目文件夾名稱) app.get('*', function(req, res) { const html = fs.readFileSync(path.resolve(__dirname, './dist/index.html'), 'utf-8'); // 設置所有訪問服務請求默認返回index.html文件 res.send(html); }); app.listen(port, hostName, function() { console.log(`服務器運行在http://${hostName}:${port}`); }); 
          
          • 1
          • 2
          • 3
          • 4
          • 5
          • 6
          • 7
          • 8
          • 9
          • 10
          • 11
          • 12
          • 13
          • 14
          • 15
          • 16
          • 17
          • 18

          三、打包部署vue項目

          1.在本地開發工具里打包需要部署的vue項目

          npm run build 
          
          • 1

          生成的dist文件夾就是我們需要部署到服務器上的項目
          在這里插入圖片描述

          2.把dist文件夾通過Xftp工具復制到服務器的var/www/demo目錄下

          11160623264.png)

          四、啟動web服務

          1.在Xshell里cd到var/www/demo目錄,輸入以下命令啟動web服務程序

          node app.js 
          
          • 1

          如果能正常訪問項目地址表示已經搭建成功。

          請求后端接口跨域方案請見:
          跨域代理方案1Nginx使用教程
          跨域代理方案2Nodejs 中使用http-proxy-middleware實現代理跨域

          2.安裝PM2托管Node Web服務程序

          在xshell里用node默認的啟動方式有一個缺點,xshell退出后nodejs項目便會停止
          使用pm2這個托管工具可以很好的解決這個問題,而且當代碼有更改時會自動重啟服務更新

          1.首先多按兩次ctrl +c結束之前的運行程序,接著輸入下面的命令安裝pm2并創建軟鏈接

          cnpm install pm2 -g
          ln -s /usr/local/nodejs/bin/pm2 /usr/local/bin/pm2 
          
          • 1
          • 2

          2.然后輸入下面的命令啟動托管任務,abc為托管項目定義的名稱

          pm2 start app.js --name abc 
          
          • 1

          以下為pm2常用命令說明

          命令 功能
          pm2 start app.js --name abc 啟動(--name為定義任務名稱的指令,abc為任務名稱值)
          pm2 start app.js --watch 啟動( --watch為監聽應用目錄的變化的指令)
          pm2 restart app.js 重啟任務
          pm2 stop abc 結束(abc為任務名稱或id)
          pm2 list 查看所有任務列表

          pm2基本功能命令

          功能 命令
          啟動進程/應用 pm2 start bin/abc 或 pm2 start app.js
          重命名進程/應用 pm2 start app.js --name abc
          添加進程/應用 pm2 start bin/abc --watch
          結束進程/應用 pm2 stop abc
          結束所有進程/應用 pm2 stop all
          刪除進程/應用 pm2 delete abc
          刪除所有進程/應用 pm2 delete all
          列出所有進程/應用 pm2 list
          查看進程/應用詳情 pm2 show abc 或 pm2 describe abc
          查看進程/應用資源消耗 pm2 monit
          查看進程/應用日志 pm2 logs abc
          查看所有進程/應用日志 pm2 logs
          重新啟動進程/應用 pm2 restart abc
          重新啟動所有進程/應用 pm2 restart all

          pm2使用教程參考鏈接:
          https://www.cnblogs.com/chyingp/p/pm2-documentation.html
          https://www.jb51.net/article/113398.htm



          轉自:csdn。作者:lihefei_coder



          藍藍設計www.syprn.cn )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 、平面設計服務



          詳談js防抖和節流

          前端達人

          本文由小芭樂發表

          0. 引入

          首先舉一個例子:

          模擬在輸入框輸入后做ajax查詢請求,沒有加入防抖和節流的效果,這里附上完整可執行代碼:

          <!DOCTYPE html> <html lang="en">  <head> <meta charset="UTF-8"> <title>沒有防抖</title> <style type="text/css"></style> <script type="text/javascript"> window.onload = function () { //模擬ajax請求  function ajax(content) { console.log('ajax request ' + content) } let inputNormal = document.getElementById('normal');  inputNormal.addEventListener('keyup', function (e) { ajax(e.target.value) }) } </script> </head>  <body> <div> 1.沒有防抖的輸入 <input type="text" name="normal" id="normal"> </div> </body>  </html> 

          效果:在輸入框里輸入一個,就會觸發一次“ajax請求”(此處是console)。


          沒有防抖和節流

          缺點:浪費請求資源,可以加入防抖和節流來優化一下。

          本文會分別介紹什么是防抖和節流,它們的應用場景,和實現方式。防抖和節流都是為了解決短時間內大量觸發某函數而導致的性能問題,比如觸發頻率過高導致的響應速度跟不上觸發頻率,出現延遲,假死或卡頓的現象。但二者應對的業務需求不一樣,所以實現的原理也不一樣,下面具體來看看吧。

          1. 防抖(debounce)

          1.1 什么是防抖

          在事件被觸發n秒后再執行回調函數,如果在這n秒內又被觸發,則重新計時。

          1.2 應用場景

          (1) 用戶在輸入框中連續輸入一串字符后,只會在輸入完后去執行最后一次的查詢ajax請求,這樣可以有效減少請求次數,節約請求資源;

          (2) window的resize、scroll事件,不斷地調整瀏覽器的窗口大小、或者滾動時會觸發對應事件,防抖讓其只觸發一次;

          1.3 實現

          還是上述列子,這里加入防抖來優化一下,完整代碼如下:

          <!DOCTYPE html> <html lang="en">  <head> <meta charset="UTF-8"> <title>加入防抖</title> <style type="text/css"></style> <script type="text/javascript"> window.onload = function () { //模擬ajax請求  function ajax(content) { console.log('ajax request ' + content) } function debounce(fun, delay) { return function (args) { //獲取函數的作用域和變量  let that = this let _args = args //每次事件被觸發,都會清除當前的timeer,然后重寫設置超時調用  clearTimeout(fun.id) fun.id = setTimeout(function () { fun.call(that, _args) }, delay) } } let inputDebounce = document.getElementById('debounce') let debounceAjax = debounce(ajax, 500) inputDebounce.addEventListener('keyup', function (e) { debounceAjax(e.target.value) }) } </script> </head>  <body> <div> 2.加入防抖后的輸入 <input type="text" name="debounce" id="debounce"> </div> </body>  </html> 

          代碼說明:

          1.每一次事件被觸發,都會清除當前的 timer 然后重新設置超時調用,即重新計時。 這就會導致每一次高頻事件都會取消前一次的超時調用,導致事件處理程序不能被觸發;

          2.只有當高頻事件停止,最后一次事件觸發的超時調用才能在delay時間后執行;

          效果:

          加入防抖后,當持續在輸入框里輸入時,并不會發送請求,只有當在指定時間間隔內沒有再輸入時,才會發送請求。如果先停止輸入,但是在指定間隔內又輸入,會重新觸發計時。


          加入防抖

          2.節流(throttle)

          2.1 什么是節流

          規定一個單位時間,在這個單位時間內,只能有一次觸發事件的回調函數執行,如果在同一個單位時間內某事件被觸發多次,只有一次能生效。

          2.2 應用場景

          (1)鼠標連續不斷地觸發某事件(如點擊),只在單位時間內只觸發一次;

          (2)在頁面的無限加載場景下,需要用戶在滾動頁面時,每隔一段時間發一次 ajax 請求,而不是在用戶停下滾動頁面操作時才去請求數據;

          (3)監聽滾動事件,比如是否滑到底部自動加載更多,用throttle來判斷;

          2.3 實現

          還是上述列子,這里加入節流來優化一下,完整代碼如下:

          <!DOCTYPE html> <html lang="en">  <head> <meta charset="UTF-8"> <title>加入節流</title> <style type="text/css"></style> <script type="text/javascript"> window.onload = function () { //模擬ajax請求  function ajax(content) { console.log('ajax request ' + content) }  function throttle(fun, delay) { let last, deferTimer return function (args) { let that = this; let _args = arguments;  let now = +new Date(); if (last && now < last + delay) { clearTimeout(deferTimer); deferTimer = setTimeout(function () { last = now; fun.apply(that, _args); }, delay) } else { last = now; fun.apply(that, _args); } } } let throttleAjax = throttle(ajax, 1000) let inputThrottle = document.getElementById('throttle') inputThrottle.addEventListener('keyup', function (e) { throttleAjax(e.target.value) }) } </script> </head>  <body> <div> 3.加入節流后的輸入 <input type="text" name="throttle" id="throttle"> </div> </body>  </html> 

          效果:實驗可發現在持續輸入時,會安裝代碼中的設定,每1秒執行一次ajax請求


          加入節流

          3. 小結

          總結下防抖和節流的區別:

          -- 效果:

          函數防抖是某一段時間內只執行一次;而函數節流是間隔時間執行,不管事件觸發有多頻繁,都會保證在規定時間內一定會執行一次真正的事件處理函數。

          -- 原理:

          防抖是維護一個計時器,規定在delay時間后觸發函數,但是在delay時間內再次觸發的話,都會清除當前的 timer 然后重新設置超時調用,即重新計時。這樣一來,只有最后一次操作能被觸發。

          節流是通過判斷是否到達一定時間來觸發函數,若沒到規定時間則使用計時器延后,而下一次事件則會重新設定計時器。

          如有問題,歡迎指正。


          轉自知乎  原文鏈接:https://zhuanlan.zhihu.com/p/51608574



          藍藍設計www.syprn.cn )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 平面設計服務

          app界面賞析 ——— 北京藍藍設計 移動端UI設計資源分享(二十二)

          前端達人

          App界面設計對于設計師而言一直是盛久不衰的話題,尤其是如今越來越多的流量轉移到了移動平臺,使得更多的UI設計師涌入移動端領域,甚至出現了市場飽和的言論,對于從事移動端的UI設計師來講,充滿壓力的同時又面臨無限機遇,唯有不斷的學習才能滋生出源源不斷的設計靈感,站穩腳跟。

          摹客想在這方面給各位設計師朋友做點什么,除了提供簡單好用的設計工具,我們也整理了非常多的優秀設計案例,希望可以對設計師朋友有借鑒意義。這將會是一個系列的專題,我們以月為單位,整理了國內外設計師的優秀APP界面設計案例,我們是搬運工,更是好設計的傳達者,希望你會喜歡。



          接下來為大家分享精美的app UI設計案例:


          jhk-1620273581216.jpgjhk-1620273582832.jpgjhk-1620273583463.jpgjhk-1620273584169.jpgjhk-1620273585641.jpgjhk-1620280329924.jpg





          --手機appUI設計--

          藍藍設計www.syprn.cn )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 、平面設計服



            更多精彩文章:

                手機appUI界面設計賞析(一)

                 手機appUI界面設計賞析(二)

                 手機appUI界面設計賞析(三)

                 手機appUI界面設計賞析(四)

                 手機appUI界面設計賞析(五)

                 手機appUI界面設計賞析(六)

                 手機appUI界面設計賞析(七)

                 手機appUI界面設計賞析(八)

                 手機appUI界面設計賞析(九)

                  手機appUI界面設計賞析(十)

                 手機appUI界面設計賞析(十一)

                手機appUI界面設計賞析(十二)

                手機appUI界面設計賞析(十三)

                手機appUI界面設計賞析(十四)

                手機appUI界面設計賞析(十五)

                手機appUI界面設計賞析(十六)

                手機appUI界面設計賞析(十七)

                手機appUI界面設計賞析(十八)

                手機appUI界面設計賞析(十九)

                手機appUI界面設計賞析(二十)

                手機appUI界面設計賞析(二十一)



          nginx下部署vue項目概覽

          前端達人

          今天要用到服務器nginx,還需要把自己的vue的項目部署到服務器上去所以就寫一下記錄下來。

          首先要去nginx官網下下載nginx:
          下載地址:https://nginx.org/en/download.html
          這里寫圖片描述

          下載下來會是一個解壓包,解壓到你想放的文件夾下

          這里寫圖片描述

          運行nginx.exe,然后打開瀏覽器輸入localhost出來如下圖片所示就說明成功了:

          這里寫圖片描述

          然后如果沒有成功出來的話也不要慌不要怕,可能是你的端口被別的內容所占了這時你就打開你的nginx的目錄下找到conf

          這里寫圖片描述

          點擊進去然后找到一個nginx.conf的文件

          這里寫圖片描述

          然后把它用編輯器的方式打開,打開之后找到這里的sever的listen就是你的端口號,默認的是80端口,你可以根據自己沒有被占用的端口進行改寫,改寫完成之后保存然后打開你的localhost:你改寫的端口號就OK了

           server {
                      listen       8088;
                      server_name  localhost;
          
                      #charset koi8-r;
          
                      #access_log  logs/host.access.log  main;
          
                      location / {
                          root   html;
                          index  index.html index.htm;
                  } 
          
          • 1
          • 2
          • 3
          • 4
          • 5
          • 6
          • 7
          • 8
          • 9
          • 10
          • 11
          • 12

          這里寫圖片描述

          上面是安裝配置nginx服務器的方法,下面就是如何把自己的vue項目部署到你所安裝配置的nginx服務器上的步驟了:

          首先找到自己的vue的項目然后輸入命令 npm run build 他會在你的vue目錄下生成一個dist文件夾里面就是你的vue的項目

          這里寫圖片描述

          然后打開這個dist文件夾把里面的內容復制下來里面會有兩個文件一個是index.html是主目錄還有一個是static文件夾

          這里寫圖片描述

          把他們復制下來然后打開你的nginx的目錄下的html文件里面會有兩個默認文件直接刪掉不要留,然后把你剛剛復制的文件粘貼進去

          這里寫圖片描述

          然后打開瀏覽器輸入最開始改的端口號localhost:你所改的端口號回車;你就會看到自己的vue的項目跑起來了我的打開就是這樣的咯:

          這里寫圖片描述

          這樣就大功告成了~~~~~~~~~


          轉自:csdn 作者:前端的搬運工 

          藍藍設計www.syprn.cn )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 、平面設計服務

          前端登錄流程

          前端達人

          前端登錄流程

          初次登錄的時候,前端調后調的登錄接口,發送用戶名和密碼,后端收到請求,驗證用戶名和密碼,驗證成功,就給前端返回一個token,和一個用戶信息的值,前端拿到token,將token儲存到Vuex中,然后從Vuex中把token的值存入瀏覽器Cookies中。把用戶信息存到Vuex然后再存儲到LocalStroage中
          Cookies
          在這里插入圖片描述
          LocalStroage
          在這里插入圖片描述
          在這里插入圖片描述
          然后跳轉到下一個頁面,根據后端接口的要求,只要不登錄就不能訪問的頁面需要在前端每次跳轉頁面師判斷Cookies中是否有token,沒有就跳轉到登錄頁,有就跳轉到相應的頁面,我們應該再每次發送post/get請求的時候應該加入token,常用方法再項目utils/service.js中添加全局攔截器,將token的值放入請求頭中
          在這里插入圖片描述
          后端判斷請求頭中有無token,有token,就拿到token并驗證token是否過期,在這里過期會返回無效的token然后有個跳回登錄頁面重新登錄并且清楚本地用戶的信息在這里插入圖片描述

          再全局攔截器中加代碼在這里插入圖片描述

          轉自:csdn 作者:mslmhl

          app界面賞析 ——— 北京藍藍設計 移動端UI設計資源分享(二十一)

          前端達人

          移動互聯網的迅速崛起,讓移動網頁,移動客戶端越來越重要,客戶端的頁面設計也是一門很大的學問??萍佳杆侔l展的今手機屏幕的尺寸越來越放大化,但卻始終 很有限,因此,在APP的界面設計中,精簡是一貫的準則。這里所說的精簡并不是內容上盡可能的少量,而是要注重重點的表達。在視覺上也要遵循用戶的視覺邏 輯,用戶看著順眼了,才會真正的喜歡。


          接下來為大家分享精美的app UI設計案例:


          jhk-1620273584169.jpgjhk-1620273585641.jpgjhk-1620273589355.jpgjhk-1620273592714.jpgjhk-1620273594998.jpgjhk-1620273606526.jpg



          --手機appUI設計--

          藍藍設計www.syprn.cn )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 平面設計服



            更多精彩文章:

                手機appUI界面設計賞析(一)

                 手機appUI界面設計賞析(二)

                 手機appUI界面設計賞析(三)

                 手機appUI界面設計賞析(四)

                 手機appUI界面設計賞析(五)

                 手機appUI界面設計賞析(六)

                 手機appUI界面設計賞析(七)

                 手機appUI界面設計賞析(八)

                 手機appUI界面設計賞析(九)

                  手機appUI界面設計賞析(十)

                 手機appUI界面設計賞析(十一)

                手機appUI界面設計賞析(十二)

                手機appUI界面設計賞析(十三)

                手機appUI界面設計賞析(十四)

                手機appUI界面設計賞析(十五)

                手機appUI界面設計賞析(十六)

                手機appUI界面設計賞析(十七)

                手機appUI界面設計賞析(十八)

                手機appUI界面設計賞析(十九)

                手機appUI界面設計賞析(二十)



          SSM框架實戰-搭建自己的個人博客1-基礎架構搭建

          前端達人

          前言

          本系列文章主要通過從零開始搭建自己的個人博客,來加深對SSM框架的學習與使用,了解一個系統從提出到設計-到開發-到測試-部署運行的過程,并記錄在搭建過程中的學習心得、遇見的錯誤及解決方式。

          個人博客的主要功能有:

          1. 博客列表展示:文章按照時間順序(時間倒序:最新最先展示)列表展示
          2. 博客文章詳情展示:展示文章全部內容,包含:作者、創建時間、所屬目錄、標簽、文章標題、內容
          3. 用戶權限管理:游客只能瀏覽文章、管理員可以發布文章、文章下線處理
          4. 添加文章功能:支持富文本編輯??梢哉{整字體大小、樣式、鍵入代碼等功能

          界面展示:

          前臺博客列表界面

          前臺博客列表頁面.png

          博客詳情頁面

          博客詳情頁面.png

          后臺管理頁面 

           

          登錄頁面

           

          后臺管理頁面.png

          項目技術簡介

          系統實現的功能點

          1. 用戶權限管理:普通的用戶(游客)只能瀏覽文章、管理員用戶可以發布文章、文章管理
          2. 博客列表展示:文章按照發布時間順序(按照時間倒敘)展示 :博客類別、標簽、博客名稱、作者名、發布時間、閱讀數量、博客的內容概括
          3. 博客詳情頁面:博客名稱、作者、時間、博客內容、標簽
          4. 博客后臺列表:博客檢索(類別、標簽、博客名稱)、博客列表(博客id、博客類別、標簽、時間)、博客操作
          5. 新增博客功能:支持富文本編輯:可以調整大小、樣式等

          服務端技術

          核心框架:Spring:5.2.8.RELEASE

          web框架:SpringMVC:5.2.8.RELEASE

          持久層框架:Mybatis 3.2.4

          數據庫連接池:阿里druid:0.2.6

          數據庫:MySQL5.XX

          JSON數據處理:谷歌gson 2.3

          前端技術

          jsp

          Ajax

          前端框架:bootstrap

          富文本編輯器:百度UEditor

          數據庫的設計

          • 用戶表:賬號id、賬號名稱、賬號密碼
          • 博客表:博客id、博客名稱、博客內容、發布時間、閱讀量、類別id、狀態
          • 博客/標簽對應表:博客id、標簽的id
          • 標簽表:標簽id、標簽名稱(博客和標簽:一對多:一個博客可以對應多個標簽)
          • 類別表:類別ID、類別名稱(博客和類別:一對一:一個博客對應一個類別)

          創建SQL語句:

           
          
          1. DROP TABLE IF EXISTS `t_article`;
          2. CREATE TABLE `t_article` (
          3. `id` int(11) NOT NULL AUTO_INCREMENT,
          4. `categoryId` int(11) NOT NULL COMMENT '分類Id',
          5. `title` varchar(40) NOT NULL COMMENT '標題',
          6. `content` blob NOT NULL COMMENT '內容',
          7. `description` varchar(500) NOT NULL COMMENT '文章簡介 用于列表顯示',
          8. `statue` int(11) NOT NULL DEFAULT '0' COMMENT '狀態 0:正常 1:不可用',
          9. `author` varchar(15) DEFAULT 'tulun' COMMENT '作者',
          10. `createTime` datetime NOT NULL COMMENT '發表時間',
          11. `showCount` int(11) NOT NULL DEFAULT '0' COMMENT '瀏覽量',
          12. PRIMARY KEY (`id`)
          13. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='文章表';
          14. -- ----------------------------
          15. -- Table structure for t_article_image
          16. -- ----------------------------
          17. DROP TABLE IF EXISTS `t_article_image`;
          18. CREATE TABLE `t_article_image` (
          19. `id` int(11) NOT NULL AUTO_INCREMENT,
          20. `imageUrl` varchar(100) NOT NULL COMMENT '圖片地址',
          21. `articleId` int(11) NOT NULL COMMENT '文章Id',
          22. PRIMARY KEY (`id`,`articleId`)
          23. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='文章圖 主要用于列表瀏覽';
          24. -- ----------------------------
          25. -- Table structure for t_tag
          26. -- ----------------------------
          27. DROP TABLE IF EXISTS `t_tag`;
          28. CREATE TABLE `t_tag` (
          29. `id` int(11) NOT NULL AUTO_INCREMENT,
          30. `tagName` varchar(25) NOT NULL COMMENT '標簽名稱 唯一',
          31. PRIMARY KEY (`id`),
          32. UNIQUE KEY `tagName_UNIQUE` (`tagName`)
          33. ) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8 COMMENT='標簽表';
          34. -- ----------------------------
          35. -- Table structure for t_article_tag
          36. -- ----------------------------
          37. DROP TABLE IF EXISTS `t_article_tag`;
          38. CREATE TABLE `t_article_tag` (
          39. `articleId` int(11) NOT NULL COMMENT '文章Id',
          40. `tagId` int(11) NOT NULL COMMENT '標簽Id',
          41. PRIMARY KEY (`articleId`,`tagId`)
          42. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='文章標簽中間表';
          43. -- ----------------------------
          44. -- Table structure for t_category
          45. -- ----------------------------
          46. DROP TABLE IF EXISTS `t_category`;
          47. CREATE TABLE `t_category` (
          48. `id` int(11) NOT NULL AUTO_INCREMENT,
          49. `categoryName` varchar(20) NOT NULL COMMENT '分類名稱 唯一',
          50. `iconClass` varchar(45) NOT NULL COMMENT '圖標樣式',
          51. `aliasName` varchar(20) NOT NULL COMMENT '別名 唯一 比如新聞 就用News 代替 欄目Id不顯示在url中',
          52. `sort` int(11) NOT NULL DEFAULT '0' COMMENT '排序 (0-10)',
          53. PRIMARY KEY (`id`),
          54. UNIQUE KEY `aliasName_UNIQUE` (`aliasName`),
          55. UNIQUE KEY `categoryName_UNIQUE` (`categoryName`)
          56. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='分類表 只支持一級分類 如果需要分多個層次 用標簽來協助實現';
          57. -- ----------------------------
          58. -- Table structure for t_manager
          59. -- ----------------------------
          60. DROP TABLE IF EXISTS `t_manager`;
          61. CREATE TABLE `t_manager` (
          62. `id` int(11) NOT NULL AUTO_INCREMENT,
          63. `userName` varchar(25) NOT NULL COMMENT '用戶名',
          64. `password` varchar(45) NOT NULL,
          65. PRIMARY KEY (`id`)
          66. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

          image.png

          框架結構搭建

          SSM項目腳手架搭建

          搭建如下框架結構:

          目錄說明:

           
          
          1. 目錄說明:
          2. |-src
          3. |--mian
          4. |---java JAVA源代碼根目錄
          5. |----com
          6. |-----tulun
          7. |------model 存放pogo類:基本基本的getter和setter方法
          8. |------controller 展示層類包路徑:前端用戶請求映射到該包路徑下類的實現
          9. |------service 業務邏輯層包路徑:業務邏輯實現,調用dao層服務
          10. |------dao 數據庫操作層包路徑:提供對數據庫的操作類與方法
          11. |------util 工具類包路徑
          12. |---resource 配置文件根目錄
          13. |----myatis mybatis接口對應配置文件目錄
          14. |----spring-XXX.xml SSM中mybatis、spring核心、springMVC的全局配置文件
          15. |--webapp 前端頁面內容根目錄
          16. |---WEB-INF
          17. |----web.xml 前端頁面必要配置文件
          18. |-pom.xml maven的配置文件

          測試Demo

          主要完成各個層之間的連接映射,完成從t_manager表中讀取數據并進行回顯

           

          POJO類

          根據數據庫表t_manager,創建User類

           
          
          1. package com.tulun.model;
          2. /**
          3. * Description :
          4. * Created by Resumebb
          5. * Date :2021/4/17
          6. */
          7. public class User {
          8. private Integer id;
          9. private String name;
          10. private String passwd;
          11. public Integer getId() {
          12. return id;
          13. }
          14. public void setId(Integer id) {
          15. this.id = id;
          16. }
          17. public String getName() {
          18. return name;
          19. }
          20. public void setName(String name) {
          21. this.name = name;
          22. }
          23. public String getPasswd() {
          24. return passwd;
          25. }
          26. public void setPasswd(String passwd) {
          27. this.passwd = passwd;
          28. }
          29. }

          Spring核心配置文件

          這里用到了阿里巴巴的druid連接池

           
          
          1. <beans xmlns="http://www.springframework.org/schema/beans"
          2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          3. xmlns:context="http://www.springframework.org/schema/context"
          4. xsi:schemaLocation="http://www.springframework.org/schema/beans
          5. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          6. http://www.springframework.org/schema/context
          7. http://www.springframework.org/schema/context/spring-context-3.0.xsd">
          8. <!--開啟注解-->
          9. <context:component-scan base-package="com.tulun"/>
          10. <!--配置數據源:借助連接池druid-->
          11. <bean id ="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
          12. <!--注入屬性-->
          13. <property name="url" value="jdbc:mysql://localhost:3306/test"/>
          14. <property name="username" value="root"/>
          15. <property name="password" value="123456"/>
          16. </bean>
          17. <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
          18. <property name="dataSource" ref="dataSource"/>
          19. <!--注入mapper映射文件-->
          20. <property name="configLocation" value="classpath:spring-mybatis.xml"></property>
          21. <property name="mapperLocations" value="classpath:mapper/*.xml"/>
          22. </bean>
          23. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
          24. <property name="basePackage" value="com.tulun.dao"/>
          25. <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
          26. </bean>
          27. </beans>

          Spring-Mybatis配置文件

           
          
          1. <?xml version="1.0" encoding="UTF-8" ?>
          2. <!DOCTYPE configuration
          3. PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
          4. "http://mybatis.org/dtd/mybatis-3-config.dtd">
          5. <!--根標簽-->
          6. <configuration>
          7. </configuration>

          SpringMVC配置文件

           
          
          1. <?xml version="1.0" encoding="UTF-8"?>
          2. <beans xmlns="http://www.springframework.org/schema/beans"
          3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          4. xmlns:context="http://www.springframework.org/schema/context"
          5. xmlns:mvc="http://www.springframework.org/schema/mvc"
          6. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          7. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
          8. http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">
          9. <!--掃描controller寫注解-->
          10. <context:component-scan base-package="com.tulun.controller"/>
          11. <!--配置映射器-->
          12. <mvc:annotation-driven/>
          13. <!--配置視圖解析器-->
          14. <!--視圖解析器-->
          15. <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
          16. <!--jsp頁面前綴-->
          17. <property name="prefix" value="/WEB-INF/jsp/"/>
          18. <!--jsp后綴-->
          19. <property name="suffix" value=".jsp"/>
          20. <property name="viewClass" value="org.springframework.web.servlet.view.freemarker.FreeMarkerView"/>
          21. </bean>
          22. </beans>

          web配置文件

           
          
          1. <?xml version="1.0" encoding="UTF-8"?>
          2. <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
          3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          4. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
          5. http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
          6. <context-param>
          7. <param-name>contextConfigLocation</param-name>
          8. <param-value>classpath:spring-core.xml</param-value>
          9. </context-param>
          10. <listener>
          11. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
          12. </listener>
          13. <!--前端控制器-->
          14. <servlet>
          15. <servlet-name>myBolg</servlet-name>
          16. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
          17. <!--將springMVC的配置文件進行配置-->
          18. <init-param>
          19. <param-name>contextConfigLocation</param-name>
          20. <param-value>classpath:spring-mvc.xml</param-value>
          21. </init-param>
          22. </servlet>
          23. <servlet-mapping>
          24. <servlet-name>myBolg</servlet-name>
          25. <url-pattern>/</url-pattern>
          26. </servlet-mapping>
          27. </web-app>

          pom依賴

           
          
          1. <dependencies>
          2. <dependency>
          3. <groupId>junit</groupId>
          4. <artifactId>junit</artifactId>
          5. <version>4.11</version>
          6. <scope>test</scope>
          7. </dependency>
          8. <!-- spring依賴-->
          9. <dependency>
          10. <groupId>org.springframework</groupId>
          11. <artifactId>spring-core</artifactId>
          12. <version>5.2.8.RELEASE</version>
          13. </dependency>
          14. <dependency>
          15. <groupId>org.springframework</groupId>
          16. <artifactId>spring-context</artifactId>
          17. <version>5.2.8.RELEASE</version>
          18. </dependency>
          19. <dependency>
          20. <groupId>org.springframework</groupId>
          21. <artifactId>spring-beans</artifactId>
          22. <version>5.2.8.RELEASE</version>
          23. </dependency>
          24. <dependency>
          25. <groupId>org.springframework</groupId>
          26. <artifactId>spring-expression</artifactId>
          27. <version>5.2.8.RELEASE</version>
          28. </dependency>
          29. <!--web依賴/spring mvc依賴-->
          30. <dependency>
          31. <groupId>org.springframework</groupId>
          32. <artifactId>spring-webmvc</artifactId>
          33. <version>5.2.8.RELEASE</version>
          34. </dependency>
          35. <dependency>
          36. <groupId>org.springframework</groupId>
          37. <artifactId>spring-web</artifactId>
          38. <version>5.2.8.RELEASE</version>
          39. </dependency>
          40. <dependency>
          41. <groupId>javax.servlet</groupId>
          42. <artifactId>javax.servlet-api</artifactId>
          43. <version>3.1.0</version>
          44. </dependency>
          45. <!--tomcat servlet api -->
          46. <dependency>
          47. <groupId>jstl</groupId>
          48. <artifactId>jstl</artifactId>
          49. <version>1.2</version>
          50. </dependency>
          51. <dependency>
          52. <groupId>taglibs</groupId>
          53. <artifactId>standard</artifactId>
          54. <version>1.1.2</version>
          55. </dependency>
          56. <!--mybatis依賴-->
          57. <dependency>
          58. <groupId>org.mybatis</groupId>
          59. <artifactId>mybatis</artifactId>
          60. <version>3.4.1</version>
          61. </dependency>
          62. <dependency>
          63. <groupId>mysql</groupId>
          64. <artifactId>mysql-connector-java</artifactId>
          65. <version>5.1.39</version>
          66. </dependency>
          67. <!-- 整合-->
          68. <dependency>
          69. <groupId>org.mybatis</groupId>
          70. <artifactId>mybatis-spring</artifactId>
          71. <version>1.3.0</version>
          72. </dependency>
          73. <!-- 連接池-->
          74. <dependency>
          75. <groupId>com.mchange</groupId>
          76. <artifactId>c3p0</artifactId>
          77. <version>0.9.5.2</version>
          78. </dependency>
          79. <dependency>
          80. <groupId>org.springframework</groupId>
          81. <artifactId>spring-tx</artifactId>
          82. <version>5.2.8.RELEASE</version>
          83. </dependency>
          84. <dependency>
          85. <groupId>org.springframework</groupId>
          86. <artifactId>spring-jdbc</artifactId>
          87. <version>5.2.8.RELEASE</version>
          88. </dependency>
          89. <dependency>
          90. <groupId>javax.servlet.jsp.jstl</groupId>
          91. <artifactId>jstl</artifactId>
          92. <version>1.2</version>
          93. </dependency>
          94. <dependency>
          95. <groupId>javax.servlet</groupId>
          96. <artifactId>servlet-api</artifactId>
          97. <version>2.5</version>
          98. </dependency>
          99. <dependency>
          100. <groupId>com.google.code.gson</groupId>
          101. <artifactId>gson</artifactId>
          102. <version>2.3</version>
          103. </dependency>
          104. <dependency>
          105. <groupId>com.alibaba</groupId>
          106. <artifactId>druid</artifactId>
          107. <version>0.2.6</version>
          108. </dependency>
          109. <dependency>
          110. <groupId>commons-logging</groupId>
          111. <artifactId>commons-logging</artifactId>
          112. <version>1.1.1</version>
          113. </dependency>
          114. <dependency>
          115. <groupId>commons-configuration</groupId>
          116. <artifactId>commons-configuration</artifactId>
          117. <version>1.9</version>
          118. </dependency>
          119. </dependencies>

          UserMapper

           
          
          1. import com.tulun.model.User;
          2. /**
          3. * Description :
          4. * Created by Resumebb
          5. * Date :2021/4/22
          6. */
          7. public interface UserMapper {
          8. public User getUserById(Integer id);
          9. }

          UserService

           
          
          1. package com.tulun.service;
          2. import com.tulun.model.User;
          3. import com.tulun.dao.UserMapper;
          4. import org.springframework.beans.factory.annotation.Autowired;
          5. import org.springframework.stereotype.Service;
          6. /**
          7. * Description :
          8. * Created by Resumebb
          9. * Date :2021/4/19
          10. */
          11. @Service
          12. public class UserService {
          13. @Autowired
          14. private UserMapper userMapper;
          15. public User getUserById(Integer id){
          16. if(id < 0)
          17. return new User();
          18. return userMapper.getUserById(id);
          19. }
          20. }

          UserController

          查詢t_manager中的id為1的數據進行顯示

           
          
          1. package com.tulun.controller;
          2. import com.tulun.model.User;
          3. import com.tulun.service.UserService;
          4. import org.springframework.beans.factory.annotation.Autowired;
          5. import org.springframework.stereotype.Controller;
          6. import org.springframework.web.bind.annotation.RequestMapping;
          7. import org.springframework.web.bind.annotation.ResponseBody;
          8. /**
          9. * Description :
          10. * Created by Resumebb
          11. * Date :2021/4/22
          12. */
          13. @Controller
          14. public class UserController {
          15. @Autowired
          16. private UserService userService;
          17. @RequestMapping("/testUser")
          18. @ResponseBody
          19. public User testUser(){
          20. User user = userService.getUserById(1);
          21. return user;
          22. }
          23. }

          UserMapper.xml

           
          
          1. <?xml version="1.0" encoding="UTF-8" ?>
          2. <!DOCTYPE mapper
          3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
          4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
          5. <mapper namespace="com.tulun.dao.UserMapper">
          6. <resultMap id="UserMap" type="com.tulun.model.User">
          7. <result property="id" column="id"></result>
          8. <result property="name" column="userName"></result>
          9. <result property="passwd" column="password"></result>
          10. </resultMap>
          11. <select id="getUserById" parameterType="int" resultMap="UserMap">
          12. select * from t_manager where id=#{id}
          13. </select>
          14. </mapper>

          運行結果

           

          錯誤記錄

          運行的界面顯示unkown the request

           原因是因為端口被占用了,更改服務器的端口號就可以了。

          出現這個錯誤就要檢查SQL查詢語句,數據源的配置是否正確,經檢查我報這個錯是因為SQL查詢語句manager寫成了manger,用戶名密碼不對也會報這個錯。

          類似這種錯,一是檢查@Service有沒有加上,二是檢查映射文件有沒有頂行寫,第一行不能有空行。

          轉自:csdn。作者:resumebb

          藍藍設計www.syprn.cn )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 、平面設計服務

          日歷

          鏈接

          個人資料

          藍藍設計的小編 http://www.syprn.cn

          存檔

          亚洲va欧美va天堂v国产综合