引入mybatis-plus

1.引入的依赖


         
             com.baomidou
             mybatis-plus-boot-starter
             3.4.3
         

 
         
             com.baomidou
             mybatis-plus-boot-starter
             3.2.0
         

2.编辑Mapper接口

public interface UserMapper extends BaseMapper

3.编写service

public interface UserService extends IService

4.编写ServiceImpl

public class UserServiceImpl extends ServiceImpl implements UserService{
}

5.查询方法


QueryWrapper wrapper = new QueryWrapper<>();
        //等于 
        wrapper.eq("user_id",userId);
        //模糊查询
        wrapper.like("username","%张%");

 mysql中模糊查询时可用concat

select userName from user where userName LIKE CONCAT(’%’, ‘张’, ‘%’)

你可能感兴趣的:(java,spring,mysql,sql,后端)