1. 程式人生 > 實用技巧 >Node.js 學習筆記之五:使用 Express 框架

Node.js 學習筆記之五:使用 Express 框架

MybatisPlus 是Mybatis的增強
所以在引入MybatisPLus的依賴時要將Mybatis的依賴刪掉(防止紊亂)

引入依賴

<!--spring整合mybatis-plus 只匯入MP包,刪除mybatis包 -->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.2.0</version>
        </dependency>

MybatisPuls將資料庫的表與物件關連,欄位與屬性關聯
@TableName("表名")
@TableId(type=IdType.AUTO)
@TableField(value="欄位名")

@Data
@Accessors(chain = true)//鏈式規則
@TableName("user")    //實現表與物件的關聯  如果名稱一致(忽略大小寫)可以省略表名
public class User implements Serializable {

    //但凡定義pojo實體物件中的屬性型別必須使用包裝型別.
    @TableId(type = IdType.AUTO)
    private Integer id;  //主鍵,並且主鍵自增
    //@TableField(value = "name")  當欄位名和屬性名一致時可以省略這個註解
    private String name;
    //@TableField(value = "age")
    private Integer age;
    private String sex;

    //動態生成get和set方法及構造方法 快捷鍵 alt+insert

}

mapper介面(dao)繼承BaseMapper注意泛型是我們要操作的物件

//@Mapper //將Mapper介面交給Spring容器管理
//注意泛型引入.如果不新增則資料庫操作沒辦法完成.
public interface UserMapper extends BaseMapper<User> {
}

修改配置檔案

#Mybatisplus整合
mybatis-plus:
  #定義別名包 將實體物件的包路徑進行封裝.
  type-aliases-package: com.jt.pojo
  #新增xml檔案的依賴
  mapper-locations: classpath:/mybatis/mappers/*.xml
  #開啟駝峰對映
  configuration:
    map-underscore-to-camel-case: true

測試MP方法

    @Test
    public void test02(){
        //查詢user表的全部資料
        List<User> userList = userMapper.selectList(null);
        System.out.println(userList);
    }