Mybatis 学习笔记四 MyBatis-Plus插件

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

Mybatis 学习笔记四 MyBatis-Plus插件

maven依赖

        
            com.baomidou
            mybatis-plus
            3.0.5
        

        
            org.apache.velocity
            velocity-engine-core
            2.0
        

        
            org.freemarker
            freemarker
            2.3.28
        

        
            org.projectlombok
            lombok
            1.18.4
            provided
        

配置

mybatis配置

conf.xml






注意:保持基本配置即可;

spring配置

applicationContext.xml




    
    
        
        
        
        
    

    
    
        
        
        
        
    

    
        
        
        
    

mapper配置

userMapper.xml





    
    

    

meng.mybatis.test.UserMapper类

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.util.List;

public interface UserMapper extends BaseMapper {
    List findUsers();

    User findUserByUserid(int id);
}

实体类

User.java

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

@TableName("users")
@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class User {
	private int id;
	private String name;
	private int age;

	@TableField(value = "stu_id")
	private String stuId;
}

Mybatis 学习笔记四 MyBatis-Plus插件_第1张图片

测试

        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        UserMapper userMapper = context.getBean(UserMapper.class);
        User user =  userMapper.selectById(1);
        System.out.println(user]");

源码

  • github sample地址
  • 官方文档
  • github mybatis-plus地址

转载于:https://my.oschina.net/mengzhang6/blog/2877903

你可能感兴趣的:(Mybatis 学习笔记四 MyBatis-Plus插件)