zoukankan      html  css  js  c++  java
  • MyBatis-Plus

    项目上正在使用MyBatis-Plus,抽空学习了一下,感觉还不错。

    DAO层,我们使用了BaseMapper接口,SQL简单查询使用Lambda表达式,复杂使用XML文件。开发效率挺高。

    官方指南地址:https://mp.baomidou.com/guide/

    举例:

    import com.baomidou.mybatisplus.core.mapper.BaseMapper;
    import com.zst.wemo.model.user.User;
    import org.apache.ibatis.annotations.Mapper;
    import org.springframework.stereotype.Component;
    //定义一个UserDao
    @Mapper
    @Component
    public interface UserMapper extends BaseMapper<User> {
    }
    import org.mybatis.spring.annotation.MapperScan;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    //启动类
    @SpringBootApplication
    @MapperScan("com.zst.wemo.dao")
    public class WemoApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(WemoApplication.class, args);
        }
    
    }
    package com.zst.wemo;
    import com.zst.wemo.dao.user.UserMapper;
    import com.zst.wemo.model.user.User;
    import org.junit.Assert;
    import org.junit.jupiter.api.Test;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.test.context.SpringBootTest;
    import java.util.List;
    //Junit Test类
    @SpringBootTest
    class WemoApplicationTests {
        @Autowired
        private UserMapper userMapper;
        
        @Test
        void contextLoads() {
        }
        @Test
        public void testSelect() {
            System.out.println(("----- selectAll method test ------"));
            List<User> userList = userMapper.selectList(null);
            Assert.assertEquals(5, userList.size());
            userList.forEach(System.out::println);
        }
    }
  • 相关阅读:
    Python 学习笔记 11.模块(Module)
    Python 学习笔记 8.引用(Reference)
    Python 学习笔记 9.函数(Function)
    Python 学习笔记 6.List和Tuple
    Python 学习笔记 4.if 表达式
    Python 学习笔记 2.自省
    Python 学习笔记 3.简单类型
    Python 学习笔记 7.Dictionary
    Python 学习笔记 5.对象驻留
    Python 学习笔记 10.类(Class)
  • 原文地址:https://www.cnblogs.com/wangle1001986/p/14765590.html
Copyright © 2011-2022 走看看