mybatis-plus强大的条件构造器直接干代码

导入mybatis-plus依赖

		<dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.1.0</version>
        </dependency>

实体类注解对应

@TableName("user")   //代表表名
public class User {
	//映射id
    @TableId(value = "id",type = IdType.AUTO)
    private Integer id;
    //映射字段和表字段对应
    @TableField("username")
    private String username;
    //映射字段和表字段对应
    @TableField("password")
    private String password;

Mapper接口类继承BaseMapper 不需要xml了

@Mapper
public interface UserMapper extends BaseMapper<User> {
}

Service接口类继承BaseMapper 同上

public interface UserService extends BaseMapper<User> {
}

实现类继承UserService 重写BaseMapper 的全部方法

用到哪个写哪个吧,不用的默认返回就OK

@Service
public class UserserviceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public int insert(User entity) {
        //如这个
        return userMapper.insert(entity);
    }

    @Override
    public int deleteById(Serializable id) {
        return userMapper.deleteById(id);
    }

    @Override
    public int deleteByMap(Map<String, Object> columnMap) {
        return userMapper.deleteByMap(columnMap);
    }

    @Override
    public int delete(Wrapper<User> wrapper) {
        return userMapper.delete(wrapper);
    }

    @Override
    public int deleteBatchIds(Collection<? extends Serializable> idList) {
        return 0;
    }

    @Override
    public int updateById(User entity) {
        return 0;
    }

    @Override
    public int update(User entity, Wrapper<User> updateWrapper) {
        return 0;
    }

    @Override
    public User selectById(Serializable id) {
        return null;
    }

    @Override
    public List<User> selectBatchIds(Collection<? extends Serializable> idList) {
        return null;
    }

    @Override
    public List<User> selectByMap(Map<String, Object> columnMap) {
        return null;
    }

    @Override
    public User selectOne(Wrapper<User> queryWrapper) {
        return null;
    }

    @Override
    public Integer selectCount(Wrapper<User> queryWrapper) {
        return null;
    }

    @Override
    public List<User> selectList(Wrapper<User> queryWrapper) {
        return null;
    }

    @Override
    public List<Map<String, Object>> selectMaps(Wrapper<User> queryWrapper) {
        return null;
    }

    @Override
    public List<Object> selectObjs(Wrapper<User> queryWrapper) {
        return null;
    }

    @Override
    public IPage<User> selectPage(IPage<User> page, Wrapper<User> queryWrapper) {
        return null;
    }

    @Override
    public IPage<Map<String, Object>> selectMapsPage(IPage<User> page, Wrapper<User> queryWrapper) {
        return null;
    }
}

然后在Controller中使用

	public void selectOne() {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username", "admin");

        User user = mapper.selectOne(queryWrapper);
        System.out.println(user);
    }

你可能感兴趣的:(java,springboot,Wrapper构造器,mybatis-plus)