mybatis-plus入门教程

1、引入依赖(springboot工程)


			com.baomidou
			mybatis-plus-boot-starter
			3.3.1.tmp
		

 

2、定义实体类

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

@Data
@TableName("user")
public class User implements Serializable {
    @TableId("id")
    private Integer id;

    @TableField("username")
    private String username;

    private String password;

    private Date birthday;

    private Byte sex;

    private String phone;

    private String email;

    private static final long serialVersionUID = 1L;

}

 

3、mapper层CRUD通用接口

import com.asiainfo.group.springbootmybatisdemo.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;


public interface UserMapper extends BaseMapper {
    
}

 

4、service层通用CRUD接口

 

4.1、接口

import com.asiainfo.group.springbootmybatisdemo.entity.User;
import com.baomidou.mybatisplus.extension.service.IService;


public interface UserService extends IService {

    

}

 

4.2、实现类

import com.asiainfo.group.springbootmybatisdemo.entity.User;
import com.asiainfo.group.springbootmybatisdemo.mapper.UserMapper;
import com.asiainfo.group.springbootmybatisdemo.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserServiceImpl extends ServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

}

 

你可能感兴趣的:(mybatis,spring,spring,boot,mybatis)