<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ## 前言 * 實體類建好了,那么下面我們來建和數據庫打交道的`Service`和`Mapper`類 。 * 因為這倆兄弟是為業務服務的,不需要被其他服務調用,所以會放到`blade-demo`這個業務工程內。 * 若其他服務需要調用本服務的一些API,則需要用到微服務遠程調用,而不是直接引用`Service`和`Mapper`。 * 微服務遠程調用將在下一章節講解。 ## 創建package 在`blade-demo`中新建`service`和`mapper`兩個package ![](https://box.kancloud.cn/1112a34849ff02ed1026dab10b3bba1c_334x200.png) ## 創建Service 1. 創建名為`BlogService`的接口類 ![](https://box.kancloud.cn/62e37c003a126a91e0830ad8440d0df4_366x157.png) 2. 創建名為`BlogServiceImpl`的接口實現類(放在service的imp包下) ![](https://box.kancloud.cn/ee4afd4969de3b18ffb827aaae3598ac_366x157.png) ## 創建Mapper 1. 創建名為`BlogMapper`的接口類 ![](https://box.kancloud.cn/4ef70db7ce14aa6e242028242d0e2d18_366x157.png) 2. 創建名為`BlogMapper`的XML文件 ![](https://box.kancloud.cn/9ef5e985c351c847323898bd21c863e9_406x145.png) 3. `BlogMapper.xml`內容如下,`通用查詢映射結果`則做到了實體類與數據庫字段對應的關系 ~~~ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="org.springblade.demo.mapper.BlogMapper"> <!-- 通用查詢映射結果 --> <resultMap id="blogResultMap" type="org.springblade.demo.entity.Blog"> <result column="id" property="id"/> <result column="blog_title" property="blogTitle"/> <result column="blog_content" property="blogContent"/> <result column="blog_date" property="blogDate"/> <result column="is_deleted" property="isDeleted"/> </resultMap> </mapper> ~~~ 4. 注意`BlogMapper.xml`的`namespace`和`resultMap` 的`type`要指向正確的地址 5. `namespace`指向對應的`BlogMapper.java`接口類 ,`type`指向對應的`Blog.java`實體類 ## 增加配置 1. `BlogMapper`增加mybatis-plus的配置 ~~~ package org.springbalde.demo.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.springblade.demo.entity.Blog; public interface BlogMapper extends BaseMapper<Blog> { } ~~~ 2. `BlogService`增加mybatis-plus的配置 ~~~ package org.springbalde.demo.service; import com.baomidou.mybatisplus.extension.service.IService; import org.springblade.demo.entity.Blog; public interface BlogService extends IService<Blog> { } ~~~ 3. `BlogServiceImpl`增加mybatis-plus的配置 ~~~ package org.springbalde.demo.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springbalde.demo.mapper.BlogMapper; import org.springbalde.demo.service.BlogService; import org.springblade.demo.entity.Blog; import org.springframework.stereotype.Service; @Service public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements BlogService{ } ~~~ ## 注意 SpringBlade默認的mybatis掃描包名為`org.springblade`,不在此目錄下的bean無法被mybatis掃描到,但大家作為各自的項目,新的服務肯定會使用其他的包名,這種情況需要自己額外定義一個配置類,配置包掃描的路徑,以及mybatis-plus掃描bean-alias的配置。 ![](https://box.kancloud.cn/42a88d5e1999cf4ff985fc260345f63d_888x342.png) ![](https://box.kancloud.cn/89d79c14a3e453f4d1143d5f48ed74f7_1588x898.png) ## 結束 好了,與mybatis-plus的集成已經結束,那么下面我們開始與數據庫交互的第一步,增刪改查的基本做法吧!
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看