springboot2 mybatis-plus custom queries

Using mybatis-plus files generated code generator

1, in the following ways mapper interfaces defined in the file :( a little complicated, deleted a lot, but a full-feature comparison, understanding soul)

The @Select ({ "<Script>" ,
             "the SELECT" ,
             "DR.id" , // delete a lot, the value of the query, titled the above mentioned id
             "DR.type AS of the type" , // ... the value of the query, rename type
             "the DATE_FORMAT (DR.date, '% Y-M-% D%% H:% I:% S') the aS Time" , // return date format
             "the FROM Table the DR" ,
             "the JOIN table_one the INNER D.id the ON DR.one_id = D " , the associated query //
             " the LEFT the JOIN table_two the ON DR.two_id = UM.id the UM " ,
             " the ON DR.man_id the LEFT the JOIN table_two UR = UR.id " ,
             " the WHERE the DR. {#} = teamId teamId and DR.state =. 1 " ,
             "<when test='userId != null'> AND DR.userId = #{userId} </when>",  // 根据参数增加条件
       "<when test='date != null'> AND DR.date BETWEEN STR_TO_DATE(CONCAT(#{date}, ' 00:00:00'),'%Y-%m-%d %H:%i:%s') AND STR_TO_DATE(CONCAT(#{date}, ' 23:59:59'),'%Y-%m-%d %H:%i:%s') </when>", // 时间段 "ORDER BY DR.date DESC",  // 排序 "LIMIT #{start}, #{count}",  // 分页 "</script>",}) List<Map> getList(@Param("teamId") String teamId, @Param("start") Integer start, @Param("count") Integer count, @Param("userId") String userId, @Param("state") Integer state, @Param("date") String date, );

2, in the implementation class so call:

public List<Map> getList(
            String teamId,
            Integer start,
            Integer count,
            String userId,
            Integer state,
            String date,
    ) {
        return this.baseMapper.getList(teamId, start, count, userId, state, date);
    }

3, when injected into the class that implements the interface, implementation class method calls the introduction of this parameter.

Guess you like

Origin www.cnblogs.com/SamNicole1809/p/12097728.html