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);
    }
}

 

posted @ 2021-05-13 17:52  wangle100  阅读(36)  评论(0编辑  收藏  举报