代码拉取完成,页面将自动刷新
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Markdown Plus exported HTML</title><link rel="stylesheet" href="https://unpkg.com/markdown-core@0.9.28/dist/index.bundle.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/mermaid/6.0.0/mermaid.css"></head><body><article class="markdown-body"><p data-source-line="1">#beetlsql-experimental</p> <p data-source-line="3"><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i></p> <h2 id="匠的追求-极简之上-dao无注解-无实现类-无框架的强耦合" data-source-line="5"><a class="anchor" href="#匠的追求-极简之上-dao无注解-无实现类-无框架的强耦合"><span class="octicon octicon-link"></span></a>匠的追求, 极简之上. dao无注解 无实现类 无框架的强耦合</h2> <ul data-source-line="7"> <li> <p><mark>beetlsql + java8 + lombok</mark>结合使用,达到代码最简洁效果, 并且可阅读性更强</p> </li> <li> <p>Effective Java 第18条:<mark>接口优于抽象类</mark></p> </li> </ul> <p data-source-line="12">简洁玩法 (实现$Sql<mark>接口</mark>, 实体类就拥有save, update, delete方法.)</p> <pre><code class="hljs"><span class="hljs-meta">@Data</span> <span class="hljs-comment">// 提供getter setter toString 等方法</span> <span class="hljs-meta">@FieldDefaults</span>(level = AccessLevel.PRIVATE) <span class="hljs-comment">// 属性默认都是private</span> <span class="hljs-meta">@lombok</span>.experimental.Accessors(chain = <span class="hljs-keyword">true</span>) <span class="hljs-comment">// 链式编程</span> <span class="hljs-meta">@Table</span>(name = <span class="hljs-string">"tb_bird"</span>) <span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Bee</span> <span class="hljs-keyword">implements</span> $<span class="hljs-title">Sql</span> </span>{ <span class="hljs-comment">// 实现$Sql接口, 可以在对象上直接使用 save, update, delete 方法 (不是必须的)</span> <span class="hljs-keyword">int</span> id; <span class="hljs-comment">/** 年龄 */</span> Integer age; <span class="hljs-comment">/** 名字 */</span> String name; <span class="hljs-comment">/** 描述 */</span> String description; }</code></pre><p data-source-line="31"><mark>简洁玩法测试用例</mark> 使用链式编程达到代码最简洁</p> <pre><code class="hljs"><span class="hljs-meta">@Log</span>4j <span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">BeeChainTest</span> </span>{ <span class="hljs-meta">@Test</span> <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">testChainSave</span><span class="hljs-params">()</span> </span>{ <span class="hljs-comment">// 自动拥有getter,setter, 无需手动敲击这些代码</span> <span class="hljs-keyword">new</span> Bee().setAge(<span class="hljs-number">18</span>).setName(<span class="hljs-string">"小伙子!"</span>).save(); } <span class="hljs-meta">@Test</span> <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">testUpdate</span><span class="hljs-params">()</span> </span>{ Bee bee = Bee.Dao.$.unique(<span class="hljs-number">1</span>); bee.setName(<span class="hljs-string">"迪米特"</span>).update(); } <span class="hljs-meta">@Test</span> <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">testDelete</span><span class="hljs-params">()</span> </span>{ Bee bee = Bee.Dao.$.unique(<span class="hljs-number">1</span>); bee.delete(); } }</code></pre><p data-source-line="55"><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i></p> <p data-source-line="58"><mark>新增一些自定义方法</mark> (与数据库交互)</p> <pre><code class="hljs"><span class="hljs-keyword">import</span> <span class="hljs-keyword">static</span> org.beetl.sql.experimental.iohao.core.SqlKit.mapper; <span class="hljs-meta">@Data</span> <span class="hljs-comment">// 提供getter setter toString 等方法</span> <span class="hljs-meta">@FieldDefaults</span>(level = AccessLevel.PRIVATE) <span class="hljs-comment">// 属性默认都是private</span> <span class="hljs-meta">@Table</span>(name = <span class="hljs-string">"animal"</span>) <span class="hljs-comment">// 实体类与表映射</span> <span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">BeeAnimal</span> <span class="hljs-keyword">implements</span> $<span class="hljs-title">Sql</span> </span>{ <span class="hljs-comment">// 实现$Sql接口可以在对象上使用save,update,delete方法(不是必须的)</span> <span class="hljs-keyword">int</span> id; <span class="hljs-keyword">int</span> age; String name; String description; <span class="hljs-comment">/** animal_info表的字段: 分布区域 */</span> String regionName; <span class="hljs-comment">/** * 匠的追求, 极简之上. * 无注解 无实现类 无框架的强耦合. 直接可以使用. * 自定义sqlDao处理类. (如果没有自定义sql就没必要定义这个接口). */</span> <span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">Dao</span> <span class="hljs-keyword">extends</span> $<span class="hljs-title">Mapper</span><<span class="hljs-title">BeeAnimal</span>> </span>{ Dao $ = mapper(Dao.class); <span class="hljs-function">List<BeeAnimal> <span class="hljs-title">findAnimals</span><span class="hljs-params">(<span class="hljs-keyword">int</span> animalInfoId, <span class="hljs-keyword">int</span> age)</span></span>; <span class="hljs-function">BeeAnimal <span class="hljs-title">findOne</span><span class="hljs-params">(String name, <span class="hljs-keyword">int</span> animalInfoId, <span class="hljs-keyword">int</span> age)</span></span>; } }</code></pre><p data-source-line="89"><mark>新增自定义方法</mark>的dao层测试用例</p> <pre><code class="hljs"><span class="hljs-meta">@Log</span>4j <span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">BeeAnimalTest</span> </span>{ <span class="hljs-meta">@Test</span> <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">findAnimals</span><span class="hljs-params">()</span> </span>{ <span class="hljs-keyword">int</span> animalInfoId = <span class="hljs-number">2</span>; <span class="hljs-keyword">int</span> age = <span class="hljs-number">15</span>; List<BeeAnimal> animals = BeeAnimal.Dao.$.findAnimals(animalInfoId, age); log.info(animals); } <span class="hljs-meta">@Test</span> <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">findOne</span><span class="hljs-params">()</span> </span>{ String name = <span class="hljs-string">"海豚"</span>; <span class="hljs-keyword">int</span> animalInfoId = <span class="hljs-number">2</span>; <span class="hljs-keyword">int</span> age = <span class="hljs-number">9</span>; BeeAnimal animal = BeeAnimal.Dao.$.findOne(name, animalInfoId, age); log.info(animal); log.info(animal.getRegionName()); } }</code></pre><p data-source-line="115"><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i></p> <p data-source-line="117">执行dir/sql目录下的sql, 就可以运行查询测试用例.</p> <p data-source-line="119"><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i><i class="e1a-whale"></i></p> <h2 id="dao无注解-在idea中配置-parameters" data-source-line="121"><a class="anchor" href="#dao无注解-在idea中配置-parameters"><span class="octicon octicon-link"></span></a>dao无注解: 在idea中配置 -parameters</h2> <p data-source-line="122"><img src="http://git.oschina.net/iohao/beetlsql-experimental/raw/master/dir/param.png" alt="image"></p> <h2 id="idea首次使用lombok请安装插件-并配置" data-source-line="124"><a class="anchor" href="#idea首次使用lombok请安装插件-并配置"><span class="octicon octicon-link"></span></a>idea首次使用lombok请安装插件, 并配置</h2> <p data-source-line="125"><img src="http://git.oschina.net/iohao/beetlsql-experimental/raw/master/dir/1.png" alt="image"></p> </article><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.slim.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.bundle.min.js"></script><script>$(function() { $('canvas.chartjs').each(function() { new Chart($(this), JSON.parse($(this).text())); }); });</script></body></html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。