<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>Gaven的小木屋</title>
        <link>https://tangly1024.com/</link>
        <description>温故而知新</description>
        <lastBuildDate>Thu, 05 Mar 2026 23:45:51 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>en-US</language>
        <copyright>All rights reserved 2026, NotionNext</copyright>
        <item>
            <title><![CDATA[el-table]]></title>
            <link>https://tangly1024.com/article/13507eb0-166d-8005-96fb-dcf278b4b0f0</link>
            <guid>https://tangly1024.com/article/13507eb0-166d-8005-96fb-dcf278b4b0f0</guid>
            <pubDate>Tue, 05 Nov 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-13507eb0166d800596fbdcf278b4b0f0"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-13507eb0166d8103b565caf03c4418ee" data-id="13507eb0166d8103b565caf03c4418ee"><span><div id="13507eb0166d8103b565caf03c4418ee" class="notion-header-anchor"></div><a class="notion-hash-link" href="#13507eb0166d8103b565caf03c4418ee" title="第一章 el-table分页"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">第一章 el-table分页</span></span></h2><div class="notion-text notion-block-05c89320cfbe44a39b701ab0039f5dbd">在 el-table 中使用分页功能可以通过以下步骤实现：</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-f56f24b0a43147ce91b4d3f228b871fe" data-id="f56f24b0a43147ce91b4d3f228b871fe"><span><div id="f56f24b0a43147ce91b4d3f228b871fe" class="notion-header-anchor"></div><a class="notion-hash-link" href="#f56f24b0a43147ce91b4d3f228b871fe" title="1. 引入 el-pagination 组件"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">1. 引入 el-pagination 组件</span></span></h4><div class="notion-text notion-block-0ffa8f92a03e4311b425223230df9d15">首先，确保在你的项目中已经引入了 Element UI 的 el-pagination 组件。</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-7263d1d130f44590868b2a34d023c89d" data-id="7263d1d130f44590868b2a34d023c89d"><span><div id="7263d1d130f44590868b2a34d023c89d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#7263d1d130f44590868b2a34d023c89d" title="2. 在模板中添加 el-pagination"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2. 在模板中添加 el-pagination</span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-f1c900dc5ece42dd961bfb8875ce024b" data-id="f1c900dc5ece42dd961bfb8875ce024b"><span><div id="f1c900dc5ece42dd961bfb8875ce024b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#f1c900dc5ece42dd961bfb8875ce024b" title="3. 在 script 中添加相关数据和方法"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3. 在 script 中添加相关数据和方法</span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-7de0ac8115254b9d93d4a46ded0f70e3" data-id="7de0ac8115254b9d93d4a46ded0f70e3"><span><div id="7de0ac8115254b9d93d4a46ded0f70e3" class="notion-header-anchor"></div><a class="notion-hash-link" href="#7de0ac8115254b9d93d4a46ded0f70e3" title="4. 实现 fetchData 方法"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4. 实现 fetchData 方法</span></span></h4><div class="notion-text notion-block-72dfc52b18054481808a478b2408de22">在 fetchData 方法中，你需要根据 currentPage 和 pageSize 从后端获取数据。这通常涉及发送一个 API 请求，并在响应中更新 tableData 和 total。</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-eabac7db77ef4d26909dc7516feb0bfe" data-id="eabac7db77ef4d26909dc7516feb0bfe"><span><div id="eabac7db77ef4d26909dc7516feb0bfe" class="notion-header-anchor"></div><a class="notion-hash-link" href="#eabac7db77ef4d26909dc7516feb0bfe" title="5. 注意事项"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">5. 注意事项</span></span></h4><ul class="notion-list notion-list-disc notion-block-f89b7535ff9447f6b324a1b5d4e10696"><li>确保后端 API 支持分页，通常需要接收 page 和 pageSize 参数。</li></ul><ul class="notion-list notion-list-disc notion-block-3b8fc3872fe34c178de080b7c9717100"><li>后端返回的数据中应包含总条数（total），用于设置分页组件的总数。</li></ul><ul class="notion-list notion-list-disc notion-block-d61341dfc7364480a8888b7f371bf5fa"><li>每次改变页码或每页显示数量时，都应该重新获取数据。</li></ul><div class="notion-text notion-block-32c9da7054964785a37cb2beae2d631d">通过以上步骤，你可以在 el-table 中实现分页功能，使得大量数据可以分页显示，提高用户体验和页面性能。</div><div class="notion-blank notion-block-13507eb0166d80eaa27de0b7ce99b99a"> </div><div class="notion-text notion-block-13507eb0166d809186f7c002d85c9647">  对于DSP大数据平台是需要携带PageSize和PageNum参数，sql执行后平台会将返回值封装成一个data对象，除了rows数据外，还会有totalNum、pageNum、pageSize属性，这样每当前端分页组件发生变化触发事件就会重新调用接口方法，携带参数，并获得到与该参数信息相对应的列表数据，在前端表格上展示。</div><div class="notion-text notion-block-13507eb0166d80379d87dbe3bbea6275">  那对于提供分页的接口来说，则需要在前端或者后端进行手动分页，对于少量的数据可以在前端进行分页，可以通过逻辑判断的方式来获取应该展示的数据：</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-13507eb0166d807d947bcd60d166e9a9"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:499px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F80e4c4d4-68f7-49db-9934-32ee42376dbb%2Fa90cc983-6f1d-42ca-b321-08549df03109%2Fimage.png?table=block&amp;id=13507eb0-166d-807d-947b-cd60d166e9a9&amp;t=13507eb0-166d-807d-947b-cd60d166e9a9&amp;width=499&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-13507eb0166d80ad9d60ccc78d278684">  后端分页可以在mysql中使用limit关键字采用上述前端判断的逻辑进行截取</div><div class="notion-text notion-block-13507eb0166d80b99201d808e6e9678a"><code class="notion-inline-code">page=(page-1)*pageSize </code></div><div class="notion-text notion-block-13507eb0166d809d9499de029da873e6"><code class="notion-inline-code">select ......     limit #{page},#{pageSize}</code></div><div class="notion-text notion-block-13507eb0166d80ddaac7d6147d5cd356">使用Mybatis-PageHelper</div><div class="notion-text notion-block-13507eb0166d807ca3b1c70a69b22741">该插件可以先让我们在dao层查询出列表后，过滤后再进行分页
