<div id="article_content" class="article_content clearfix">
<link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/kdoc_html_views-1a98987dfd.css">
<link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/ck_htmledit_views-6e43165c0a.css">
<div id="content_views" class="markdown_views prism-tomorrow-night">
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
<path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path>
</svg>
<p></p>
<div class="toc">
<h3><a name="t0"></a>文章目录</h3>
<ul><li><a href="#_1" target="_self">问题描述</a></li><li><a href="#1_4" target="_self">1.实体类</a></li><li><a href="#2_19" target="_self">2.数据访问层</a></li><li><a href="#3N1_56" target="_self">3.测试触发N+1</a></li><li><a href="#4N1_66" target="_self">4.解决N+1的问题</a></li><li><a href="#5jacksonN1_82" target="_self">5.jackson序列化导致的N+1问题</a></li></ul>
</div>
<p></p>
<h1><a name="t1"></a><a id="_1"></a>问题描述</h1>
<p>因为设计<a href="https://so.csdn.net/so/search?q=%E6%A0%91%E5%BD%A2%E7%BB%93%E6%9E%84&spm=1001.2101.3001.7020" target="_blank" class="hl hl-1" data-report-click="{"spm":"1001.2101.3001.7020","dest":"https://so.csdn.net/so/search?q=%E6%A0%91%E5%BD%A2%E7%BB%93%E6%9E%84&spm=1001.2101.3001.7020","extra":"{\"searchword\":\"树形结构\"}"}" data-tit="树形结构" data-pretit="树形结构">树形结构</a>的实体中用到了多对一,一对多的映射关系,在加载这个实体对象的时候,因为JPA的懒加载特效会导致触发N+1的问题,通常1的这方是通过1条SQL查找得到的1个对象或1个集合,由于关联的存在 ,又需要将这个对象(或集合)关联的集合取出,1这方的集合数量是N,则要发出N条SQL,于是本来的1条联表查询SQL可解决的问题变成了N+1条SQL。<br> <strong>例如以下场景,后台管理系统菜单往往都是树结构的,一般会存在多个菜单和子菜单,如下:</strong></p>
<h1><a name="t2"></a><a id="1_4"></a>1.实体类</h1>
<pre data-index="0" class="prettyprint"><code class="prism language-java has-numbering" οnclick="mdcp.copyCode(event)" style="position: unset;"><span class="token annotation punctuation">@Data</span>
<span class="token annotation punctuation">@Entity</span>
<span class="token annotation punctuation">@Table</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"menu"</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Menu</span> <span class="token punctuation">{<!-- --></span>
<span class="token annotation punctuation">@Id</span>
<span class="token keyword">private</span> <span class="token class-name">Integer</span> id<span class="token punctuation">;</span>
<span class="token keyword">private</span> <span class="token class-name">String</span> menuName<span class="token punctuation">;</span>
<span class="token keyword">private</span> <span class="token class-name">Integer</span> parentId<span class="token punctuation">;</span>
<span class="token annotation punctuation">@OneToMany</span>
<span class="token annotation punctuation">@JoinColumn</span><span class="token punctuation">(</span>name<span class="token operator">=</span><span class="token string">"parentId"</span><span class="token punctuation">)</span>
<span class="token keyword">private</span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation"><</span><span class="token class-name">Menu</span><span class="token punctuation">></span></span> childList<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<div class="hljs-button {2}" data-title="复制"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li></ul></pre>
<h1><a name="t3"></a><a id="2_19"></a>2.数据访问层</h1>
<pre data-index="1" class="prettyprint"><code class="prism language-java has-numbering" οnclick="mdcp.copyCode(event)" style="position: unset;"><span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">MenuRepository</span> <span class="token keyword">extends</span> <span class="token class-name">JpaRepository</span><span class="token generics"><span class="token punctuation"><</span><span class="token class-name">Menu</span><span class="token punctuation">,</span><span class="token class-name">Integer</span><span class="token punctuation">></span></span> <span class="token punctuation">{<!-- --></span>
<span class="token class-name">List</span><span class="token generics"><span class="token punctuation"><</span><span class="token class-name">Menu</span><span class="token punctuation">></span></span> <span class="token function">findAllByParentIdIsNull</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<div class="hljs-button {2}" data-title="复制"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li></ul></pre>
<p>插入基础数据,以下插入了2个根菜单和3个子菜单</p>
<pre data-index="2" class="prettyprint"><code class="prism language-java has-numbering" οnclick="mdcp.copyCode(event)" style="position: unset;"> <span class="token annotation punctuation">@Autowired</span>
<span class="token class-name">MenuRepository</span> menuRepository<span class="token punctuation">;</span>
<span class="token punctuation">{<!-- --></span>
<span class="token class-name">Menu</span> menu <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Menu</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
menu<span class="token punctuation">.</span><span class="token function">setId</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
menu<span class="token punctuation">.</span><span class="token function">setMenuName</span><span class="token punctuation">(</span><span class="token string">"系统管理"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">Menu</span> menu2 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Menu</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
menu2<span class="token punctuation">.</span><span class="token function">setId</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
menu2<span class="token punctuation">.</span><span class="token function">setMenuName</span><span class="token punctuation">(</span><span class="token string">"用户管理"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
menu2<span class="token punctuation">.</span><span class="token function">setParentId</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">Menu</span> menu3 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Menu</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
menu3<span class="token punctuation">.</span><span class="token function">setId</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
menu3<span class="token punctuation">.</span><span class="token function">setMenuName</span><span class="token punctuation">(</span><span class="token string">"角色管理"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
menu3<span class="token punctuation">.</span><span class="token function">setParentId</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">Menu</span> menu4 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Menu</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
menu4<span class="token punctuation">.</span><span class="token function">setId</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
menu4<span class="token punctuation">.</span><span class="token function">setMenuName</span><span class="token punctuation">(</span><span class="token string">"报表统计"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">Menu</span> menu5 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Menu</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
menu5<span class="token punctuation">.</span><span class="token function">setId</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
menu5<span class="token punctuation">.</span><span class="token function">setMenuName</span><span class="token punctuation">(</span><span class="token string">"按月统计"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
menu5<span class="token punctuation">.</span><span class="token function">setParentId</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
menuRepository<span class="token punctuation">.</span><span class="token function">save</span><span class="token punctuation">(</span>menu<span class="token punctuation">)</span><span class="token punctuation">;</span>
menuRepository<span class="token punctuation">.</span><span class="token function">save</span><span class="token punctuation">(</span>menu2<span class="token punctuation">)</span><span class="token punctuation">;</span>
menuRepository<span class="token punctuation">.</span><span class="token function">save</span><span class="token punctuation">(</span>menu3<span class="token punctuation">)</span><span class="token punctuation">;</span>
menuRepository<span class="token punctuation">.</span><span class="token function">save</span><span class="token punctuation">(</span>menu4<span class="token punctuation">)</span><span class="token punctuation">;</span>
menuRepository<span class="token punctuation">.</span><span class="token function">save</span><span class="token punctuation">(</span>menu5<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<div class="hljs-button {2}" data-title="复制"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li></ul></pre>
<h1><a name="t4"></a><a id="3N1_56"></a>3.测试触发N+1</h1>
<pre data-index="3" class="prettyprint"><code class="prism language-java has-numbering" οnclick="mdcp.copyCode(event)" style="position: unset;"> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation"><</span><span class="token class-name">Menu</span><span class="token punctuation">></span></span> menuList <span class="token operator">=</span> menuRepository<span class="token punctuation">.</span><span class="token function">findAllByParentIdIsNull</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"一级菜单数量="</span><span class="token operator">+</span>menuList<span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token class-name">Menu</span> menu <span class="token operator">:</span> menuList<span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"菜单名称="</span><span class="token operator">+</span>menu<span class="token punctuation">.</span><span class="token function">getMenuName</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">+</span><span class="token string">"的子菜单数量="</span><span class="token operator">+</span>menu<span class="token punctuation">.</span><span class="token function">getChildList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<div class="hljs-button {2}" data-title="复制"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li></ul></pre>
<p>可以看到执行的sql一共打印了3条sql,第1条sql查询出所有的根菜单,第2和第3条则是根据根菜单的Id去查询对应的子菜单信息。<br> <img src="https://img-blog.csdnimg.cn/e73ccf9a626b48228657ce3f0558a592.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA55qT5Lqu5ZCb,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<h1><a name="t5"></a><a id="4N1_66"></a>4.解决N+1的问题</h1>
<p>在实体类加@NamedEntityGraph注解,并且通过@NamedAttributeNode注解关联上需要一起加载的模型类</p>
<pre data-index="4" class="prettyprint"><code class="prism language-java has-numbering" οnclick="mdcp.copyCode(event)" style="position: unset;"><span class="token annotation punctuation">@NamedEntityGraph</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"menu.findAll"</span><span class="token punctuation">,</span> attributeNodes <span class="token operator">=</span> <span class="token punctuation">{<!-- --></span>
<span class="token annotation punctuation">@NamedAttributeNode</span><span class="token punctuation">(</span>value <span class="token operator">=</span> <span class="token string">"childList"</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Menu</span> <span class="token punctuation">{<!-- --></span><span class="token punctuation">}</span>
<div class="hljs-button {2}" data-title="复制"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li></ul></pre>
<p>在数据访问层通过@EntityGraph的value指定需要使用@NamedEntityGraph注解里配置的name名称</p>
<pre data-index="5" class="prettyprint"><code class="prism language-java has-numbering" οnclick="mdcp.copyCode(event)" style="position: unset;"> <span class="token annotation punctuation">@EntityGraph</span><span class="token punctuation">(</span>value <span class="token operator">=</span> <span class="token string">"menu.findAll"</span><span class="token punctuation">,</span> type <span class="token operator">=</span> <span class="token class-name">EntityGraph<span class="token punctuation">.</span>EntityGraphType</span><span class="token punctuation">.</span><span class="token constant">FETCH</span><span class="token punctuation">)</span>
<span class="token class-name">List</span><span class="token generics"><span class="token punctuation"><</span><span class="token class-name">Menu</span><span class="token punctuation">></span></span> <span class="token function">findAllByParentIdIsNull</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<div class="hljs-button {2}" data-title="复制"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li></ul></pre>
<p>然后再执行测试代码,可以看到下面只打印了一条sql,代表着N+1的问题消失了。<br> <img src="https://img-blog.csdnimg.cn/9eec3334acb24af89f37ef0fe2808ae7.png" alt="在这里插入图片描述"></p>
<h1><a name="t6"></a><a id="5jacksonN1_82"></a>5.jackson序列化导致的N+1问题</h1>
<p>标签4解决的N+1问题只是在遍历获取的元素的时候,当没有遍历直接返回数据给页面时候又会导致这个问题。<br> <strong>问题复现:</strong></p>
<pre data-index="6" class="prettyprint"><code class="prism language-java has-numbering" οnclick="mdcp.copyCode(event)" style="position: unset;"><span class="token annotation punctuation">@RestController</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">TestController</span> <span class="token punctuation">{<!-- --></span>
<span class="token annotation punctuation">@Autowired</span>
<span class="token keyword">private</span> <span class="token class-name">MenuRepository</span> menuRepository<span class="token punctuation">;</span>
<span class="token annotation punctuation">@GetMapping</span><span class="token punctuation">(</span><span class="token string">"/test"</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation"><</span><span class="token class-name">Menu</span><span class="token punctuation">></span></span> <span class="token function">menuList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{<!-- --></span>
<span class="token class-name">List</span><span class="token generics"><span class="token punctuation"><</span><span class="token class-name">Menu</span><span class="token punctuation">></span></span> menuList <span class="token operator">=</span> menuRepository<span class="token punctuation">.</span><span class="token function">findAllByParentIdIsNull</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">return</span> menuList<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<div class="hljs-button {2}" data-title="复制"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li></ul></pre>
<p><img src="https://img-blog.csdnimg.cn/13e4837c034142bf945875d86d0e4436.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA55qT5Lqu5ZCb,size_17,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"><br> <img src="https://img-blog.csdnimg.cn/00f2a3a0f31f47c097526a50d508e4c6.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA55qT5Lqu5ZCb,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<p><strong>解决N+1问题</strong><br> 添加jackson-datatype-hibernate5包</p>
<pre data-index="7" class="prettyprint"><code class="prism language-pom has-numbering" οnclick="mdcp.copyCode(event)" style="position: unset;"> <dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-hibernate5</artifactId>
<version>2.13.2</version>
</dependency>
<div class="hljs-button {2}" data-title="复制"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li></ul></pre>
<p>重写 SpringMvc的 MappingJackson2HttpMessageConverter,将Hibernate5Module这个Module 注册到ObjectMapper。</p>
<pre data-index="8" class="prettyprint"><code class="prism language-java has-numbering" οnclick="mdcp.copyCode(event)" style="position: unset;"><span class="token annotation punctuation">@Configuration</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">WebMvcConfig</span> <span class="token punctuation">{<!-- --></span>
<span class="token annotation punctuation">@Bean</span>
<span class="token keyword">public</span> <span class="token class-name">MappingJackson2HttpMessageConverter</span> <span class="token function">mappingJackson2HttpMessageConverter</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
<span class="token class-name">MappingJackson2HttpMessageConverter</span> converter <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">MappingJackson2HttpMessageConverter</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">ObjectMapper</span> mapper <span class="token operator">=</span> converter<span class="token punctuation">.</span><span class="token function">getObjectMapper</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">Hibernate5Module</span> hibernate5Module <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Hibernate5Module</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
mapper<span class="token punctuation">.</span><span class="token function">registerModule</span><span class="token punctuation">(</span>hibernate5Module<span class="token punctuation">)</span><span class="token punctuation">;</span>
mapper<span class="token punctuation">.</span><span class="token function">setDateFormat</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">SimpleDateFormat</span><span class="token punctuation">(</span><span class="token string">"yyyy-MM-dd HH:mm:ss"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">return</span> converter<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<div class="hljs-button {2}" data-title="复制"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li></ul></pre>
<p>再次访问http://localhost:8013/test即可发现控制台只打印1条sql了。</p>
</div><div><div></div></div><div><div></div></div>
<link href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/markdown_views-0407448025.css" rel="stylesheet">
<link href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/style-bb308a51ed.css" rel="stylesheet">
</div>
JPA 懒加载 无效
最新推荐文章于 2024-05-16 17:25:45 发布