mybatis-plus CURD

mybatis-plus CURD

mybatis-plus

  1. 查询指定字段
    .select(“字段名”,“字段名”)
EsinfoAreaKeeperObject esinfoAreaKeeperObject = areaKeeperObjectMapper.selectOne(new QueryWrapper<EsinfoAreaKeeperObject>()
                .select("fldObjectGuid")
                .eq("fldKeeperGuid", keeperId));

2.查询语法(网上找的图)
在这里插入图片描述

mybatis-plus 插入添加多个对象save方法

BaseMapper没有方法插入多个对象,但 IService 有插入多个对象的方法

private IAreaKeeperObjectService iAreaKeeperObjectService;
List<EsinfoAreaKeeperObject> areaKeeperObjectVos = esinfoAreakeeper.getAreaKeeperObjectVos();
iAreaKeeperObjectService.saveBatch(areaKeeperObjectVos);

关联查询,自动映射

  1. xml 中
    type => 映射的对象,id=“cmap” => cmap 是映射对象的别称
    collection,使用标签,property=>映射的对象,select=>使用的方法,column=>对应的关联值
    result 标签中,column=>数据库字段名,property=>映射对象字段名
<resultMap type="com.es.base.info.vo.EsinfoObjectandownerVo" id="cmap">
             <id property="fldGuid" column="fldGuid" />
             <result column="fldObjectGuid" property="fldObjectGuid"/>
             <result column="fldOwnerGuid" property="fldOwnerGuid"/>
             <collection property="esInfoObjectVo" select="com.es.info.mapper.EsinfoObjectMapper.selectByfldObjectGuid" column="fldObjectGuid">
            </collection>
            <collection property="esinfoPersonbaseVo" select="com.es.info.mapper.EsinfoPersonbaseMapper.selectOnePersonbase" column="fldOwnerGuid">
            </collection>
    </resultMap>
  1. 实体类中
    字段名要与 xml 中相同,可以不用全部映射
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value="对象")
public class EsinfoObjectandownerVo {
    @ApiModelProperty(value = "主键")
    private String fldGuid;

    @ApiModelProperty(value = "小区主键")
    private String fldAreaGuid;

    @ApiModelProperty(value = "资源主键")
    private String fldObjectGuid;

    @ApiModelProperty(value = "客户主表主键")
    private String fldOwnerGuid;

    @ApiModelProperty(value = "居住关系")
    private Integer fldIsOwner;

    @ApiModelProperty(value = "是否计费(0否 1是)")
    private Integer fldIsCharge;

    @ApiModelProperty(value = "客户等级(是否是重要客户)")
    private Integer fldRelation;

    @ApiModelProperty(value = "开始日期")
    private String fldBeginDate;

    @ApiModelProperty(value = "结束日期")
    private String fldEndDate;

    @ApiModelProperty(value = "备注")
    private String fldDesc;

    @ApiModelProperty(value = "是否当前(0否 1是)")
    private Integer fldIsCurrent;

    @ApiModelProperty(value = "迁出客户原因")
    private String fldOutReason;

    @ApiModelProperty(value = "业主对象")
    private List<EsinfoPersonbaseVo> esinfoPersonbaseVo;

    @ApiModelProperty(value = "业主资源对象")
    private EsInfoObjectVo esInfoObjectVo;
}
  1. 方法中
    resultMap => 选择映射对象的别称,就是上面设置的
<select id="selectList" parameterType="java.lang.String" resultMap="cmap">
        select fldOwnerGuid,fldObjectGuid from esinfo_objectandowner where fldObjectGuid = #{fldObjectGuid};
    </select>

查询时,添加一行默认值的列

别名要是取的和映射字段名一样,也会自动映射

select #{传入的字段名} as 别名 from 表

循环查询,循环条件查询

collection => 循环对象
item => 每次循环出的对象
open => 循环体前加的值,close => 循环体后加的值,separator => 每次循环后加的值

<select id="selectListByObjectIds" resultType="com.es.base.info.vo.AreaKeeperObjectVo">
        select distinct fldObjectGuid,fldIsHouse,#{keeperId} as fldKeeperGuid
        from esinfo_areakeeperobject as a
        where fldObjectGuid in
        <foreach collection="objectIds" item="objectId" open="(" close=")" separator=",">
             #{objectId}
        </foreach>
    </select>

查询时判断,赋予新值方法,case when then

case相当与你要查询的字段


select 
case 字段名
when 条件1
then 满足条件的值
when 条件2
then 满足条件的值
when 条件3
then 满足条件的值
else
then 其余条件的值
end 
as 别名
from 表名

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值