第一步:设置分页</div><div class="notion-text notion-block-13507eb0166d8063844dfd03bf9d2a92"><code class="notion-inline-code">//注意这里的page不需要进行计算，直接使用前端传过来的数据</code>
<code class="notion-inline-code">PageHelper.startPage(page,pageSize);</code>
第二步：从dao层获取list列表数据并自行过滤</div><div class="notion-text notion-block-13507eb0166d80be9142f3a47f912c8d"><code class="notion-inline-code">List&lt;User&gt; list=userDao.getUserByAge(int age);</code>
第三步：分页封装</div><div class="notion-text notion-block-13507eb0166d809eab99c77ecc379b5c"><code class="notion-inline-code">PageInfo&lt;User&gt; pageInfo=new PageInfo&lt;&gt;(list);</code></div><div class="notion-text notion-block-13507eb0166d80baaf7be279f21293e1">第四步:在service中对list进行拆分</div><div class="notion-text notion-block-13507eb0166d809e9649f14c456f938e">使用<code class="notion-inline-code">list</code>的<code class="notion-inline-code">api</code>进行分页</div><div class="notion-text notion-block-13507eb0166d80a19c2ed2d6e7424fee"><code class="notion-inline-code">int size = list.size();
if (size % pageSize!= 0){
size = size / pageSize+ 1;
if(page == size){
list = list.subList((page - 1) * pageSize,list.size());
}else {
list = list.subList((page - 1) * pageSize,page * pageSize);
}
map.put(&quot;pages&quot;,size);
map.put(&quot;current&quot;,page);
}else {
if(size!=0)
list = list.subList((page - 1) * pageSize,page * pageSize);
map.put(&quot;current&quot;,page);
map.put(&quot;pages&quot;,size/pageSize);
}</code></div><div class="notion-text notion-block-13507eb0166d806c90a8e48e461f8deb"><b>MP官方插件</b></div><div class="notion-text notion-block-13507eb0166d803e865ee799fc5254b0"><code class="notion-inline-code">@Configuration
public class MybatisPlusConfig {
/*
* 分页插件，自动识别数据库类型 多租户，请参考官网【插件扩展】
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
}</code></div><div class="notion-text notion-block-13507eb0166d80ac9dd5ee940927cbf5">使用MP封装的查询API
第一步：创建一个Page对象(不用进行计算，继续使用前端传过来的数据)</div><div class="notion-text notion-block-13507eb0166d8019abcfe5cb12aff959"><code class="notion-inline-code">IPage&lt;User&gt; userPage = new Page&lt;&gt;(page, pageSize);//参数一是当前页，参数二是每页个数</code>
第二步：调用官方API</div><div class="notion-text notion-block-13507eb0166d8042a9aec61dc1333a59"><code class="notion-inline-code">userPage = userMapper.selectPage(userPage, null);</code>
第三步：获取page中的数据</div><div class="notion-text notion-block-13507eb0166d809fa8e9e3c9e52fa084"><code class="notion-inline-code">List&lt;User&gt; list = userPage.getRecords();</code></div><div class="notion-blank notion-block-13507eb0166d80788c7df8c098f0562d"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vue3拆分组件——父子传值]]></title>
            <link>https://tangly1024.com/article/12107eb0-166d-80a4-8096-ce5ccbf5c0db</link>
            <guid>https://tangly1024.com/article/12107eb0-166d-80a4-8096-ce5ccbf5c0db</guid>
            <pubDate>Wed, 16 Oct 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-12107eb0166d80a48096ce5ccbf5c0db"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-callout notion-gray_background_co notion-block-12107eb0166d819db576cf2862831ab2"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="😀">😀</span></div><div class="notion-callout-text">最近在试着把之前写的前端代码拆分成可复用的组件以减少冗余代码和解耦，而拆分组件时遇到的第一个事情就是传值问题。</div></div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-12107eb0166d8133a7bfc36cb642842d" data-id="12107eb0166d8133a7bfc36cb642842d"><span><div id="12107eb0166d8133a7bfc36cb642842d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#12107eb0166d8133a7bfc36cb642842d" title="一、父传子（通过props方式传值）"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">一、父传子（通过props方式传值）</span></span></h3><div class="notion-text notion-block-12107eb0166d80c6a127c5ec83b89468">1.在子组件中定义要传参的变量</div><div class="notion-text notion-block-a0fa92b4760b46df9cecbe55aa191781">2.在父组件中使用子组件并传递参数</div><div class="notion-text notion-block-c9d200c4c1054cc7b13034b2123d40c2">这样，父组件就成功地将 &quot;Hello from parent!&quot; 这个消息传递给了子组件。子组件通过 props 接收到这个消息并显示出来。</div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-12107eb0166d813e9e3ec86323cdc765" data-id="12107eb0166d813e9e3ec86323cdc765"><span><div id="12107eb0166d813e9e3ec86323cdc765" class="notion-header-anchor"></div><a class="notion-hash-link" href="#12107eb0166d813e9e3ec86323cdc765" title="二、子传父（通过事件）"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">二、子传父（通过事件）</span></span></h3><ol start="1" class="notion-list notion-list-numbered notion-block-213bdfaef5dc4dd8b8d73b9d10b33afb" style="list-style-type:decimal"><li>在子组件中定义一个方法，并通过 emit 触发一个事件</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-0e4c8c5e45924ab490f50e2d364fffd3" style="list-style-type:decimal"><li>在父组件中监听子组件触发的事件</li></ol><div class="notion-text notion-block-2c1646547b834949a0faac5810f84a04">在这个例子中，子组件通过 emit(&#x27;update&#x27;, count.value) 触发了一个名为 &#x27;update&#x27; 的事件，并将新的计数值作为参数传递。父组件通过 @update=&quot;handleUpdate&quot; 监听这个事件，并在 handleUpdate 方法中更新自己的状态。</div><div class="notion-text notion-block-12107eb0166d816dbc4fcc9a43091529">
• <b>问题：</b> 当父组件传递给子组件的值发生改变后，子组件不能立刻改变的问题。如下图代码所示，子组件的<code class="notion-inline-code">loading</code>变量没有发生改变。</div><div class="notion-text notion-block-12107eb0166d80d093fbffda9086d0c5">
• <b>原因：</b> 原因是接收父组件传递的值赋值在<code class="notion-inline-code">props</code>变量里，而<code class="notion-inline-code">loading</code>变量拷贝了<code class="notion-inline-code">props[&quot;process&quot;]</code>的值后，不会再关联<code class="notion-inline-code">props</code>的改变。</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-12107eb0166d80ec9dd6c297a74302eb" data-id="12107eb0166d80ec9dd6c297a74302eb"><span><div id="12107eb0166d80ec9dd6c297a74302eb" class="notion-header-anchor"></div><a class="notion-hash-link" href="#12107eb0166d80ec9dd6c297a74302eb" title="使用computed"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">使用<code class="notion-inline-code">computed</code></span></span></h4><div class="notion-text notion-block-12107eb0166d8086afa7c6b96bcd21cf">给<code class="notion-inline-code">loading</code>变量使用<code class="notion-inline-code">computed</code>属性，同步<code class="notion-inline-code">computed[&quot;process&quot;]</code>的变化。</div><ul class="notion-list notion-list-disc notion-block-12107eb0166d801d82c4de64fb6cd5f2"><li><b>修改后代码：</b></li></ul><div class="notion-blank notion-block-12107eb0166d80338adbe883177d330a"> </div><div class="notion-text notion-block-12107eb0166d808b8431fd115e273525">掘金链接：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://juejin.cn/post/7373216827013513227">https://juejin.cn/post/7373216827013513227</a></div><div class="notion-blank notion-block-12107eb0166d80218fbcc55d5895184f"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[浅谈DTO、VO的区别]]></title>
            <link>https://tangly1024.com/article/11607eb0-166d-8009-bff1-f53731ca38e0</link>
            <guid>https://tangly1024.com/article/11607eb0-166d-8009-bff1-f53731ca38e0</guid>
            <pubDate>Sat, 05 Oct 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-11607eb0166d8009bff1f53731ca38e0"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-text notion-block-11807eb0166d8083abbfebef3aa6a516"><b>PO/DO数据库对应类：nameDO
DTO接收前端传入参数：DTO
VO后端响应给前端：用到的页面NameVo
统称为POJO </b> </div><div class="notion-text notion-block-dcf64f6a723b44a3a54bc47ec8fd2318">在这个例子中：</div><ul class="notion-list notion-list-disc notion-block-7061e2aca6714f41aea9b3b42a869500"><li><b>OrderEntity</b>：代表数据库中的订单表，包含所有订单相关的字段。</li></ul><ul class="notion-list notion-list-disc notion-block-6526426870c64b9385bc9558f62016f7"><li><b>OrderDTO</b>：用于在应用程序的不同层之间传输订单数据，可能省略了一些敏感或不必要的字段。</li></ul><ul class="notion-list notion-list-disc notion-block-9fdaf93aeea44a209ffb936ade691a16"><li><b>OrderVO</b>：专门用于在用户界面展示订单信息，包含了格式化后的日期和金额，以及更易读的状态描述。</li></ul><div class="notion-text notion-block-2c8db563121f486c994efa8e1ca3928c">这种设计允许我们在不同的层次和场景中使用最合适的对象，提高了代码的清晰度和可维护性。</div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java8新特性]]></title>
            <link>https://tangly1024.com/article/10c07eb0-166d-80f7-9b57-f6a8cd288f6d</link>
            <guid>https://tangly1024.com/article/10c07eb0-166d-80f7-9b57-f6a8cd288f6d</guid>
            <pubDate>Wed, 25 Sep 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-10c07eb0166d80f79b57f6a8cd288f6d"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-callout notion-gray_background_co notion-block-fff07eb0166d81939c25f644b0e572f1"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="😀">😀</span></div><div class="notion-callout-text">Java 8作为Java语言的一个重要更新，引入了一系列新特性，这些特性不仅提高了代码的可读性和可维护性，还增强了程序的性能。本文将详细介绍Java 8中的几个关键使用技巧，并通过代码案例来展示它们的应</div></div><div class="notion-blank notion-block-fff07eb0166d814f82efce3589e17a57"> </div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-fff07eb0166d8125b563fa1d912847b4" data-id="fff07eb0166d8125b563fa1d912847b4"><span><div id="fff07eb0166d8125b563fa1d912847b4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#fff07eb0166d8125b563fa1d912847b4" title="📝 主旨内容"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">📝 主旨内容</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-fff07eb0166d813c9dcde9c99b32ce6b" data-id="fff07eb0166d813c9dcde9c99b32ce6b"><span><div id="fff07eb0166d813c9dcde9c99b32ce6b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#fff07eb0166d813c9dcde9c99b32ce6b" title="一、Lambda表达式"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>一、Lambda表达式</b></span></span></h3><blockquote class="notion-quote notion-block-fff07eb0166d8168b516ebbac37022a4"><div>首先，第一个要介绍的是Lambda。Lambda表达式是Java 8中最引人注目的新特性之一。它们提供了一种简洁的方式来表示匿名函数，从而简化了代码逻辑。代码案例如下：</div></blockquote><div class="notion-text notion-block-646ea8391313455db8e1579f384186b8">在上面的代码中，我们展示了Lambda表达式在不同场景下的应用：</div><ul class="notion-list notion-list-disc notion-block-0758dbe764e84fadac6554a5b0a208b3"><li>用于列表排序，简化了Comparator的实现。</li></ul><ul class="notion-list notion-list-disc notion-block-d651564e075545768d727825179cd1f6"><li>实现函数式接口，使得创建匿名内部类变得更加简洁。</li></ul><ul class="notion-list notion-list-disc notion-block-b62a7f8890074f76a563754015e245c2"><li>用于集合遍历，替代了传统的for循环，使代码更加清晰。</li></ul><div class="notion-text notion-block-eeb8354c4b0c4d44b63afa45afb5b3c6">Lambda表达式的使用大大提高了代码的可读性和简洁性，尤其在处理集合、多线程等场景时，能够显著减少代码量。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-fff07eb0166d81af82a0f97407109793" data-id="fff07eb0166d81af82a0f97407109793"><span><div id="fff07eb0166d81af82a0f97407109793" class="notion-header-anchor"></div><a class="notion-hash-link" href="#fff07eb0166d81af82a0f97407109793" title="二、Stream API"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>二、Stream API</b></span></span></h3><blockquote class="notion-quote notion-block-d56a6103ceee46ceb3ec9f1b6f2fe55c"><div>Stream API是Java 8引入的另一个重要特性，它提供了一种声明式的方法来处理数据集合。Stream API允许我们以一种更加简洁和函数式的方式来操作集合，大大提高了代码的可读性和效率。以下是Stream API的一些主要特点和使用示例：</div></blockquote><div class="notion-text notion-block-875fd89d078d48ce866eca9d93b4ae97">在上面的代码中，我们展示了Stream API的几个常见用法：</div><ul class="notion-list notion-list-disc notion-block-8ee57e0b449c45efb8107009344c2bd4"><li>使用filter()方法进行数据过滤</li></ul><ul class="notion-list notion-list-disc notion-block-63a7ea8a8f6e47dfae8317995bb14984"><li>使用map()方法进行数据转换</li></ul><ul class="notion-list notion-list-disc notion-block-5cc9c194933e4e66a514856e63260bcb"><li>使用collect()方法将结果收集到新的集合中</li></ul><ul class="notion-list notion-list-disc notion-block-774255e32c5648768a394ff2905f89fe"><li>使用parallelStream()进行并行处理，提高性能</li></ul><div class="notion-text notion-block-2d983a100e6d4306b6dfc82c1d713564">Stream API的使用不仅使代码更加简洁，还提高了处理大量数据时的效率。它特别适合用于复杂的数据处理操作，如过滤、映射、归约等。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-10c07eb0166d80b49268f3aa6cc65d8a" data-id="10c07eb0166d80b49268f3aa6cc65d8a"><span><div id="10c07eb0166d80b49268f3aa6cc65d8a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#10c07eb0166d80b49268f3aa6cc65d8a" title="三、Optional类"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>三、Optional类</b></span></span></h3><blockquote class="notion-quote notion-block-5afd3dc8fe2e45dd83d41cff36ade1a3"><div>Optional类是Java 8引入的一个新的容器类，用于解决空指针异常（NullPointerException）问题。它可以包含一个非空值，也可以不包含任何值。Optional类提供了一种更优雅的方式来处理可能为null的对象，从而提高代码的健壮性。以下是Optional类的一些主要特点和使用示例：</div></blockquote><div class="notion-text notion-block-da442fe7f5f7427ba2579d20df08bf30">在上面的代码中，我们展示了Optional类的几个常见用法：</div><ul class="notion-list notion-list-disc notion-block-78178b4adcb34e71b45e7a9d9fc073e9"><li>使用of()和ofNullable()方法创建Optional对象</li></ul><ul class="notion-list notion-list-disc notion-block-6ce3ade32bdf415ab8c79f471ea58b9c"><li>使用isPresent()方法检查值是否存在</li></ul><ul class="notion-list notion-list-disc notion-block-44e998a5488040cca61f5a20a3c0bc37"><li>使用orElse()方法提供默认值</li></ul><ul class="notion-list notion-list-disc notion-block-a628ded9eb8f496db3591571700d1362"><li>使用map()方法转换Optional中的值</li></ul><ul class="notion-list notion-list-disc notion-block-2b59722a7c9344a3b48d8a2b813c0877"><li>使用filter()方法过滤Optional中的值</li></ul><div class="notion-text notion-block-b5f3cc268a9e43b08b7a4c2c629f9586">Optional类的使用可以有效减少代码中的null检查，使代码更加简洁和安全。它特别适用于返回值可能为null的方法，以及在链式调用中处理可能为null的中间结果。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-10c07eb0166d80a5956bc2695671ae81" data-id="10c07eb0166d80a5956bc2695671ae81"><span><div id="10c07eb0166d80a5956bc2695671ae81" class="notion-header-anchor"></div><a class="notion-hash-link" href="#10c07eb0166d80a5956bc2695671ae81" title="四、接口中的默认方法"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>四、接口中的默认方法</b></span></span></h3><blockquote class="notion-quote notion-block-1da4897a6f234924ac7ffbb7c4768190"><div>Java 8引入了接口默认方法的概念，允许在接口中定义具有默认实现的方法。这个特性使得接口能够在不破坏现有实现的情况下进行扩展，增加了接口的灵活性。以下是接口默认方法的一些主要特点和使用示例：</div></blockquote><div class="notion-text notion-block-da14d32b89c7472ebc047f7ac9f4d704">在上面的代码中，我们展示了接口默认方法的几个关键特点：</div><ul class="notion-list notion-list-disc notion-block-96834df3bd3540fabab583724801de06"><li>接口可以包含具有默认实现的方法（使用default关键字）</li></ul><ul class="notion-list notion-list-disc notion-block-e61075d4ac9946dcb47dc048695e1474"><li>实现类可以选择是否覆盖默认方法</li></ul><ul class="notion-list notion-list-disc notion-block-b8c9d79ed2da4317bd30e864b877c593"><li>接口还可以包含静态方法</li></ul><div class="notion-text notion-block-0c8bd35d678140af8eda1c4b91416e80">接口默认方法的引入使得接口的设计更加灵活，允许在不影响现有实现的情况下向接口添加新功能。这对于库的设计者特别有用，因为他们可以在不破坏向后兼容性的情况下扩展接口。然而，使用时需要注意可能出现的多重继承问题，即当一个类实现多个具有相同默认方法的接口时，需要明确指定使用哪个接口的实现。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-10c07eb0166d80b2a858f8e1d5f12dee" data-id="10c07eb0166d80b2a858f8e1d5f12dee"><span><div id="10c07eb0166d80b2a858f8e1d5f12dee" class="notion-header-anchor"></div><a class="notion-hash-link" href="#10c07eb0166d80b2a858f8e1d5f12dee" title="五、日期和时间API"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>五、日期和时间API</b></span></span></h3><blockquote class="notion-quote notion-block-5c02b0a30d734459b07a6fea324d54e0"><div>Java 8引入了新的日期和时间API，位于java.time包下。这个新API解决了旧的java.util.Date和java.util.Calendar API的许多问题，提供了更加简洁、不可变和线程安全的类。以下是新日期和时间API的一些主要特点和使用示例：</div></blockquote><div class="notion-text notion-block-a11c3093ca154251a3ba0685fe28957e">在上面的代码中，我们展示了新日期和时间API的几个主要特点：</div><ul class="notion-list notion-list-disc notion-block-383c57ebd9c34824aeb4c11ac134275a"><li>使用LocalDate、LocalTime和LocalDateTime类分别表示日期、时间和日期时间</li></ul><ul class="notion-list notion-list-disc notion-block-5d73a961b57d4c258c0d158bd1a2fa46"><li>日期和时间的操作变得更加简单和直观</li></ul><ul class="notion-list notion-list-disc notion-block-1622b49187e84d2485f30dc526c7a99e"><li>使用DateTimeFormatter进行日期时间的格式化和解析</li></ul><ul class="notion-list notion-list-disc notion-block-b6e21e02c8a848c393a211088aaf1bc4"><li>所有的类都是不可变的，确保了线程安全</li></ul><div class="notion-text notion-block-c46b58a9b0f7458491f9e5a2f5415e9e">新的日期和时间API不仅使用起来更加方便，还解决了旧API中的许多问题，如线程安全性和易用性。它特别适用于需要精确时间操作的应用，如日程安排、事件记录等场景。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-10c07eb0166d80a5b8cfe84cd2187e20" data-id="10c07eb0166d80a5b8cfe84cd2187e20"><span><div id="10c07eb0166d80a5b8cfe84cd2187e20" class="notion-header-anchor"></div><a class="notion-hash-link" href="#10c07eb0166d80a5b8cfe84cd2187e20" title="六、并行流"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>六、并行流</b></span></span></h3><blockquote class="notion-quote notion-block-57ec81c4a1a241008ef078e4917bd6b7"><div>并行流是Java 8引入的一个强大特性，它允许我们利用多核处理器的能力来并行执行流操作。并行流可以显著提高处理大量数据时的性能。以下是并行流的一些主要特点和使用示例：</div></blockquote><div class="notion-text notion-block-dbab512246df4fb0853006104bbd79cb">在上面的代码中，我们展示了并行流的基本用法：</div><ul class="notion-list notion-list-disc notion-block-a2846edeb8a04be891b94a5abfe8e366"><li>使用parallelStream()方法创建并行流</li></ul><ul class="notion-list notion-list-disc notion-block-1043fc15e04043e59b3318fa68ba0bea"><li>对比了顺序流和并行流的执行时间</li></ul><div class="notion-text notion-block-b400285399d0429887c551c43f5d66f0">并行流的主要优点包括：</div><ul class="notion-list notion-list-disc notion-block-b7fb628419ef4a3d91f6495400553371"><li>利用多核处理器提高性能</li></ul><ul class="notion-list notion-list-disc notion-block-70ab7cf8f0494f77bdd8cf1037d78744"><li>适用于大数据集的处理</li></ul><ul class="notion-list notion-list-disc notion-block-96fdaa95ac6e4d13ba1cb67542511913"><li>可以轻松地从顺序流转换为并行流</li></ul><div class="notion-text notion-block-b8f484e1149643669402e02ff8638912">然而，使用并行流时也需要注意一些潜在的问题：</div><ul class="notion-list notion-list-disc notion-block-9258caef4d6241669fa05176f5fc41cf"><li>并不是所有操作都适合并行化，有些操作可能在并行时反而更慢</li></ul><ul class="notion-list notion-list-disc notion-block-8826b83f966c43389634a24458fdb54f"><li>并行流可能导致线程安全问题，特别是在使用有状态操作时</li></ul><ul class="notion-list notion-list-disc notion-block-e29f9c18f30146c79cf7c8cda7019a05"><li>对于小数据集，并行流的开销可能会超过其带来的性能提升</li></ul><div class="notion-text notion-block-77fe5f8a1cd64ae7bde2783502ad1846">总的来说，并行流是一个强大的工具，但需要根据具体情况谨慎使用，以确保它能真正提高程序的性能。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-10c07eb0166d803e90bed6784063f52d" data-id="10c07eb0166d803e90bed6784063f52d"><span><div id="10c07eb0166d803e90bed6784063f52d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#10c07eb0166d803e90bed6784063f52d" title="七、类型推断：简化泛型实例化"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>七、类型推断：简化泛型实例化</b></span></span></h3><div class="notion-text notion-block-d5d8917f47624095a466df7db2eb705f">Java 8引入了类型推断的改进，特别是在泛型实例化方面。这个特性允许编译器自动推断泛型类型，从而简化了代码。以下是类型推断的主要特点和使用示例：</div><div class="notion-text notion-block-a5ca289c7b374060821f04a9073913b4">在上面的例子中，我们可以看到：</div><ul class="notion-list notion-list-disc notion-block-39a8be7abb6648a7bc7013963e8f1e54"><li>使用菱形操作符 &lt;&gt; 可以省略右侧的类型参数</li></ul><ul class="notion-list notion-list-disc notion-block-415c2da9c2d246f3936c6252f06129f3"><li>编译器能够根据左侧的声明自动推断出正确的类型</li></ul><div class="notion-text notion-block-4b435cdf5f8a44e2b0b9e36b103fe813">类型推断的优势包括：</div><ul class="notion-list notion-list-disc notion-block-30fc0a9183004aaf8422bcd479123102"><li>减少代码冗余，提高可读性</li></ul><ul class="notion-list notion-list-disc notion-block-9c3043b5165d44f2ad44504a564aca53"><li>简化泛型的使用，使代码更加简洁</li></ul><ul class="notion-list notion-list-disc notion-block-a3f00484faa64035b9f0a51b1e1f781f"><li>减少因手动指定类型而可能产生的错误</li></ul><div class="notion-text notion-block-442fdd815d4c44eab2b79c1a4b68519b">类型推断不仅限于集合类，它也适用于其他泛型类和方法。例如：</div><div class="notion-text notion-block-90e37bfae2a9489f8903ead97a53290e">虽然类型推断大大简化了代码，但在某些复杂的情况下，显式指定类型仍然是必要的，以确保代码的清晰性和正确性。总的来说，类型推断是Java 8中一个小但有用的改进，它使得泛型的使用更加方便和直观。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-11807eb0166d803ca642c39190eb43c7" data-id="11807eb0166d803ca642c39190eb43c7"><span><div id="11807eb0166d803ca642c39190eb43c7" class="notion-header-anchor"></div><a class="notion-hash-link" href="#11807eb0166d803ca642c39190eb43c7" title="根据 Person 对象的 age 属性进行排序。
"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">根据 <code class="notion-inline-code">Person</code> 对象的 <code class="notion-inline-code">age</code> 属性进行排序。
</span></span></h3><div class="notion-text notion-block-11807eb0166d80ab8dabc449deb68f02"> people.sort(Comparator.comparingInt(Person::getAge));</div><ul class="notion-list notion-list-disc notion-block-11807eb0166d80eaadfbe0a28d49a2e6"><li><code class="notion-inline-code">Comparator.comparingInt(Person::getAge)</code> 创建了一个比较器，该比较器根据 <code class="notion-inline-code">Person</code> 对象的 <code class="notion-inline-code">age</code> 属性进行比较。</li></ul><ul class="notion-list notion-list-disc notion-block-11807eb0166d8034b7d7c4769dc09601"><li><code class="notion-inline-code">people.sort(...)</code> 方法使用这个比较器对 <code class="notion-inline-code">people</code> 列表进行排序。</li></ul><ul class="notion-list notion-list-disc notion-block-11807eb0166d807bb3dff37469c334a4"><li><code class="notion-inline-code">Person::getAge</code> 是一个方法引用，它等价于 <code class="notion-inline-code">p -&gt; p.getAge()</code>，这是一个lambda表达式，表示从 <code class="notion-inline-code">Person</code> 对象中提取 <code class="notion-inline-code">age</code> 属性</li></ul><div class="notion-text notion-block-11807eb0166d809ba9d3f6d128bebcdb"><b>按字符串属性排序</b></div><div class="notion-text notion-block-11807eb0166d808e9d40d1c79d9f8665">// 按名字排序
people.sort(Comparator.comparing(Person::getName));</div><div class="notion-text notion-block-11807eb0166d80aab5afc793d837b4c5"><b>降序排序</b></div><div class="notion-text notion-block-11807eb0166d802f8b7ed275b8d785a4">// 按年龄降序排序
people.sort(Comparator.comparingInt(Person::getAge).reversed());</div><div class="notion-text notion-block-11807eb0166d80cd8ddceeaa0c02dd9e">// 按名字降序排序
people.sort(Comparator.comparing(Person::getName).reversed());</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-fff07eb0166d81d8b16dee27687dfdd4" data-id="fff07eb0166d81d8b16dee27687dfdd4"><span><div id="fff07eb0166d81d8b16dee27687dfdd4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#fff07eb0166d81d8b16dee27687dfdd4" title="🤗 总结归纳"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">🤗 总结归纳</span></span></h2><div class="notion-text notion-block-eaf07c70f1824a568eef7d0dc433e3bc">本文详细介绍了Java 8引入的几个关键新特性和使用技巧：</div><ul class="notion-list notion-list-disc notion-block-bd1c26e754ea41da9bb120521b015893"><li>Lambda表达式：提供了一种简洁的方式来表示匿名函数，简化了代码逻辑。</li></ul><ul class="notion-list notion-list-disc notion-block-4ea875fe80824233856dddab55f966d0"><li>接口默认方法：允许在接口中添加具有默认实现的方法，增加了接口设计的灵活性。</li></ul><ul class="notion-list notion-list-disc notion-block-1504f13b825b40139df50ac5367adbf8"><li>新的日期和时间API：引入了更简洁、不可变和线程安全的日期时间类，解决了旧API的许多问题。</li></ul><ul class="notion-list notion-list-disc notion-block-b65ebf45f2314ebba93878ac78d696b4"><li>并行流：利用多核处理器能力并行执行流操作，提高大数据集处理性能。</li></ul><ul class="notion-list notion-list-disc notion-block-4b566d7732c348438c6227c87649bce6"><li>类型推断：简化了泛型实例化，减少代码冗余，提高可读性。</li></ul><div class="notion-text notion-block-d5273e2c459e4d718b5fbd58f5ef6e91">这些新特性不仅提高了代码的可读性和可维护性，还增强了程序的性能。它们为Java开发者提供了更强大、更灵活的工具，使得编写高效、简洁的代码变得更加容易。然而，在使用这些新特性时，开发者也需要注意潜在的陷阱和最佳实践，以充分发挥它们的优势。</div><div class="notion-blank notion-block-fff07eb0166d81219492e7ebe0b80845"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[实现数据导出Excel功能]]></title>
            <link>https://tangly1024.com/article/10e07eb0-166d-8070-88a4-d5a704fccf4d</link>
            <guid>https://tangly1024.com/article/10e07eb0-166d-8070-88a4-d5a704fccf4d</guid>
            <pubDate>Fri, 27 Sep 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-10e07eb0166d807088a4d5a704fccf4d"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-callout notion-gray_background_co notion-block-10e07eb0166d81a19e04c6d5c476931a"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="😀">😀</span></div><div class="notion-callout-text">钢轧二期智慧质量晨会看板的质量体系界面需要实现数据的Excel导出功能：用户在前端点击导出按钮后，页面将显示已下载的Excel文件。</div></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-10e07eb0166d81b192cbc5ce15098c75" data-id="10e07eb0166d81b192cbc5ce15098c75"><span><div id="10e07eb0166d81b192cbc5ce15098c75" class="notion-header-anchor"></div><a class="notion-hash-link" href="#10e07eb0166d81b192cbc5ce15098c75" title="📝 前端部分"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">📝 前端部分</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-10e07eb0166d814a8bc0fabac14e23bd" data-id="10e07eb0166d814a8bc0fabac14e23bd"><span><div id="10e07eb0166d814a8bc0fabac14e23bd" class="notion-header-anchor"></div><a class="notion-hash-link" href="#10e07eb0166d814a8bc0fabac14e23bd" title="1.exportExcel通用方法"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">1.exportExcel通用方法</span></span></h3><ol start="1" class="notion-list notion-list-numbered notion-block-10e07eb0166d80fd83c8c2f69e5f1a48" style="list-style-type:decimal"><li><b>baseUrl</b>：从环境变量 <code class="notion-inline-code">process.env.VUE_APP_BASE_API</code> 获取基础 API 地址，这通常在 <code class="notion-inline-code">.env</code> 文件中定义。</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-10e07eb0166d808cbcb7cfc707ce0afa" style="list-style-type:decimal"><li><b>ParamsType</b>：这是一个 TypeScript 类型定义，表示参数对象，其中键是字符串类型，值可以是任何类型。</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-10e07eb0166d80f085fbdf4ff5ae7ef4" style="list-style-type:decimal"><li><b>excel 函数</b>：</li><ol class="notion-list notion-list-numbered notion-block-10e07eb0166d80f085fbdf4ff5ae7ef4" style="list-style-type:lower-alpha"><ul class="notion-list notion-list-disc notion-block-10e07eb0166d80309f6dc8e8956972d8"><li>接受两个参数：<code class="notion-inline-code">path</code>（API 路径）和 <code class="notion-inline-code">params</code>（请求参数）。</li></ul><ul class="notion-list notion-list-disc notion-block-10e07eb0166d800594b2f606012c2c10"><li>使用 <code class="notion-inline-code">axios</code> 发起一个 GET 请求到指定的 URL，同时传递参数 <code class="notion-inline-code">params</code> 和响应类型设置为 <code class="notion-inline-code">blob</code>（二进制大对象），这意味着服务器返回的数据将被视为二进制数据。</li></ul><ul class="notion-list notion-list-disc notion-block-10e07eb0166d80bfa51dc1fbc5b5f4d2"><li>在请求头中添加了 <code class="notion-inline-code">Authorization</code> 字段，其值由 <code class="notion-inline-code">Bearer</code> 和通过 <code class="notion-inline-code">getToken()</code> 函数获取的令牌组成，用于身份验证。</li></ul><ul class="notion-list notion-list-disc notion-block-10e07eb0166d808bb847c0499b880be7"><li>当请求成功时，从响应头部 <code class="notion-inline-code">content-disposition</code> 中提取文件名，并创建一个新的 <code class="notion-inline-code">Blob</code> 对象。</li></ul><ul class="notion-list notion-list-disc notion-block-10e07eb0166d8053a105e04bccea2f65"><li>创建一个 <code class="notion-inline-code">&lt;a&gt;</code> 元素（下载链接），将其 <code class="notion-inline-code">href</code> 属性设置为通过 <code class="notion-inline-code">window.URL.createObjectURL(blob)</code> 生成的 URL，并设置 <code class="notion-inline-code">download</code> 属性为解码后的文件名。</li></ul><ul class="notion-list notion-list-disc notion-block-10e07eb0166d80f39020ef481b9cfb4b"><li>将下载链接添加到文档中，触发点击事件以开始下载，然后从文档中移除该元素。</li></ul><ul class="notion-list notion-list-disc notion-block-10e07eb0166d80b580fcce75059bd9de"><li>最后，调用 <code class="notion-inline-code">window.URL.revokeObjectURL(href)</code> 释放之前创建的 URL 对象，避免内存泄漏。</li></ul></ol></ol><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-10e07eb0166d81bd90d9c12d9f1d7470" data-id="10e07eb0166d81bd90d9c12d9f1d7470"><span><div id="10e07eb0166d81bd90d9c12d9f1d7470" class="notion-header-anchor"></div><a class="notion-hash-link" href="#10e07eb0166d81bd90d9c12d9f1d7470" title="2.前端使用"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.前端使用</span></span></h3><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-10e07eb0166d80fd9a98f0c53ea8e100" data-id="10e07eb0166d80fd9a98f0c53ea8e100"><span><div id="10e07eb0166d80fd9a98f0c53ea8e100" class="notion-header-anchor"></div><a class="notion-hash-link" href="#10e07eb0166d80fd9a98f0c53ea8e100" title="后端部分"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">后端部分</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-10e07eb0166d808caffbc99b5af3e68a" data-id="10e07eb0166d808caffbc99b5af3e68a"><span><div id="10e07eb0166d808caffbc99b5af3e68a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#10e07eb0166d808caffbc99b5af3e68a" title="1.ExcelUtil工具类"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">1.ExcelUtil工具类</span></span></h3><div class="notion-text notion-block-6d9015d5192f4855a4eb614aebcfc227">这段代码是一个用于导出Excel文件的工具方法。让我们逐步分析其功能：</div><ol start="1" class="notion-list notion-list-numbered notion-block-726a95d5d4324aa88c0841af7ae957b7" style="list-style-type:decimal"><li><b>方法签名：</b> 这是一个静态方法，接受四个参数：HttpServletResponse、文件名、表头列表和数据列表。</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-0b8e49cfc4d2455da5a953b53a9391a3" style="list-style-type:decimal"><li><b>设置响应头：</b></li><ol class="notion-list notion-list-numbered notion-block-0b8e49cfc4d2455da5a953b53a9391a3" style="list-style-type:lower-alpha"><ul class="notion-list notion-list-disc notion-block-40c5af49afa842d0887598edd528b71b"><li>设置内容类型为Excel文件</li></ul><ul class="notion-list notion-list-disc notion-block-026927c9801d4fbaa59f5e87241c098b"><li>设置字符编码为UTF-8</li></ul><ul class="notion-list notion-list-disc notion-block-da5c3f226e36414ea7cc880ec47c6596"><li>设置Content-disposition头，指定文件名（经过URL编码以避免中文乱码）</li></ul></ol></ol><ol start="3" class="notion-list notion-list-numbered notion-block-05686f2ccf824f9a8b404873d073ff70" style="list-style-type:decimal"><li><b>使用EasyExcel库写入Excel：</b></li><ol class="notion-list notion-list-numbered notion-block-05686f2ccf824f9a8b404873d073ff70" style="list-style-type:lower-alpha"><ul class="notion-list notion-list-disc notion-block-48325bc4b29c475898e116eb75e03992"><li>通过response.getOutputStream()获取输出流</li></ul><ul class="notion-list notion-list-disc notion-block-53eb62822ad4496aa218c8a6b7f19fae"><li>设置表头(head)和工作表名(sheet)</li></ul><ul class="notion-list notion-list-disc notion-block-5359de9fda334369980966bc9e13e831"><li>写入数据(doWrite)</li></ul></ol></ol><ol start="4" class="notion-list notion-list-numbered notion-block-b7cb956b4bd945c0a1cc0f2e7e6aa8d0" style="list-style-type:decimal"><li><b>异常处理：</b> 捕获并打印可能发生的IOException。</li></ol><div class="notion-text notion-block-ba337b3b5b714127b600a6fb086bb8d8">这个方法封装了Excel导出的复杂性，使得在其他地方调用时能够简单地传入必要的参数即可完成Excel文件的生成和下载。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-10e07eb0166d80e4ae14f032aeab8fef" data-id="10e07eb0166d80e4ae14f032aeab8fef"><span><div id="10e07eb0166d80e4ae14f032aeab8fef" class="notion-header-anchor"></div><a class="notion-hash-link" href="#10e07eb0166d80e4ae14f032aeab8fef" title="2.EasyExcel"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.EasyExcel</span></span></h3><div class="notion-text notion-block-bd9fe27757f94aeabc16398bccfe3c6c">EasyExcel是一个基于Java的、简单易用的Excel处理库，由阿里巴巴开源。它的设计目标是简化Excel的读写操作，提高性能并减少内存占用。以下是EasyExcel的主要特点和使用方法：</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-adc79ce86da042039d8635282a3024b0" data-id="adc79ce86da042039d8635282a3024b0"><span><div id="adc79ce86da042039d8635282a3024b0" class="notion-header-anchor"></div><a class="notion-hash-link" href="#adc79ce86da042039d8635282a3024b0" title="EasyExcel的主要特点："><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">EasyExcel的主要特点：</span></span></h4><ol start="1" class="notion-list notion-list-numbered notion-block-fc7b57f91042438d955cffad0e7f4e72" style="list-style-type:decimal"><li>内存占用小：通过流式读写，大大减少内存占用</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-6d1e376867574ac6ba5a2cf2cf6d5821" style="list-style-type:decimal"><li>性能高：相比Apache POI，EasyExcel在读写大文件时有显著的性能优势</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-211ed7abbc0343b5a8c38fa110513a2d" style="list-style-type:decimal"><li>使用简单：API设计简洁，易于上手</li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-2b01bcf25e0145de92d6673e929d3426" style="list-style-type:decimal"><li>功能强大：支持读写Excel（包括03和07版本），还支持CSV的读写</li></ol><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-c63d0e1ff8174aa0bd677ceb5fc1bde8" data-id="c63d0e1ff8174aa0bd677ceb5fc1bde8"><span><div id="c63d0e1ff8174aa0bd677ceb5fc1bde8" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c63d0e1ff8174aa0bd677ceb5fc1bde8" title="如何使用EasyExcel："><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">如何使用EasyExcel：</span></span></h4><ol start="1" class="notion-list notion-list-numbered notion-block-8614e790a5e14019ad5843d3481956d0" style="list-style-type:decimal"><ol class="notion-list notion-list-numbered notion-block-8614e790a5e14019ad5843d3481956d0" style="list-style-type:lower-alpha"><li>添加依赖：在Maven项目的pom.xml文件中添加EasyExcel依赖</li></ol></ol><ol start="1" class="notion-list notion-list-numbered notion-block-50b1f94227c6461e9c4e023e8ba315be" style="list-style-type:decimal"><ol class="notion-list notion-list-numbered notion-block-50b1f94227c6461e9c4e023e8ba315be" style="list-style-type:lower-alpha"><li>创建实体类：定义与Excel表格结构对应的Java类，使用注解来映射列</li></ol></ol><ol start="1" class="notion-list notion-list-numbered notion-block-627f8f71ce214211aa34a7dbb47d402a" style="list-style-type:decimal"><ol class="notion-list notion-list-numbered notion-block-627f8f71ce214211aa34a7dbb47d402a" style="list-style-type:lower-alpha"><li>写入Excel：使用EasyExcel.write()方法写入数据</li></ol></ol><ol start="1" class="notion-list notion-list-numbered notion-block-538f68c951754389b2e313f0e5af8512" style="list-style-type:decimal"><ol class="notion-list notion-list-numbered notion-block-538f68c951754389b2e313f0e5af8512" style="list-style-type:lower-alpha"><li>读取Excel：使用EasyExcel.read()方法读取数据</li></ol></ol><div class="notion-text notion-block-004c8181c6334478a692c69be7e43d1f">EasyExcel还提供了许多高级功能，如自定义样式、合并单元格、导出图片等。在实际使用中，可以根据具体需求查阅官方文档以获取更详细的使用说明。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-10e07eb0166d80659f02e9ea2aff729b" data-id="10e07eb0166d80659f02e9ea2aff729b"><span><div id="10e07eb0166d80659f02e9ea2aff729b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#10e07eb0166d80659f02e9ea2aff729b" title="3.后端使用"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3.后端使用</span></span></h3><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-10e07eb0166d81c1952bcc7140d41d07" data-id="10e07eb0166d81c1952bcc7140d41d07"><span><div id="10e07eb0166d81c1952bcc7140d41d07" class="notion-header-anchor"></div><a class="notion-hash-link" href="#10e07eb0166d81c1952bcc7140d41d07" title="🤗 总结归纳"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">🤗 总结归纳</span></span></h2><div class="notion-text notion-block-c4f1a804cd3a48ab9b6d4ddfa4c7d1a0">本文详细介绍了如何在一个Web应用中实现数据导出Excel功能，包括前端和后端的实现方法。以下是主要内容的总结：</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-88f015235c7c4eb58904c4317c69dc70" data-id="88f015235c7c4eb58904c4317c69dc70"><span><div id="88f015235c7c4eb58904c4317c69dc70" class="notion-header-anchor"></div><a class="notion-hash-link" href="#88f015235c7c4eb58904c4317c69dc70" title="前端实现："><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">前端实现：</span></span></h3><ul class="notion-list notion-list-disc notion-block-4652413a15ff42bfa1ae3d1bb220257c"><li>创建了一个通用的exportExcel方法，使用axios发送GET请求获取Excel文件。</li></ul><ul class="notion-list notion-list-disc notion-block-869457d4344d4200a6929826c5c48c4b"><li>实现了文件下载功能，包括创建Blob对象和触发下载。</li></ul><ul class="notion-list notion-list-disc notion-block-f9d1bb65a97f47dd805e2e639f57ae28"><li>展示了如何在前端调用exportExcel方法。</li></ul><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-24b0f3e251984c819a2e4d93647a74e9" data-id="24b0f3e251984c819a2e4d93647a74e9"><span><div id="24b0f3e251984c819a2e4d93647a74e9" class="notion-header-anchor"></div><a class="notion-hash-link" href="#24b0f3e251984c819a2e4d93647a74e9" title="后端实现："><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">后端实现：</span></span></h3><ul class="notion-list notion-list-disc notion-block-20a6dcee9cc94ff68e3c769ccf21b240"><li>使用ExcelUtil工具类处理Excel导出，设置响应头和文件名。</li></ul><ul class="notion-list notion-list-disc notion-block-1ba85c24586145f3b28140887af68cae"><li>利用EasyExcel库进行Excel的写入操作。</li></ul><ul class="notion-list notion-list-disc notion-block-3b45c300a9ef4e418159ca73af214090"><li>详细介绍了EasyExcel的特点和使用方法，包括依赖添加、实体类创建、数据写入和读取。</li></ul><ul class="notion-list notion-list-disc notion-block-a60186b1857843418b23bae1e2d07011"><li>展示了后端如何处理导出请求，包括数据查询、标题和数据列表的准备。</li></ul><div class="notion-text notion-block-6ec7ba48e1624da1ae169915fa04e0cf">总的来说，这个实现方案提供了一个完整的Excel导出功能，从前端请求到后端数据处理和文件生成，再到前端文件下载的全过程。使用EasyExcel库简化了Excel处理的复杂性，提高了性能和可维护性。</div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[css实现居中]]></title>
            <link>https://tangly1024.com/article/10e07eb0-166d-808c-925a-c7df992f34f8</link>
            <guid>https://tangly1024.com/article/10e07eb0-166d-808c-925a-c7df992f34f8</guid>
            <pubDate>Fri, 27 Sep 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-10e07eb0166d808c925ac7df992f34f8"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-callout notion-gray_background_co notion-block-10e07eb0166d815ca8f6ebb0ff2f9389"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="😀">😀</span></div><div class="notion-callout-text">这里写文章的前言：
一个简单的开头,简述这篇文章讨论的问题、目标、人物、背景是什么？并简述你给出的答案。<div class="notion-text notion-block-10e07eb0166d81929904c5e2bc8850dc">可以说说你的故事：阻碍、努力、结果成果，意外与转折。</div></div></div><div class="notion-blank notion-block-10e07eb0166d81b69203c9edde6059a3"> </div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-10e07eb0166d810e8d97e6a03a80f514" data-id="10e07eb0166d810e8d97e6a03a80f514"><span><div id="10e07eb0166d810e8d97e6a03a80f514" class="notion-header-anchor"></div><a class="notion-hash-link" href="#10e07eb0166d810e8d97e6a03a80f514" title="📝 主旨内容"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">📝 主旨内容</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-10e07eb0166d81479e5adc0085895bb9" data-id="10e07eb0166d81479e5adc0085895bb9"><span><div id="10e07eb0166d81479e5adc0085895bb9" class="notion-header-anchor"></div><a class="notion-hash-link" href="#10e07eb0166d81479e5adc0085895bb9" title="垂直居中"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">垂直居中</span></span></h3><div class="notion-text notion-block-8e982ae55a7045a887308e99e8fd0945">在CSS中实现垂直居中有多种方法，以下是几种常用的技巧：</div><div class="notion-text notion-block-a10dd78c0da44746b91115238f7fbc59">这些方法各有优缺点，适用于不同的场景：</div><ul class="notion-list notion-list-disc notion-block-9b3f32d4188e4a28aea44084d7c3df41"><li>Flexbox和Grid方法简单直观，但对旧版浏览器的支持较差。</li></ul><ul class="notion-list notion-list-disc notion-block-df5c9e31099a4153856074b0369d1e98"><li>绝对定位方法兼容性好，但可能会影响其他元素的布局。</li></ul><ul class="notion-list notion-list-disc notion-block-07cec873585a41a49c424a2b90c213a7"><li>table-cell方法兼容性最好，但语义上不太合适。</li></ul><div class="notion-text notion-block-ba35a3880db245e4b7f82498d4a4ae42">选择哪种方法取决于你的具体需求和目标浏览器支持。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-10e07eb0166d813fbc50f8519b9b0a5e" data-id="10e07eb0166d813fbc50f8519b9b0a5e"><span><div id="10e07eb0166d813fbc50f8519b9b0a5e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#10e07eb0166d813fbc50f8519b9b0a5e" title="观点2"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">观点2</span></span></h3><blockquote class="notion-quote notion-block-10e07eb0166d818ba63cc6a9c1c84499"><div>引用的话语</div></blockquote><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-10e07eb0166d81aa9f79e5c585b5eeb3" data-id="10e07eb0166d81aa9f79e5c585b5eeb3"><span><div id="10e07eb0166d81aa9f79e5c585b5eeb3" class="notion-header-anchor"></div><a class="notion-hash-link" href="#10e07eb0166d81aa9f79e5c585b5eeb3" title="🤗 总结归纳"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">🤗 总结归纳</span></span></h2><div class="notion-text notion-block-10e07eb0166d812c8d07fa5c290edbb2">总结文章的内容</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-10e07eb0166d81409f29ecf769b029cb" data-id="10e07eb0166d81409f29ecf769b029cb"><span><div id="10e07eb0166d81409f29ecf769b029cb" class="notion-header-anchor"></div><a class="notion-hash-link" href="#10e07eb0166d81409f29ecf769b029cb" title="📎 参考文章"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">📎 参考文章</span></span></h2><ul class="notion-list notion-list-disc notion-block-10e07eb0166d81f5a5a8c30c71f6edd9"><li>一些引用</li></ul><ul class="notion-list notion-list-disc notion-block-10e07eb0166d81638e52f3a44ec3f5af"><li>引用文章</li></ul><div class="notion-blank notion-block-10e07eb0166d81d6885ae6480fe154d7"> </div><div class="notion-callout notion-gray_background_co notion-block-10e07eb0166d815f86a3e6ac4084f6d3"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="💡">💡</span></div><div class="notion-callout-text">有关Notion安装或者使用上的问题，欢迎您在底部评论区留言，一起交流~</div></div></main></div>]]></content:encoded>
        </item>
    </channel>
</rss>