乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Java教程分享MyBatis Plus介紹

       好程序員IT 2019-10-29

      Java教程分享MyBatis Plus介紹

      1.MyBatis Plus 介紹

        MyBatis Plus 是國內(nèi)人員開發(fā)的 MyBatis 增強(qiáng)工具,在 MyBatis 的基礎(chǔ)上只做增強(qiáng)不做改變,為簡化開發(fā)、提高效率而生。

        MyBatis Plus 的核心功能有:支持通用的 CRUD、代碼生成器與條件構(gòu)造器。

        通用 CRUD:定義好 Mapper 接口后,只需要繼承 BaseMapper<T> 接口即可獲得通用的增刪改查功能,無需編寫任何接口方法與配置文件

        條件構(gòu)造器:通過 EntityWrapper<T> (實體包裝類),可以用于拼接 SQL 語句,并且支持排序、分組查詢等復(fù)雜的 SQL

      2.添加依賴

        <dependency>

      <groupId>com.baomidou</groupId>

      <artifactId>mybatis-plus</artifactId>

      <version>2.3</version>

      </dependency>

      3.配置

      <!-- MP 提供的 MybatisSqlSessionFactoryBean -->

      <bean id="sqlSessionFactoryBean"

      class="com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean">

      <!-- 數(shù)據(jù)源 -->

      <property name="dataSource" ref="dataSource"/>

      <!-- 別名處理 -->

      <property name="typeAliasesPackage" value="com.qf.entity"/>

      <!-- 插件注冊 -->

      <property name="plugins">

      <list>

      <!-- 注冊分頁插件 -->

      <bean class="com.baomidou.mybatisplus.plugins.PaginationInterceptor" />

      </list>

      </property>

      </bean>

      4.Dao

      public interface IUserDao extends BaseMapper<User> {

      }

      5.實體類

      @Data

      @TableName(value="t_user")

      public class User{

      @TableId(value="id",type=IdType.AUTO)

      private Integer id;

      @TableField(value="username")

      private String name;

      private Integer age;

      private String password;

      @TableField(exist=false)

      private Integer xxx;

      }

      6.常見注解

      @TableField(exist = false):表示該屬性不為數(shù)據(jù)庫表字段,但又是必須使用的。

      @TableField(exist = true):表示該屬性為數(shù)據(jù)庫表字段。

      @TableName:數(shù)據(jù)庫表相關(guān)

      @TableId:表主鍵標(biāo)識

      @TableField:表字段標(biāo)識

      7.測試方法

        @Test

      public void testMybatisPlus(){

      System.out.println("selectById:"+userDao.selectById(4)); // 根據(jù)Id查詢

      System.out.println("selectList:"+userDao.selectList(null)); // 查詢?nèi)?/span>

      com.baomidou.mybatisplus.plugins.Page<User> page = new com.baomidou.mybatisplus.plugins.Page<>();

      List<User> list = userDao.selectPage(page, null); // 分頁查詢

      page.setRecords(list); // 把結(jié)果封裝到分頁對象中

      System.out.println(page.getCurrent());

      System.out.println(page.getPages());

      System.out.println(page.getSize());

      System.out.println(page.getTotal());

      System.out.println(page.getRecords());

      EntityWrapper<User> entityWrapper = new EntityWrapper<>();

      entityWrapper.eq("id", 4);

      entityWrapper.or().like("username", "3");

      List<User> selectList = userDao.selectList(entityWrapper); // 條件查詢

      System.out.println("wrapper:"+selectList);

      }

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多