本文主要是介绍mybatis-plus 多表查询通过Java实体,不写sql xml,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、java 实体
/*** <p>* 角色加租户名称* </p>** @author lohas*/
@Data
@TableName("t_role as tr LEFT JOIN t_auth_tenant_info as tati on tr.tenant_id = tati.id")
@ApiModel(value = "RoleVoEntity对象", description = "角色加租户名称")
public class RoleVoEntity extends Model {private static final long serialVersionUID = 1L;@ApiModelProperty(value = "tr.ID")@TableId(value = "tr.id")private String id;@ApiModelProperty(value = "角色标识", required = true)@TableField(value = "tr.identification")private String identification;@ApiModelProperty(value = "角色名称", required = true)@TableField(value = "tr.role_name")private String roleName;@ApiModelProperty(value = "描述")@TableField(value = "tr.description")private String description;@ApiModelProperty(value = "创建人ID")@TableField(value = "tr.creator_id")private String creatorId;@ApiModelProperty(value = "更新人ID")@TableField(value = "tr.update_id")private String updateId;@ApiModelProperty(value = "删除状态(0:删除、1: 正常)")@TableField(value = "tr.delete_flag")private String deleteFlag;@ApiModelProperty(value = "租户ID")@TableField(value = "tr.tenant_id")private String tenantId;@ApiModelProperty(value = "租户名称")@TableField(value = "tati.tenant_name")private String tenantName;
}
二、mapper
package com.lohas.mapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lohas.entity.RoleVoEntity;/*** <p>* 角色租户名称 Mapper 接口* </p>** @author lohas*/
public interface RoleVoMapper extends BaseMapper<RoleVoEntity> {}
三、sevice、seviceImpl 接口和实现层
package com.lohas.service;import com.baomidou.mybatisplus.extension.service.IService;
import com.lohas.entity.RoleVoEntity;/*** <p>* 角色租户名称 服务类* </p>** @author lohas*/
public interface IRoleVoService extends IService<RoleVoEntity> {}
package com.lohas.service.impl;import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lohas.entity.RoleVoEntity;
import com.lohas.mapper.RoleVoMapper;
import com.lohas.service.IRoleVoService;
import org.springframework.stereotype.Service;/*** <p>* 角色租户名称 服务实现类* </p>** @author lohas*/
@Service
public class RoleVoServiceImpl extends ServiceImpl<RoleVoMapper, RoleVoEntity> implements IRoleVoService {}
四、调用
@Resource
private RoleVoMapper roleVoMapper;@Resource
private IRoleVoService iRoleVoService;public ResponseMessage<Page<RoleVoEntity>> getList(RoleParam param) {LambdaQueryWrapper<RoleVoEntity> queryWrapper = new QueryWrapper<RoleVoEntity>().lambda();if (StringUtils.isNotBlank(param.getTenantId())) {queryWrapper.eq(RoleVoEntity::getTenantId, param.getTenantId());}queryWrapper.eq(RoleVoEntity::getDeleteFlag, AuthorityConstant.DATA_STATUS_1);// 第一种方法:通过roleVoMapper
// Page<RoleVoEntity> page = roleVoMapper.selectPage(new Page<>(param.getPage(), param.getPageSize()), queryWrapper);// 第二种方法:通过iRoleVoServicePage<RoleVoEntity> page = iRoleVoService.page(new Page<>(param.getPage(), param.getPageSize()), queryWrapper);return ResponseMessage.buildSuccess(page);}
这篇关于mybatis-plus 多表查询通过Java实体,不写sql xml的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!