mybatis plus conditional constructor queryWrapper learning

1. What is queryWrapper?
queryWrapper is an object encapsulation operation class that implements query in mybatis plus. Its hierarchical relationship is as follows

In the picture above,

Wrapper: conditionally constructed abstract class, the top parent class, and 4 methods are provided in the abstract class, and the source code is posted on the west. AbstractWrapper
: used for encapsulating query conditions and generating sql where conditions
.
LambdaQueryWrapper: It can be understood from the name that it is used for the query Wrapper used by Lambda syntax
LambdaUpdateWrapper: Lambda update package Wrapper
QueryWrapper: Entity object package operation class, not using lambda syntax
UpdateWrapper: Update condition package, used for Entity object update operation

2. Use
the key code used in the demo
QueryWrapper<PbListBlack> sectionQueryWrapper = new QueryWrapper<>();
sectionQueryWrapper.eq("OPTYPE", 1);
sectionQueryWrapper.eq("BLTYPE", 1);
List<PbListBlack> pbListBlacks = iPbListBlackMapper.selectList(sectionQueryWrapper);
The meaning of the above code is to create a QueryWrapper object first, the type is PbListBlack object, which is the entity data you need to query,

sectionQueryWrapper.eq("OPTYPE", 1);

sectionQueryWrapper.eq("BLTYPE", 1);

These two sentences mean the OPTYPE in the database table corresponding to the PbListBlack object, and the value of the BLTYPE field should be 1

Then call the iPbListBlackMapper.selectList method, and the input parameter is the newly created query object encapsulation class

Paste the code for the query entity below

@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("PB_LIST_BLACK")
@ApiModel(value = "PB_LIST_BLACK对象", description = "")
public class PbListBlack extends Model<PbListBlack> {
   @TableField("ID")
   private Long id;

   @TableField("USERID")
   private String userId;
   @TableField("SPGATE")
   private String spgate;
   @TableField("SPNUMBER")
   private String spnumber;
   @TableField("PHONE")
   private Long phone;
   @TableField("OPTYPE")
   private Integer optype;
   @TableField("OPTTIME")
   private Timestamp optTime;
   @TableField("CORPCODE")
   private String corpCode;
   @TableField("SVRTYPE")
   private String svrType;

   @TableField("MSG")
   private String msg = " ";

   @ApiModelProperty(value = "Blacklist type. 1: SMS; 2: MMS")
   @TableField("BLTYPE")
   private Integer blType;


}

Then the code of iPbListBlackMapper', the code is simple

@Repository
public interface IPbListBlackMapper extends BaseMapper<PbListBlack> { } Only the base-level BaseMapper interface is required, so that the bottom-level encapsulation method of mybatis plus can help you query the data you have set query conditions for

When your Mapper inherits the BaseMapper interface, you can get the CRUD function without writing the mapper.xml file.
3. QueryWrapper method


 

 

Guess you like

Origin blog.csdn.net/qq_45991812/article/details/131779739