…'),0!==t&&e.push(''+(a.last||a.pages)+"")),e.join("")}(),next:function(){return a.next?''+a.next+"":""}(),count:'共 '+a.count+" 条",limit:function(){var e=['"}(),refresh:['','',""].join(""),skip:function(){return['到第','','页',""].join("")}()};return['',function(){var e=[];return layui.each(a.layout,function(a,t){i[t]&&e.push(i[t])}),e.join("")}(),"
"].join("")},u.prototype.jump=function(e,a){if(e){var t=this,i=t.config,r=e.children,u=e[n]("button")[0],l=e[n]("input")[0],p=e[n]("select")[0],c=function(){var e=0|l.value.replace(/\s|\D/g,"");e&&(i.curr=e,t.render())};if(a)return c();for(var o=0,y=r.length;oi.pages||(i.curr=e,t.render())});p&&s.on(p,"change",function(){var e=this.value;i.curr*e>i.count&&(i.curr=Math.ceil(i.count/e)),i.limit=e,t.render()}),u&&s.on(u,"click",function(){c()})}},u.prototype.skip=function(e){if(e){var a=this,t=e[n]("input")[0];t&&s.on(t,"keyup",function(t){var n=this.value,i=t.keyCode;/^(37|38|39|40)$/.test(i)||(/\D/.test(n)&&(this.value=n.replace(/\D/,"")),13===i&&a.jump(e,!0))})}},u.prototype.render=function(e){var n=this,i=n.config,r=n.type(),u=n.view();2===r?i.elem&&(i.elem.innerHTML=u):3===r?i.elem.html(u):a[t](i.elem)&&(a[t](i.elem).innerHTML=u),i.jump&&i.jump(i,e);var s=a[t]("layui-laypage-"+i.index);n.jump(s),i.hash&&!e&&(location.hash="!"+i.hash+"="+i.curr),n.skip(s)};var s={render:function(e){var a=new u(e);return a.index},index:layui.laypage?layui.laypage.index+1e4:0,on:function(e,a,t){return e.attachEvent?e.attachEvent("on"+a,function(a){a.target=a.srcElement,t.call(e,a)}):e.addEventListener(a,t,!1),this}};e(i,s)});
--------------------------------------------------------------------------------
/springboot-layui-demo/src/main/resources/static/layui/lay/modules/laytpl.js:
--------------------------------------------------------------------------------
1 | /** layui-v2.4.5 MIT License By https://www.layui.com */
2 | ;layui.define(function(e){"use strict";var r={open:"{{",close:"}}"},c={exp:function(e){return new RegExp(e,"g")},query:function(e,c,t){var o=["#([\\s\\S])+?","([^{#}])*?"][e||0];return n((c||"")+r.open+o+r.close+(t||""))},escape:function(e){return String(e||"").replace(/&(?!#?[a-zA-Z0-9]+;)/g,"&").replace(//g,">").replace(/'/g,"'").replace(/"/g,""")},error:function(e,r){var c="Laytpl Error:";return"object"==typeof console&&console.error(c+e+"\n"+(r||"")),c+e}},n=c.exp,t=function(e){this.tpl=e};t.pt=t.prototype,window.errors=0,t.pt.parse=function(e,t){var o=this,p=e,a=n("^"+r.open+"#",""),l=n(r.close+"$","");e=e.replace(/\s+|\r|\t|\n/g," ").replace(n(r.open+"#"),r.open+"# ").replace(n(r.close+"}"),"} "+r.close).replace(/\\/g,"\\\\").replace(n(r.open+"!(.+?)!"+r.close),function(e){return e=e.replace(n("^"+r.open+"!"),"").replace(n("!"+r.close),"").replace(n(r.open+"|"+r.close),function(e){return e.replace(/(.)/g,"\\$1")})}).replace(/(?="|')/g,"\\").replace(c.query(),function(e){return e=e.replace(a,"").replace(l,""),'";'+e.replace(/\\/g,"")+';view+="'}).replace(c.query(1),function(e){var c='"+(';return e.replace(/\s/g,"")===r.open+r.close?"":(e=e.replace(n(r.open+"|"+r.close),""),/^=/.test(e)&&(e=e.replace(/^=/,""),c='"+_escape_('),c+e.replace(/\\/g,"")+')+"')}),e='"use strict";var view = "'+e+'";return view;';try{return o.cache=e=new Function("d, _escape_",e),e(t,c.escape)}catch(u){return delete o.cache,c.error(u,p)}},t.pt.render=function(e,r){var n,t=this;return e?(n=t.cache?t.cache(e,c.escape):t.parse(t.tpl,e),r?void r(n):n):c.error("no data")};var o=function(e){return"string"!=typeof e?c.error("Template not found"):new t(e)};o.config=function(e){e=e||{};for(var c in e)r[c]=e[c]},o.v="1.2.0",e("laytpl",o)});
--------------------------------------------------------------------------------
/springboot-layui-demo/src/main/resources/static/layui/lay/modules/rate.js:
--------------------------------------------------------------------------------
1 | /** layui-v2.4.5 MIT License By https://www.layui.com */
2 | ;layui.define("jquery",function(e){"use strict";var a=layui.jquery,i={config:{},index:layui.rate?layui.rate.index+1e4:0,set:function(e){var i=this;return i.config=a.extend({},i.config,e),i},on:function(e,a){return layui.onevent.call(this,n,e,a)}},l=function(){var e=this,a=e.config;return{setvalue:function(a){e.setvalue.call(e,a)},config:a}},n="rate",t="layui-rate",o="layui-icon-rate",s="layui-icon-rate-solid",u="layui-icon-rate-half",r="layui-icon-rate-solid layui-icon-rate-half",c="layui-icon-rate-solid layui-icon-rate",f="layui-icon-rate layui-icon-rate-half",v=function(e){var l=this;l.index=++i.index,l.config=a.extend({},l.config,i.config,e),l.render()};v.prototype.config={length:5,text:!1,readonly:!1,half:!1,value:0,theme:""},v.prototype.render=function(){var e=this,i=e.config,l=i.theme?'style="color: '+i.theme+';"':"";i.elem=a(i.elem),parseInt(i.value)!==i.value&&(i.half||(i.value=Math.ceil(i.value)-i.value<.5?Math.ceil(i.value):Math.floor(i.value)));for(var n='",u=1;u<=i.length;u++){var r=' ";i.half&&parseInt(i.value)!==i.value&&u==Math.ceil(i.value)?n=n+' ":n+=r}n+="
"+(i.text?''+i.value+"星":"")+"";var c=i.elem,f=c.next("."+t);f[0]&&f.remove(),e.elemTemp=a(n),i.span=e.elemTemp.next("span"),i.setText&&i.setText(i.value),c.html(e.elemTemp),c.addClass("layui-inline"),i.readonly||e.action()},v.prototype.setvalue=function(e){var a=this,i=a.config;i.value=e,a.render()},v.prototype.action=function(){var e=this,i=e.config,l=e.elemTemp,n=l.find("i").width();l.children("li").each(function(e){var t=e+1,v=a(this);v.on("click",function(e){if(i.value=t,i.half){var o=e.pageX-a(this).offset().left;o<=n/2&&(i.value=i.value-.5)}i.text&&l.next("span").text(i.value+"星"),i.choose&&i.choose(i.value),i.setText&&i.setText(i.value)}),v.on("mousemove",function(e){if(l.find("i").each(function(){a(this).addClass(o).removeClass(r)}),l.find("i:lt("+t+")").each(function(){a(this).addClass(s).removeClass(f)}),i.half){var c=e.pageX-a(this).offset().left;c<=n/2&&v.children("i").addClass(u).removeClass(s)}}),v.on("mouseleave",function(){l.find("i").each(function(){a(this).addClass(o).removeClass(r)}),l.find("i:lt("+Math.floor(i.value)+")").each(function(){a(this).addClass(s).removeClass(f)}),i.half&&parseInt(i.value)!==i.value&&l.children("li:eq("+Math.floor(i.value)+")").children("i").addClass(u).removeClass(c)})})},v.prototype.events=function(){var e=this;e.config},i.render=function(e){var a=new v(e);return l.call(a)},e(n,i)});
--------------------------------------------------------------------------------
/springboot-layui-demo/src/main/resources/static/layui/lay/modules/tree.js:
--------------------------------------------------------------------------------
1 | /** layui-v2.4.5 MIT License By https://www.layui.com */
2 | ;layui.define("jquery",function(e){"use strict";var o=layui.$,a=layui.hint(),i="layui-tree-enter",r=function(e){this.options=e},t={arrow:["",""],checkbox:["",""],radio:["",""],branch:["",""],leaf:""};r.prototype.init=function(e){var o=this;e.addClass("layui-box layui-tree"),o.options.skin&&e.addClass("layui-tree-skin-"+o.options.skin),o.tree(e),o.on(e)},r.prototype.tree=function(e,a){var i=this,r=i.options,n=a||r.nodes;layui.each(n,function(a,n){var l=n.children&&n.children.length>0,c=o(''),s=o(["",function(){return l?''+(n.spread?t.arrow[1]:t.arrow[0])+"":""}(),function(){return r.check?''+("checkbox"===r.check?t.checkbox[0]:"radio"===r.check?t.radio[0]:"")+"":""}(),function(){return'"+(''+(l?n.spread?t.branch[1]:t.branch[0]:t.leaf)+"")+(""+(n.name||"未命名")+"")}(),""].join(""));l&&(s.append(c),i.tree(c,n.children)),e.append(s),"function"==typeof r.click&&i.click(s,n),i.spread(s,n),r.drag&&i.drag(s,n)})},r.prototype.click=function(e,o){var a=this,i=a.options;e.children("a").on("click",function(e){layui.stope(e),i.click(o)})},r.prototype.spread=function(e,o){var a=this,i=(a.options,e.children(".layui-tree-spread")),r=e.children("ul"),n=e.children("a"),l=function(){e.data("spread")?(e.data("spread",null),r.removeClass("layui-show"),i.html(t.arrow[0]),n.find(".layui-icon").html(t.branch[0])):(e.data("spread",!0),r.addClass("layui-show"),i.html(t.arrow[1]),n.find(".layui-icon").html(t.branch[1]))};r[0]&&(i.on("click",l),n.on("dblclick",l))},r.prototype.on=function(e){var a=this,r=a.options,t="layui-tree-drag";e.find("i").on("selectstart",function(e){return!1}),r.drag&&o(document).on("mousemove",function(e){var i=a.move;if(i.from){var r=(i.to,o(''));e.preventDefault(),o("."+t)[0]||o("body").append(r);var n=o("."+t)[0]?o("."+t):r;n.addClass("layui-show").html(i.from.elem.children("a").html()),n.css({left:e.pageX+10,top:e.pageY+10})}}).on("mouseup",function(){var e=a.move;e.from&&(e.from.elem.children("a").removeClass(i),e.to&&e.to.elem.children("a").removeClass(i),a.move={},o("."+t).remove())})},r.prototype.move={},r.prototype.drag=function(e,a){var r=this,t=(r.options,e.children("a")),n=function(){var t=o(this),n=r.move;n.from&&(n.to={item:a,elem:e},t.addClass(i))};t.on("mousedown",function(){var o=r.move;o.from={item:a,elem:e}}),t.on("mouseenter",n).on("mousemove",n).on("mouseleave",function(){var e=o(this),a=r.move;a.from&&(delete a.to,e.removeClass(i))})},e("tree",function(e){var i=new r(e=e||{}),t=o(e.elem);return t[0]?void i.init(t):a.error("layui.tree 没有找到"+e.elem+"元素")})});
--------------------------------------------------------------------------------
/springboot-layui-demo/src/main/resources/static/layui/lay/modules/upload.js:
--------------------------------------------------------------------------------
1 | /** layui-v2.4.5 MIT License By https://www.layui.com */
2 | ;layui.define("layer",function(e){"use strict";var i=layui.$,t=layui.layer,n=layui.hint(),a=layui.device(),o={config:{},set:function(e){var t=this;return t.config=i.extend({},t.config,e),t},on:function(e,i){return layui.onevent.call(this,r,e,i)}},l=function(){var e=this;return{upload:function(i){e.upload.call(e,i)},config:e.config}},r="upload",u="layui-upload-file",c="layui-upload-form",f="layui-upload-iframe",s="layui-upload-choose",p=function(e){var t=this;t.config=i.extend({},t.config,o.config,e),t.render()};p.prototype.config={accept:"images",exts:"",auto:!0,bindAction:"",url:"",field:"file",method:"post",data:{},drag:!0,size:0,number:0,multiple:!1},p.prototype.render=function(e){var t=this,e=t.config;e.elem=i(e.elem),e.bindAction=i(e.bindAction),t.file(),t.events()},p.prototype.file=function(){var e=this,t=e.config,n=e.elemFile=i(['"].join("")),o=t.elem.next();(o.hasClass(u)||o.hasClass(c))&&o.remove(),a.ie&&a.ie<10&&t.elem.wrap(''),e.isFile()?(e.elemFile=t.elem,t.field=t.elem[0].name):t.elem.after(n),a.ie&&a.ie<10&&e.initIE()},p.prototype.initIE=function(){var e=this,t=e.config,n=i(''),a=i(['"].join(""));i("#"+f)[0]||i("body").append(n),t.elem.next().hasClass(c)||(e.elemFile.wrap(a),t.elem.next("."+c).append(function(){var e=[];return layui.each(t.data,function(i,t){t="function"==typeof t?t():t,e.push('')}),e.join("")}()))},p.prototype.msg=function(e){return t.msg(e,{icon:2,shift:6})},p.prototype.isFile=function(){var e=this.config.elem[0];if(e)return"input"===e.tagName.toLocaleLowerCase()&&"file"===e.type},p.prototype.preview=function(e){var i=this;window.FileReader&&layui.each(i.chooseFiles,function(i,t){var n=new FileReader;n.readAsDataURL(t),n.onload=function(){e&&e(i,t,this.result)}})},p.prototype.upload=function(e,t){var n,o=this,l=o.config,r=o.elemFile[0],u=function(){var t=0,n=0,a=e||o.files||o.chooseFiles||r.files,u=function(){l.multiple&&t+n===o.fileLength&&"function"==typeof l.allDone&&l.allDone({total:o.fileLength,successful:t,aborted:n})};layui.each(a,function(e,a){var r=new FormData;r.append(l.field,a),layui.each(l.data,function(e,i){i="function"==typeof i?i():i,r.append(e,i)}),i.ajax({url:l.url,type:"post",data:r,contentType:!1,processData:!1,dataType:"json",headers:l.headers||{},success:function(i){t++,d(e,i),u()},error:function(){n++,o.msg("请求上传接口出现异常"),m(e),u()}})})},c=function(){var e=i("#"+f);o.elemFile.parent().submit(),clearInterval(p.timer),p.timer=setInterval(function(){var i,t=e.contents().find("body");try{i=t.text()}catch(n){o.msg("获取上传后的响应信息出现异常"),clearInterval(p.timer),m()}i&&(clearInterval(p.timer),t.html(""),d(0,i))},30)},d=function(e,i){if(o.elemFile.next("."+s).remove(),r.value="","object"!=typeof i)try{i=JSON.parse(i)}catch(t){return i={},o.msg("请对上传接口返回有效JSON")}"function"==typeof l.done&&l.done(i,e||0,function(e){o.upload(e)})},m=function(e){l.auto&&(r.value=""),"function"==typeof l.error&&l.error(e||0,function(e){o.upload(e)})},h=l.exts,v=function(){var i=[];return layui.each(e||o.chooseFiles,function(e,t){i.push(t.name)}),i}(),g={preview:function(e){o.preview(e)},upload:function(e,i){var t={};t[e]=i,o.upload(t)},pushFile:function(){return o.files=o.files||{},layui.each(o.chooseFiles,function(e,i){o.files[e]=i}),o.files},resetFile:function(e,i,t){var n=new File([i],t);o.files=o.files||{},o.files[e]=n}},y=function(){if("choose"!==t&&!l.auto||(l.choose&&l.choose(g),"choose"!==t))return l.before&&l.before(g),a.ie?a.ie>9?u():c():void u()};if(v=0===v.length?r.value.match(/[^\/\\]+\..+/g)||[]||"":v,0!==v.length){switch(l.accept){case"file":if(h&&!RegExp("\\w\\.("+h+")$","i").test(escape(v)))return o.msg("选择的文件中包含不支持的格式"),r.value="";break;case"video":if(!RegExp("\\w\\.("+(h||"avi|mp4|wma|rmvb|rm|flash|3gp|flv")+")$","i").test(escape(v)))return o.msg("选择的视频中包含不支持的格式"),r.value="";break;case"audio":if(!RegExp("\\w\\.("+(h||"mp3|wav|mid")+")$","i").test(escape(v)))return o.msg("选择的音频中包含不支持的格式"),r.value="";break;default:if(layui.each(v,function(e,i){RegExp("\\w\\.("+(h||"jpg|png|gif|bmp|jpeg$")+")","i").test(escape(i))||(n=!0)}),n)return o.msg("选择的图片中包含不支持的格式"),r.value=""}if(o.fileLength=function(){var i=0,t=e||o.files||o.chooseFiles||r.files;return layui.each(t,function(){i++}),i}(),l.number&&o.fileLength>l.number)return o.msg("同时最多只能上传的数量为:"+l.number);if(l.size>0&&!(a.ie&&a.ie<10)){var F;if(layui.each(o.chooseFiles,function(e,i){if(i.size>1024*l.size){var t=l.size/1024;t=t>=1?t.toFixed(2)+"MB":l.size+"KB",r.value="",F=t}}),F)return o.msg("文件不能超过"+F)}y()}},p.prototype.events=function(){var e=this,t=e.config,o=function(i){e.chooseFiles={},layui.each(i,function(i,t){var n=(new Date).getTime();e.chooseFiles[n+"-"+i]=t})},l=function(i,n){var a=e.elemFile,o=i.length>1?i.length+"个文件":(i[0]||{}).name||a[0].value.match(/[^\/\\]+\..+/g)||[]||"";a.next().hasClass(s)&&a.next().remove(),e.upload(null,"choose"),e.isFile()||t.choose||a.after(''+o+"")};t.elem.off("upload.start").on("upload.start",function(){var a=i(this),o=a.attr("lay-data");if(o)try{o=new Function("return "+o)(),e.config=i.extend({},t,o)}catch(l){n.error("Upload element property lay-data configuration item has a syntax error: "+o)}e.config.item=a,e.elemFile[0].click()}),a.ie&&a.ie<10||t.elem.off("upload.over").on("upload.over",function(){var e=i(this);e.attr("lay-over","")}).off("upload.leave").on("upload.leave",function(){var e=i(this);e.removeAttr("lay-over")}).off("upload.drop").on("upload.drop",function(n,a){var r=i(this),u=a.originalEvent.dataTransfer.files||[];r.removeAttr("lay-over"),o(u),t.auto?e.upload(u):l(u)}),e.elemFile.off("upload.change").on("upload.change",function(){var i=this.files||[];o(i),t.auto?e.upload():l(i)}),t.bindAction.off("upload.action").on("upload.action",function(){e.upload()}),t.elem.data("haveEvents")||(e.elemFile.on("change",function(){i(this).trigger("upload.change")}),t.elem.on("click",function(){e.isFile()||i(this).trigger("upload.start")}),t.drag&&t.elem.on("dragover",function(e){e.preventDefault(),i(this).trigger("upload.over")}).on("dragleave",function(e){i(this).trigger("upload.leave")}).on("drop",function(e){e.preventDefault(),i(this).trigger("upload.drop",e)}),t.bindAction.on("click",function(){i(this).trigger("upload.action")}),t.elem.data("haveEvents",!0))},o.render=function(e){var i=new p(e);return l.call(i)},e(r,o)});
--------------------------------------------------------------------------------
/springboot-layui-demo/src/main/resources/static/layui/lay/modules/util.js:
--------------------------------------------------------------------------------
1 | /** layui-v2.4.5 MIT License By https://www.layui.com */
2 | ;layui.define("jquery",function(t){"use strict";var e=layui.$,i={fixbar:function(t){var i,a,n="layui-fixbar",r="layui-fixbar-top",o=e(document),l=e("body");t=e.extend({showHeight:200},t),t.bar1=t.bar1===!0?"":t.bar1,t.bar2=t.bar2===!0?"":t.bar2,t.bgcolor=t.bgcolor?"background-color:"+t.bgcolor:"";var c=[t.bar1,t.bar2,""],g=e(['',t.bar1?'- '+c[0]+"
":"",t.bar2?'- '+c[1]+"
":"",'- '+c[2]+"
","
"].join("")),s=g.find("."+r),u=function(){var e=o.scrollTop();e>=t.showHeight?i||(s.show(),i=1):i&&(s.hide(),i=0)};e("."+n)[0]||("object"==typeof t.css&&g.css(t.css),l.append(g),u(),g.find("li").on("click",function(){var i=e(this),a=i.attr("lay-type");"top"===a&&e("html,body").animate({scrollTop:0},200),t.click&&t.click.call(this,a)}),o.on("scroll",function(){clearTimeout(a),a=setTimeout(function(){u()},100)}))},countdown:function(t,e,i){var a=this,n="function"==typeof e,r=new Date(t).getTime(),o=new Date(!e||n?(new Date).getTime():e).getTime(),l=r-o,c=[Math.floor(l/864e5),Math.floor(l/36e5)%24,Math.floor(l/6e4)%60,Math.floor(l/1e3)%60];n&&(i=e);var g=setTimeout(function(){a.countdown(t,o+1e3,i)},1e3);return i&&i(l>0?c:[0,0,0,0],e,g),l<=0&&clearTimeout(g),g},timeAgo:function(t,e){var i=this,a=[[],[]],n=(new Date).getTime()-new Date(t).getTime();return n>6912e5?(n=new Date(t),a[0][0]=i.digit(n.getFullYear(),4),a[0][1]=i.digit(n.getMonth()+1),a[0][2]=i.digit(n.getDate()),e||(a[1][0]=i.digit(n.getHours()),a[1][1]=i.digit(n.getMinutes()),a[1][2]=i.digit(n.getSeconds())),a[0].join("-")+" "+a[1].join(":")):n>=864e5?(n/1e3/60/60/24|0)+"天前":n>=36e5?(n/1e3/60/60|0)+"小时前":n>=12e4?(n/1e3/60|0)+"分钟前":n<0?"未来":"刚刚"},digit:function(t,e){var i="";t=String(t),e=e||2;for(var a=t.length;a/g,">").replace(/'/g,"'").replace(/"/g,""")}};!function(t,e,i){"$:nomunge";function a(){n=e[l](function(){r.each(function(){var e=t(this),i=e.width(),a=e.height(),n=t.data(this,g);(i!==n.w||a!==n.h)&&e.trigger(c,[n.w=i,n.h=a])}),a()},o[s])}var n,r=t([]),o=t.resize=t.extend(t.resize,{}),l="setTimeout",c="resize",g=c+"-special-event",s="delay",u="throttleWindow";o[s]=250,o[u]=!0,t.event.special[c]={setup:function(){if(!o[u]&&this[l])return!1;var e=t(this);r=r.add(e),t.data(this,g,{w:e.width(),h:e.height()}),1===r.length&&a()},teardown:function(){if(!o[u]&&this[l])return!1;var e=t(this);r=r.not(e),e.removeData(g),r.length||clearTimeout(n)},add:function(e){function a(e,a,r){var o=t(this),l=t.data(this,g)||{};l.w=a!==i?a:o.width(),l.h=r!==i?r:o.height(),n.apply(this,arguments)}if(!o[u]&&this[l])return!1;var n;return t.isFunction(e)?(n=e,a):(n=e.handler,void(e.handler=a))}}}(e,window),t("util",i)});
--------------------------------------------------------------------------------
/springboot-layui-demo/src/main/resources/static/layui/layui.js:
--------------------------------------------------------------------------------
1 | /** layui-v2.4.5 MIT License By https://www.layui.com */
2 | ;!function(e){"use strict";var t=document,o={modules:{},status:{},timeout:10,event:{}},n=function(){this.v="2.4.5"},r=function(){var e=t.currentScript?t.currentScript.src:function(){for(var e,o=t.scripts,n=o.length-1,r=n;r>0;r--)if("interactive"===o[r].readyState){e=o[r].src;break}return e||o[n].src}();return e.substring(0,e.lastIndexOf("/")+1)}(),i=function(t){e.console&&console.error&&console.error("Layui hint: "+t)},a="undefined"!=typeof opera&&"[object Opera]"===opera.toString(),u={layer:"modules/layer",laydate:"modules/laydate",laypage:"modules/laypage",laytpl:"modules/laytpl",layim:"modules/layim",layedit:"modules/layedit",form:"modules/form",upload:"modules/upload",tree:"modules/tree",table:"modules/table",element:"modules/element",rate:"modules/rate",colorpicker:"modules/colorpicker",slider:"modules/slider",carousel:"modules/carousel",flow:"modules/flow",util:"modules/util",code:"modules/code",jquery:"modules/jquery",mobile:"modules/mobile","layui.all":"../layui.all"};n.prototype.cache=o,n.prototype.define=function(e,t){var n=this,r="function"==typeof e,i=function(){var e=function(e,t){layui[e]=t,o.status[e]=!0};return"function"==typeof t&&t(function(n,r){e(n,r),o.callback[n]=function(){t(e)}}),this};return r&&(t=e,e=[]),layui["layui.all"]||!layui["layui.all"]&&layui["layui.mobile"]?i.call(n):(n.use(e,i),n)},n.prototype.use=function(e,n,l){function s(e,t){var n="PLaySTATION 3"===navigator.platform?/^complete$/:/^(complete|loaded)$/;("load"===e.type||n.test((e.currentTarget||e.srcElement).readyState))&&(o.modules[f]=t,d.removeChild(v),function r(){return++m>1e3*o.timeout/4?i(f+" is not a valid module"):void(o.status[f]?c():setTimeout(r,4))}())}function c(){l.push(layui[f]),e.length>1?y.use(e.slice(1),n,l):"function"==typeof n&&n.apply(layui,l)}var y=this,p=o.dir=o.dir?o.dir:r,d=t.getElementsByTagName("head")[0];e="string"==typeof e?[e]:e,window.jQuery&&jQuery.fn.on&&(y.each(e,function(t,o){"jquery"===o&&e.splice(t,1)}),layui.jquery=layui.$=jQuery);var f=e[0],m=0;if(l=l||[],o.host=o.host||(p.match(/\/\/([\s\S]+?)\//)||["//"+location.host+"/"])[0],0===e.length||layui["layui.all"]&&u[f]||!layui["layui.all"]&&layui["layui.mobile"]&&u[f])return c(),y;if(o.modules[f])!function g(){return++m>1e3*o.timeout/4?i(f+" is not a valid module"):void("string"==typeof o.modules[f]&&o.status[f]?c():setTimeout(g,4))}();else{var v=t.createElement("script"),h=(u[f]?p+"lay/":/^\{\/\}/.test(y.modules[f])?"":o.base||"")+(y.modules[f]||f)+".js";h=h.replace(/^\{\/\}/,""),v.async=!0,v.charset="utf-8",v.src=h+function(){var e=o.version===!0?o.v||(new Date).getTime():o.version||"";return e?"?v="+e:""}(),d.appendChild(v),!v.attachEvent||v.attachEvent.toString&&v.attachEvent.toString().indexOf("[native code")<0||a?v.addEventListener("load",function(e){s(e,h)},!1):v.attachEvent("onreadystatechange",function(e){s(e,h)}),o.modules[f]=h}return y},n.prototype.getStyle=function(t,o){var n=t.currentStyle?t.currentStyle:e.getComputedStyle(t,null);return n[n.getPropertyValue?"getPropertyValue":"getAttribute"](o)},n.prototype.link=function(e,n,r){var a=this,u=t.createElement("link"),l=t.getElementsByTagName("head")[0];"string"==typeof n&&(r=n);var s=(r||e).replace(/\.|\//g,""),c=u.id="layuicss-"+s,y=0;return u.rel="stylesheet",u.href=e+(o.debug?"?v="+(new Date).getTime():""),u.media="all",t.getElementById(c)||l.appendChild(u),"function"!=typeof n?a:(function p(){return++y>1e3*o.timeout/100?i(e+" timeout"):void(1989===parseInt(a.getStyle(t.getElementById(c),"width"))?function(){n()}():setTimeout(p,100))}(),a)},o.callback={},n.prototype.factory=function(e){if(layui[e])return"function"==typeof o.callback[e]?o.callback[e]:null},n.prototype.addcss=function(e,t,n){return layui.link(o.dir+"css/"+e,t,n)},n.prototype.img=function(e,t,o){var n=new Image;return n.src=e,n.complete?t(n):(n.onload=function(){n.onload=null,"function"==typeof t&&t(n)},void(n.onerror=function(e){n.onerror=null,"function"==typeof o&&o(e)}))},n.prototype.config=function(e){e=e||{};for(var t in e)o[t]=e[t];return this},n.prototype.modules=function(){var e={};for(var t in u)e[t]=u[t];return e}(),n.prototype.extend=function(e){var t=this;e=e||{};for(var o in e)t[o]||t.modules[o]?i("模块名 "+o+" 已被占用"):t.modules[o]=e[o];return t},n.prototype.router=function(e){var t=this,e=e||location.hash,o={path:[],search:{},hash:(e.match(/[^#](#.*$)/)||[])[1]||""};return/^#\//.test(e)?(e=e.replace(/^#\//,""),o.href="/"+e,e=e.replace(/([^#])(#.*$)/,"$1").split("/")||[],t.each(e,function(e,t){/^\w+=/.test(t)?function(){t=t.split("="),o.search[t[0]]=t[1]}():o.path.push(t)}),o):o},n.prototype.data=function(t,o,n){if(t=t||"layui",n=n||localStorage,e.JSON&&e.JSON.parse){if(null===o)return delete n[t];o="object"==typeof o?o:{key:o};try{var r=JSON.parse(n[t])}catch(i){var r={}}return"value"in o&&(r[o.key]=o.value),o.remove&&delete r[o.key],n[t]=JSON.stringify(r),o.key?r[o.key]:r}},n.prototype.sessionData=function(e,t){return this.data(e,t,sessionStorage)},n.prototype.device=function(t){var o=navigator.userAgent.toLowerCase(),n=function(e){var t=new RegExp(e+"/([^\\s\\_\\-]+)");return e=(o.match(t)||[])[1],e||!1},r={os:function(){return/windows/.test(o)?"windows":/linux/.test(o)?"linux":/iphone|ipod|ipad|ios/.test(o)?"ios":/mac/.test(o)?"mac":void 0}(),ie:function(){return!!(e.ActiveXObject||"ActiveXObject"in e)&&((o.match(/msie\s(\d+)/)||[])[1]||"11")}(),weixin:n("micromessenger")};return t&&!r[t]&&(r[t]=n(t)),r.android=/android/.test(o),r.ios="ios"===r.os,r},n.prototype.hint=function(){return{error:i}},n.prototype.each=function(e,t){var o,n=this;if("function"!=typeof t)return n;if(e=e||[],e.constructor===Object){for(o in e)if(t.call(e[o],o,e[o]))break}else for(o=0;oi?1:rdiv.layui-select-title+ dl,
2 | .select_option_in_layer div.layui-form-select>div.layui-select-title+ dl
3 | /*.layui-table-view .layui-form-select dl*/
4 | {
5 | /*display: none !important;*/
6 | visibility: hidden;
7 | }
8 |
9 | .layui-layer.layui-option-layer {
10 | mso-border-shadow: no;
11 | box-shadow: none;
12 | }
13 |
--------------------------------------------------------------------------------
/springboot-layui-demo/src/main/resources/static/layui/plugin/optimizeSelectOption/optimizeSelectOption.min.js:
--------------------------------------------------------------------------------
1 | /** layui-v2.5.4 MIT License By https://www.layui.com */
2 | ;!function(e){"use strict";var t="optimizeSelectOption";window.top.layui?window.top.layui.use("layer",function(){layui.define(["form"],function(n){n(t,e(t))})}):(console.warn("使用插件:"+t+"页面顶层窗口必须引入layui"),layui.define(["form"],function(e){e(t,{msg:"使用插件:"+t+"页面顶层窗口必须引入layui"})}))}(function(e){function t(e,n,o){n=n||window,e=e.length?e.get(0):e;var i={};if(o&&n.top!==n.self){var l=n.frames.frameElement;i=t(l,n.parent,o)}var a=e.getBoundingClientRect();return{top:a.top+(i.top||0),left:a.left+(i.left||0)}}var n="0.1.9",o=layui.$,i=layui.form,l=(layui.layer,layui.cache.modules.optimizeSelectOption.substr(0,layui.cache.modules.optimizeSelectOption.lastIndexOf("/")));layui.link(l+"/optimizeSelectOption.css?v"+n);var a=[".layui-table-view",".layui-layer-content",".select_option_to_layer"];if(window.top.layer._indexTemp=window.top.layer._indexTemp||{},!i.render.plugFlag){var r=i.render;i.render=function(e,t,n){var i,l=this;return n?layui.each(n,function(t,n){n=o(n);var a=n.parent(),s=a.hasClass("layui-form"),u=a.attr("lay-filter");s?"":a.addClass("layui-form"),u?"":a.attr("lay-filter","tablePlug_form_filter_temp_"+(new Date).getTime()+"_"+Math.floor(1e5*Math.random())),i=r.call(l,e,a.attr("lay-filter")),s?"":a.removeClass("layui-form"),u?"":a.attr("lay-filter",null)}):i=r.call(l,e,t),i},i.render.plugFlag=!0}var s=function(){window.top.layer.close(window.top.layer._indexTemp[e])},u={},c=function(n,i){var l=this;return u.name?(console.warn("针对",n,"的显示优化已经存在,请不要重复渲染!"),l):void o(document).on("click",a.map(function(e){return e+" "+i.triggerElem}).join(","),function(n){function l(){var e=t(u,window,!0),n=e.top,o=e.left;return p?n=n-c.outerHeight()+u.outerHeight()-parseFloat(c.css("bottom")):n+=parseFloat(c.css("top")),{top:n,left:o}}layui.stope(n),s();var r=o(this),u=r,c="function"==typeof i.dlElem?i.dlElem(r):u.next(),f=u.parent().prev(),p=u.parent().hasClass("layui-form-selectup"),d=l();u.css({backgroundColor:"transparent"}),window.top.layer._indexTemp[e]=window.top.layer.open({type:1,title:!1,closeBtn:0,shade:0,anim:-1,fixed:u.closest(".layui-layer-content").length||window.top!==window.self,isOutAnim:!1,offset:[d.top+"px",d.left+"px"],area:c.outerWidth()+"px",content:'',skin:"layui-option-layer",success:function(e,t){c.css({top:0,position:"relative"}).appendTo(e.find(".layui-layer-content").css({overflow:"hidden"}).find(".layui-form-selected")),e.width(u.width());var n=window.top.innerHeight-e.outerHeight()-parseFloat(e.css("top"));p&&e.css({top:"auto",bottom:n+"px"}),"function"==typeof i.success&&i.success.call(this,t,e),e.on("mousedown",function(e){layui.stope(e)}),setTimeout(function(){u.parentsUntil(a.join(",")).one("scroll",function(e){s()}),u.parents(a.join(",")).one("scroll",function(e){s()});var e=window;do{var t=e.$||e.layui.$;t&&(t(e.document).one("click",function(e){s()}),t(e.document).one("mousedown",function(e){s()}),t(e).one("resize",function(e){s()}),t(e.document).one("scroll",function(){top!==self&&parent.parent&&s()}))}while(e.self!==e.top&&(e=e.parent))},500)},end:function(){"function"==typeof i.end&&i.end.call(this,f)}})})};return c("layuiSelect",{triggerElem:"div:not(.layui-select-disabled)>.layui-select-title",success:function(e,t){t.find("dl dd").click(function(){s()})},end:function(e){i.render("select",null,e)}}),{version:n,getPosition:t,close:s}});
--------------------------------------------------------------------------------
/springboot-layui-demo/src/main/resources/static/pages/addPerson.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 更新武侠
6 |
7 |
8 |
9 |
10 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
123 |
124 |
125 |
--------------------------------------------------------------------------------
/springboot-layui-demo/src/main/resources/static/utils/common.js:
--------------------------------------------------------------------------------
1 | var index;
2 |
3 | function open_form(element, data, title, width, height) {
4 | if (title == null || title == '') {
5 | title = false;
6 | }
7 | if (width == null || width == '') {
8 | width = '100%';
9 | }
10 | if (height == null || height == '') {
11 | height = '100%';
12 | }
13 |
14 | index = layer.open({
15 | type: 1,
16 | title: title,
17 | area: [width, height],
18 | fix: false, //不固定
19 | maxmin: true,//开启最大化最小化按钮
20 | shadeClose: true,//点击阴影处可关闭
21 | shade: 0.4,//背景灰度
22 | // skin: 'layui-layer-rim', //加上边框
23 | content: $(element),
24 | success: function () {
25 | $(element).setForm(data);
26 | layui.form.render(); // 下拉框赋值
27 | }
28 | });
29 | }
30 |
31 | function checkForm(formId) {
32 | var form = document.getElementById(formId);
33 | var count = 0;
34 | for (var i = 0; i < form.elements.length - 1; i++) {
35 | if (!form.elements[i].value == "") {
36 | count++;
37 | }
38 | }
39 | return count;
40 | }
41 |
42 | function tableReload(tableId, where, contentType, url, method) {
43 | layui.table.reload(tableId, {
44 | where: where,
45 | contentType: contentType,
46 | page: {
47 | curr: 1 //重新从第 1 页开始
48 | },
49 | url: url
50 | , method: method
51 | });
52 | }
53 | //这个方法是用来初始化弹层
54 | $.fn.setForm = function (jsonValue) {
55 | var obj = this;
56 | $.each(jsonValue, function (name, ival) {
57 | var $oinput = obj.find("input[name=" + name + "]");
58 | if ($oinput.attr("type") == "checkbox") {
59 | if (ival !== null) {
60 | var checkboxObj = $("[name=" + name + "]");
61 | var checkArray = ival.split(";");
62 | for (var i = 0; i < checkboxObj.length; i++) {
63 | for (var j = 0; j < checkArray.length; j++) {
64 | if (checkboxObj[i].value == checkArray[j]) {
65 | checkboxObj[i].click();
66 | }
67 | }
68 | }
69 | }
70 | } else if ($oinput.attr("type") == "radio") {
71 | $oinput.each(function () {
72 | var radioObj = $("[name=" + name + "]");
73 | for (var i = 0; i < radioObj.length; i++) {
74 | if (radioObj[i].value == ival) {
75 | radioObj[i].click();
76 | }
77 | }
78 | });
79 | } else if ($oinput.attr("type") == "textarea") {
80 | obj.find("[name=" + name + "]").html(ival);
81 | } else {
82 | obj.find("[name=" + name + "]").val(ival);
83 | }
84 | })
85 | };
--------------------------------------------------------------------------------
/stream-demo/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | springboot-demo-major
7 | com.mutest
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | stream-demo
13 |
14 |
15 | 8
16 | 8
17 |
18 |
19 |
--------------------------------------------------------------------------------
/stream-demo/src/main/java/stream/model/Person.java:
--------------------------------------------------------------------------------
1 | package stream.model;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | /**
9 | * @author muguozheng
10 | * @version 1.0.0
11 | * @createTime 2022/9/6 9:54
12 | * @description 实体类
13 | */
14 | @Data
15 | public class Person {
16 | private String name; // 姓名
17 | private int salary; // 薪资
18 | private int age; // 年龄
19 | private String sex; //性别
20 | private String area; // 地区
21 |
22 | // 构造方法
23 | public Person(String name, int salary, int age, String sex, String area) {
24 | this.name = name;
25 | this.salary = salary;
26 | this.age = age;
27 | this.sex = sex;
28 | this.area = area;
29 | }
30 |
31 | public static List assemblePersonList() {
32 | List personList = new ArrayList<>();
33 | personList.add(new Person("Tom", 8900, 23, "male", "New York"));
34 | personList.add(new Person("Jack", 7000, 25, "male", "Washington"));
35 | personList.add(new Person("Lily", 7800, 21, "female", "Washington"));
36 | personList.add(new Person("Anni", 8200, 24, "female", "New York"));
37 | personList.add(new Person("Owen", 9500, 25, "male", "New York"));
38 | personList.add(new Person("Alisa", 7900, 26, "female", "New York"));
39 |
40 | return personList;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/stream-demo/src/main/java/stream/test/AggregationTest.java:
--------------------------------------------------------------------------------
1 | package stream.test;
2 |
3 | import stream.model.Person;
4 |
5 | import java.util.*;
6 |
7 | /**
8 | * @author muguozheng
9 | * @version 1.0.0
10 | * @createTime 2022/9/6 10:04
11 | * @description 聚合测试类,包括max、min、sum、count
12 | */
13 | public class AggregationTest {
14 | public static void main(String[] args) {
15 | findingLongest();
16 | findingMax();
17 | maxmumSalary();
18 | count();
19 | }
20 |
21 | /**
22 | * 获取String集合中最长的元素。
23 | */
24 | public static void findingLongest() {
25 | List list = Arrays.asList("adnm", "admmt", "pot", "xbangd", "weoujgsd");
26 |
27 | Optional max = list.stream().max(Comparator.comparing(String::length));
28 | System.out.println("最长的字符串:" + max.get());
29 | }
30 |
31 | /**
32 | * 获取Integer集合中的最大值
33 | */
34 | public static void findingMax() {
35 | List list = Arrays.asList(7, 6, 9, 4, 11, 6);
36 |
37 | // 自然排序
38 | Optional max = list.stream().max(Integer::compareTo);
39 | // 自定义排序
40 | Optional max2 = list.stream().max((o1, o2) -> o2 - o1);
41 | System.out.println("自然排序的最大值:" + max.get());
42 | System.out.println("自定义排序的最大值:" + max2.get());
43 | }
44 |
45 | /**
46 | * 获取员工薪资最高的人
47 | */
48 | public static void maxmumSalary() {
49 | List personList = Person.assemblePersonList();
50 |
51 | Optional max = personList.stream().max(Comparator.comparingInt(Person::getSalary));
52 | System.out.println("员工工资最大值:" + max.get().getSalary());
53 | }
54 |
55 | public static void count() {
56 | List list = Arrays.asList(7, 6, 4, 8, 2, 11, 9);
57 |
58 | long count = list.stream().filter(x -> x > 6).count();
59 | System.out.println("list中大于6的元素个数:" + count);
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/stream-demo/src/main/java/stream/test/CollectTest.java:
--------------------------------------------------------------------------------
1 | package stream.test;
2 |
3 | import stream.model.Person;
4 |
5 | import java.util.*;
6 | import java.util.stream.Collectors;
7 |
8 | /**
9 | * @author muguozheng
10 | * @version 1.0.0
11 | * @createTime 2022/9/6 14:35
12 | * @description collect测试类
13 | */
14 | public class CollectTest {
15 | public static void main(String[] args) {
16 | collectTest();
17 | collectTest2();
18 | collectTest3();
19 | }
20 |
21 | public static void collectTest() {
22 | List list = Arrays.asList(1, 6, 3, 4, 6, 7, 9, 6, 20);
23 | List listNew = list.stream().filter(x -> x % 2 == 0).collect(Collectors.toList());
24 | Set set = list.stream().filter(x -> x % 2 == 0).collect(Collectors.toSet());
25 |
26 | List personList = Person.assemblePersonList();
27 |
28 | Map, Person> map = personList.stream().filter(p -> p.getSalary() > 8000)
29 | .collect(Collectors.toMap(Person::getName, p -> p));
30 | System.out.println("toList:" + listNew);
31 | System.out.println("toSet:" + set);
32 | System.out.println("toMap:" + map);
33 | }
34 |
35 | public static void collectTest2() {
36 | List personList = Person.assemblePersonList();
37 | // 求总数
38 | Long count = personList.stream().collect(Collectors.counting());
39 | // 求平均工资
40 | Double average = personList.stream().collect(Collectors.averagingDouble(Person::getSalary));
41 | // 求最高工资
42 | Optional max = personList.stream().map(Person::getSalary).collect(Collectors.maxBy(Integer::compare));
43 | // 求工资之和
44 | Integer sum = personList.stream().collect(Collectors.summingInt(Person::getSalary));
45 | // 一次性统计所有信息
46 | DoubleSummaryStatistics collect = personList.stream().collect(Collectors.summarizingDouble(Person::getSalary));
47 |
48 | System.out.println("员工总数:" + count);
49 | System.out.println("员工平均工资:" + average);
50 | System.out.println("员工工资总和:" + sum);
51 | System.out.println("员工工资所有统计:" + collect);
52 | }
53 |
54 | public static void collectTest3() {
55 | List personList = Person.assemblePersonList();
56 | // 将员工按薪资是否高于8000分组
57 | Map> part = personList.stream().collect(Collectors.partitioningBy(x -> x.getSalary() > 8000));
58 | // 将员工按性别分组
59 | Map> group = personList.stream().collect(Collectors.groupingBy(Person::getSex));
60 | // 将员工先按性别分组,再按地区分组
61 | Map>> group2 = personList.stream().collect(Collectors.groupingBy(Person::getSex, Collectors.groupingBy(Person::getArea)));
62 | System.out.println("员工按薪资是否大于8000分组情况:" + part);
63 | System.out.println("员工按性别分组情况:" + group);
64 | System.out.println("员工按性别、地区:" + group2);
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/stream-demo/src/main/java/stream/test/FilterTest.java:
--------------------------------------------------------------------------------
1 | package stream.test;
2 |
3 | import stream.model.Person;
4 |
5 | import java.util.ArrayList;
6 | import java.util.Arrays;
7 | import java.util.List;
8 | import java.util.stream.Collectors;
9 | import java.util.stream.Stream;
10 |
11 | /**
12 | * @author muguozheng
13 | * @version 1.0.0
14 | * @createTime 2022/9/6 9:59
15 | * @description filter测试类
16 | */
17 | public class FilterTest {
18 | public static void main(String[] args) {
19 | filter();
20 | filter2();
21 | }
22 |
23 | public static void filter() {
24 | List list = Arrays.asList(6, 7, 3, 8, 1, 2, 9);
25 | Stream stream = list.stream();
26 | stream.filter(x -> x > 7).forEach(System.out::println);
27 | }
28 |
29 | public static void filter2() {
30 | List personList = Person.assemblePersonList();
31 |
32 | List fiterList = personList.stream().filter(x -> x.getSalary() > 8000).map(Person::getName)
33 | .collect(Collectors.toList());
34 | System.out.print("高于8000的员工姓名:" + fiterList);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/stream-demo/src/main/java/stream/test/ForeachTest.java:
--------------------------------------------------------------------------------
1 | package stream.test;
2 |
3 | import java.util.Arrays;
4 | import java.util.List;
5 | import java.util.Optional;
6 |
7 | /**
8 | * @author muguozheng
9 | * @version 1.0.0
10 | * @createTime 2022/9/6 9:55
11 | * @description stream遍历匹配测试类
12 | */
13 | public class ForeachTest {
14 | public static void main(String[] args) {
15 | List list = Arrays.asList(7, 6, 9, 3, 8, 2, 1);
16 |
17 | // 遍历输出符合条件的元素
18 | list.stream().filter(x -> x > 6).forEach(System.out::println);
19 | // 匹配第一个
20 | Optional findFirst = list.stream().filter(x -> x > 6).findFirst();
21 | // 匹配任意(适用于并行流)
22 | Optional findAny = list.parallelStream().filter(x -> x > 6).findAny();
23 | // 是否包含符合特定条件的元素
24 | boolean anyMatch = list.stream().anyMatch(x -> x > 6);
25 | System.out.println("匹配第一个值:" + findFirst.get());
26 | System.out.println("匹配任意一个值:" + findAny.get());
27 | System.out.println("是否存在大于6的值:" + anyMatch);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/stream-demo/src/main/java/stream/test/MapTest.java:
--------------------------------------------------------------------------------
1 | package stream.test;
2 |
3 | import stream.model.Person;
4 |
5 | import java.util.Arrays;
6 | import java.util.List;
7 | import java.util.stream.Collectors;
8 |
9 | /**
10 | * @author muguozheng
11 | * @version 1.0.0
12 | * @createTime 2022/9/6 10:23
13 | * @description 映射测试类
14 | */
15 | public class MapTest {
16 | public static void main(String[] args) {
17 | // mapTest();
18 | // mapTest2();
19 | // mapTest3();
20 | // mapTest4();
21 | mapTest5();
22 | }
23 |
24 | /**
25 | * 英文字符串数组的元素全部改为大写。整数数组每个元素+3
26 | */
27 | public static void mapTest() {
28 | String[] strArr = {"abcd", "bcdd", "defde", "fTr"};
29 | List strList = Arrays.stream(strArr).map(String::toUpperCase).collect(Collectors.toList());
30 |
31 | List intList = Arrays.asList(1, 3, 5, 7, 9, 11);
32 | List intListNew = intList.stream().map(x -> x + 3).collect(Collectors.toList());
33 |
34 | System.out.println("每个元素大写:" + strList);
35 | System.out.println("每个元素+3:" + intListNew);
36 | }
37 |
38 | /**
39 | * 将员工的薪资全部增加1000
40 | */
41 | public static void mapTest2() {
42 | List personList = Person.assemblePersonList();
43 | // 不改变原来员工集合的方式
44 | List personListNew = personList.stream().map(person -> {
45 | Person personNew = new Person(person.getName(), 0, 0, null, null);
46 | personNew.setSalary(person.getSalary() + 10000);
47 | return personNew;
48 | }).collect(Collectors.toList());
49 | System.out.println("一次改动前:" + personList.get(0).getName() + "-->" + personList.get(0).getSalary());
50 | System.out.println("一次改动后:" + personListNew.get(0).getName() + "-->" + personListNew.get(0).getSalary());
51 |
52 | // 改变原来员工集合的方式
53 | List personListNew2 = personList.stream().map(person -> {
54 | person.setSalary(person.getSalary() + 10000);
55 | return person;
56 | }).collect(Collectors.toList());
57 | List personListNew3 = personList.stream().peek(person -> person.setSalary(person.getSalary() + 10000)).collect(Collectors.toList());
58 | System.out.println("二次改动前:" + personList.get(0).getName() + "-->" + personListNew.get(0).getSalary());
59 | System.out.println("二次改动后:" + personListNew2.get(0).getName() + "-->" + personListNew2.get(0).getSalary());
60 | System.out.println("二次改动后:" + personListNew3.get(0).getName() + "-->" + personListNew3.get(0).getSalary());
61 | }
62 |
63 | public static void mapTest3() {
64 | List list = Arrays.asList("m,k,l,a", "1,3,5,7");
65 | List listNew = list.stream().flatMap(s -> {
66 | // 将每个元素转换成一个stream
67 | String[] split = s.split(",");
68 | return Arrays.stream(split);
69 | }).collect(Collectors.toList());
70 |
71 | System.out.println("处理前的集合:" + list);
72 | System.out.println("处理后的集合:" + listNew);
73 | }
74 |
75 | public static void mapTest4() {
76 | List stringList = Arrays.asList("mu", "CSDN", "hello",
77 | "world", "quickly");
78 | stringList.stream().mapToInt(String::length).forEach(System.out::println);
79 | List integerList = Arrays.asList(4, 5, 2, 1, 6, 3);
80 | integerList.stream().mapToInt(x -> x + 1000).forEach(System.out::println);
81 | }
82 |
83 | public static void mapTest5() {
84 | List doubleList = Arrays.asList(1.0, 2.0, 3.0, 4.0, 2.0);
85 | double average = doubleList.stream().mapToDouble(Number::doubleValue).average().getAsDouble();
86 | double sum = doubleList.stream().mapToDouble(Number::doubleValue).sum();
87 | double max = doubleList.stream().mapToDouble(Number::doubleValue).max().getAsDouble();
88 | System.out.println("平均值:" + average + ",总和:" + sum + ",最大值:" + max);
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/stream-demo/src/main/java/stream/test/ReduceTest.java:
--------------------------------------------------------------------------------
1 | package stream.test;
2 |
3 | import stream.model.Person;
4 |
5 | import java.util.Arrays;
6 | import java.util.List;
7 | import java.util.Optional;
8 |
9 | /**
10 | * @author muguozheng
11 | * @version 1.0.0
12 | * @createTime 2022/9/6 10:28
13 | * @description 规约测试类
14 | */
15 | public class ReduceTest {
16 | public static void main(String[] args) {
17 | reduceTest1();
18 | reduceTest2();
19 | }
20 |
21 | public static void reduceTest1() {
22 | List list = Arrays.asList(1, 3, 2, 8, 11, 4);
23 | // 求和方式1
24 | Optional sum = list.stream().reduce((x, y) -> x + y);
25 | // 求和方式2
26 | Optional sum2 = list.stream().reduce(Integer::sum);
27 | // 求和方式3
28 | Integer sum3 = list.stream().reduce(0, Integer::sum);
29 |
30 | // 求乘积
31 | Optional product = list.stream().reduce((x, y) -> x * y);
32 |
33 | // 求最大值方式1
34 | Optional max = list.stream().reduce((x, y) -> x > y ? x : y);
35 | // 求最大值写法2
36 | Integer max2 = list.stream().reduce(1, Integer::max);
37 |
38 | System.out.println("list求和:" + sum.get() + "," + sum2.get() + "," + sum3);
39 | System.out.println("list求积:" + product.get());
40 | System.out.println("list求和:" + max.get() + "," + max2);
41 | }
42 |
43 | public static void reduceTest2() {
44 | List personList = Person.assemblePersonList();
45 | // 求工资之和方式1:
46 | Optional sumSalary = personList.stream().map(Person::getSalary).reduce(Integer::sum);
47 | // 求工资之和方式2:
48 | Integer sumSalary2 = personList.stream().reduce(0, (sum, p) -> sum += p.getSalary(), (sum1, sum2) -> sum1 + sum2);
49 | // 求工资之和方式3:
50 | Integer sumSalary3 = personList.stream().reduce(0, (sum, p) -> sum += p.getSalary(), Integer::sum);
51 |
52 | // 求最高工资方式1:
53 | Integer maxSalary = personList.stream().reduce(0, (max, p) -> max > p.getSalary() ? max : p.getSalary(),
54 | Integer::max);
55 | // 求最高工资方式2:
56 | Integer maxSalary2 = personList.stream().reduce(0, (max, p) -> max > p.getSalary() ? max : p.getSalary(),
57 | (max1, max2) -> max1 > max2 ? max1 : max2);
58 | // 求最高工资方式3:
59 | Integer maxSalary3 = personList.stream().map(Person::getSalary).reduce(Integer::max).get();
60 |
61 | System.out.println("工资之和:" + sumSalary.get() + "," + sumSalary2 + "," + sumSalary3);
62 | System.out.println("最高工资:" + maxSalary + "," + maxSalary2 + "," + maxSalary3);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/websocket-demo/.gitignore:
--------------------------------------------------------------------------------
1 | HELP.md
2 | target/
3 | !.mvn/wrapper/maven-wrapper.jar
4 | !**/src/main/**/target/
5 | !**/src/test/**/target/
6 |
7 | ### STS ###
8 | .apt_generated
9 | .classpath
10 | .factorypath
11 | .project
12 | .settings
13 | .springBeans
14 | .sts4-cache
15 |
16 | ### IntelliJ IDEA ###
17 | .idea
18 | *.iws
19 | *.iml
20 | *.ipr
21 |
22 | ### NetBeans ###
23 | /nbproject/private/
24 | /nbbuild/
25 | /dist/
26 | /nbdist/
27 | /.nb-gradle/
28 | build/
29 | !**/src/main/**/build/
30 | !**/src/test/**/build/
31 |
32 | ### VS Code ###
33 | .vscode/
34 |
--------------------------------------------------------------------------------
/websocket-demo/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ThinkMugz/springboot-demo-major/c9cb339da7d043dc7b60c09dc3c8de0e4d2d1127/websocket-demo/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/websocket-demo/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # https://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.7/apache-maven-3.8.7-bin.zip
18 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
19 |
--------------------------------------------------------------------------------
/websocket-demo/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.5.9
9 |
10 |
11 | com.mutest
12 | websocket-demo
13 | 0.0.1-SNAPSHOT
14 | websocket-demo
15 | websocket demo
16 |
17 | 8
18 |
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter
23 |
24 |
25 |
26 | org.springframework.boot
27 | spring-boot-starter-test
28 | test
29 |
30 |
31 | org.springframework.boot
32 | spring-boot-starter-websocket
33 |
34 |
35 | org.projectlombok
36 | lombok
37 |
38 |
39 |
40 |
41 |
42 |
43 | org.springframework.boot
44 | spring-boot-maven-plugin
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/websocket-demo/src/main/java/com/mutest/websocket/WebSocketApplication.java:
--------------------------------------------------------------------------------
1 | package com.mutest.websocket;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
6 | import org.springframework.scheduling.annotation.EnableScheduling;
7 |
8 | @EnableScheduling
9 | @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
10 | public class WebSocketApplication {
11 |
12 | public static void main(String[] args) {
13 | SpringApplication.run(WebSocketApplication.class, args);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/websocket-demo/src/main/java/com/mutest/websocket/config/WebSocketConfig.java:
--------------------------------------------------------------------------------
1 | package com.mutest.websocket.config;
2 |
3 | import com.mutest.websocket.handler.MyWsHandler;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.web.socket.config.annotation.EnableWebSocket;
7 | import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
8 | import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
9 |
10 | /**
11 | * @author muguozheng
12 | * @version 1.0.0
13 | * @createTime 2023/4/7 17:34
14 | * @description websocket config
15 | */
16 | @Configuration
17 | @EnableWebSocket
18 | public class WebSocketConfig implements WebSocketConfigurer {
19 | @Autowired
20 | private MyWsHandler myWsHandler;
21 |
22 | @Override
23 | public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
24 | registry
25 | .addHandler(myWsHandler, "myWs")
26 | //允许跨域
27 | .setAllowedOrigins("*");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/websocket-demo/src/main/java/com/mutest/websocket/handler/MyWsHandler.java:
--------------------------------------------------------------------------------
1 | package com.mutest.websocket.handler;
2 |
3 | import com.mutest.websocket.utlis.WsSessionManager;
4 | import lombok.extern.slf4j.Slf4j;
5 | import org.springframework.stereotype.Component;
6 | import org.springframework.web.socket.BinaryMessage;
7 | import org.springframework.web.socket.CloseStatus;
8 | import org.springframework.web.socket.TextMessage;
9 | import org.springframework.web.socket.WebSocketSession;
10 | import org.springframework.web.socket.handler.AbstractWebSocketHandler;
11 |
12 | import java.time.LocalDateTime;
13 |
14 | /**
15 | * @author muguozheng
16 | * @version 1.0.0
17 | * @createTime 2023/4/8 10:48
18 | * @description ws消息处理类
19 | */
20 | @Component
21 | @Slf4j
22 | public class MyWsHandler extends AbstractWebSocketHandler {
23 |
24 |
25 | @Override
26 | public void afterConnectionEstablished(WebSocketSession session) {
27 | log.info("建立ws连接");
28 | WsSessionManager.add(session.getId(), session);
29 | }
30 |
31 | @Override
32 | protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
33 | log.info("发送文本消息");
34 | // 获得客户端传来的消息
35 | String payload = message.getPayload();
36 | log.info("server 接收到消息 " + payload);
37 | session.sendMessage(new TextMessage("server 发送给的消息 " + payload + ",发送时间:" + LocalDateTime.now().toString()));
38 | }
39 |
40 | @Override
41 | protected void handleBinaryMessage(WebSocketSession session, BinaryMessage message) throws Exception {
42 | log.info("发送二进制消息");
43 | }
44 |
45 | @Override
46 | public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
47 | log.error("异常处理");
48 | WsSessionManager.removeAndClose(session.getId());
49 | }
50 |
51 | @Override
52 | public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
53 | log.info("关闭ws连接");
54 | WsSessionManager.removeAndClose(session.getId());
55 | }
56 |
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/websocket-demo/src/main/java/com/mutest/websocket/job/MessageJob.java:
--------------------------------------------------------------------------------
1 | package com.mutest.websocket.job;
2 |
3 | import com.mutest.websocket.service.WsService;
4 | import lombok.extern.slf4j.Slf4j;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.scheduling.annotation.Scheduled;
7 | import org.springframework.stereotype.Component;
8 |
9 | import java.io.IOException;
10 | import java.time.LocalDateTime;
11 |
12 | /**
13 | * @author muguozheng
14 | * @version 1.0.0
15 | * @createTime 2023/4/8 10:52
16 | * @description 定时生成消息
17 | */
18 | @Slf4j
19 | @Component
20 | public class MessageJob {
21 | @Autowired
22 | WsService wsService;
23 |
24 | /**
25 | * 每5s发送
26 | */
27 | @Scheduled(cron = "0/5 * * * * *")
28 | public void run() {
29 | try {
30 | log.info("推送消息===>" + LocalDateTime.now().toString());
31 | wsService.broadcastMsg("自动生成消息 " + LocalDateTime.now().toString());
32 | } catch (IOException e) {
33 | e.printStackTrace();
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/websocket-demo/src/main/java/com/mutest/websocket/service/WsService.java:
--------------------------------------------------------------------------------
1 | package com.mutest.websocket.service;
2 |
3 | import com.mutest.websocket.utlis.WsSessionManager;
4 | import lombok.extern.slf4j.Slf4j;
5 | import org.springframework.stereotype.Service;
6 | import org.springframework.web.socket.TextMessage;
7 | import org.springframework.web.socket.WebSocketSession;
8 |
9 | import java.io.IOException;
10 |
11 | /**
12 | * @author muguozheng
13 | * @version 1.0.0
14 | * @createTime 2023/4/8 10:53
15 | * @description ws操作相关服务
16 | */
17 | @Service
18 | @Slf4j
19 | public class WsService {
20 | /**
21 | * 发送消息
22 | *
23 | * @param session 连接信息
24 | * @param text 消息
25 | */
26 | public void sendMsg(WebSocketSession session, String text) throws IOException {
27 | session.sendMessage(new TextMessage(text));
28 | }
29 |
30 | /**
31 | * 广播消息
32 | *
33 | * @param text 消息
34 | */
35 | public void broadcastMsg(String text) throws IOException {
36 | for (WebSocketSession session : WsSessionManager.SESSION_POOL.values()) {
37 | session.sendMessage(new TextMessage(text));
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/websocket-demo/src/main/java/com/mutest/websocket/utlis/WsSessionManager.java:
--------------------------------------------------------------------------------
1 | package com.mutest.websocket.utlis;
2 |
3 | import lombok.extern.slf4j.Slf4j;
4 | import org.springframework.web.socket.WebSocketSession;
5 |
6 | import java.io.IOException;
7 | import java.util.concurrent.ConcurrentHashMap;
8 |
9 | /**
10 | * @author muguozheng
11 | * @version 1.0.0
12 | * @createTime 2023/4/8 10:50
13 | * @description webSocket session管理器
14 | */
15 | @Slf4j
16 | public class WsSessionManager {
17 | /**
18 | * 保存连接 session 的地方
19 | */
20 | public static ConcurrentHashMap SESSION_POOL = new ConcurrentHashMap<>();
21 |
22 | /**
23 | * 添加 session
24 | *
25 | * @param key key
26 | */
27 | public static void add(String key, WebSocketSession session) {
28 | // 添加 session
29 | SESSION_POOL.put(key, session);
30 | }
31 |
32 | /**
33 | * 删除 session,会返回删除的 session
34 | *
35 | * @param key key
36 | * @return WebSocketSession
37 | */
38 | public static WebSocketSession remove(String key) {
39 | // 删除 session
40 | return SESSION_POOL.remove(key);
41 | }
42 |
43 | /**
44 | * 删除并同步关闭连接
45 | *
46 | * @param key key
47 | */
48 | public static void removeAndClose(String key) {
49 | WebSocketSession session = remove(key);
50 | if (session != null) {
51 | try {
52 | // 关闭连接
53 | session.close();
54 | } catch (IOException e) {
55 | // todo: 关闭出现异常处理
56 | e.printStackTrace();
57 | }
58 | }
59 | }
60 |
61 | /**
62 | * 获得 session
63 | *
64 | * @param key key
65 | * @return WebSocketSession
66 | */
67 | public static WebSocketSession get(String key) {
68 | // 获得 session
69 | return SESSION_POOL.get(key);
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/websocket-demo/src/main/resources/application.yml:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ThinkMugz/springboot-demo-major/c9cb339da7d043dc7b60c09dc3c8de0e4d2d1127/websocket-demo/src/main/resources/application.yml
--------------------------------------------------------------------------------
/websocket-demo/src/test/java/com/mutest/websocket/WebSocketApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.mutest.websocket;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import org.springframework.boot.test.context.SpringBootTest;
5 |
6 | @SpringBootTest
7 | class WebSocketApplicationTests {
8 |
9 | @Test
10 | void contextLoads() {
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------