首先需要引入mybatisplus包
<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.1.1</version>
</dependency>
第一种注解方式:参数是通过#{}来接收的
public interface ApArticleMapper extends BaseMapper<ApArticle> {@Select("SELECT apa.* from ap_article apa LEFT JOIN ap_article_config aac on apa.id = aac.article_id where " +"aac.is_delete=0 and aac.is_down=0 and apa.channel_id=2 and publish_time>#{startTime}")List<ApArticle> selectRedisVoList(LocalDateTime startTime);
}
调用:
apArticleMapper.selectRedisVoList(startTime);
第二种xml方式:
public interface ApArticleMapper extends BaseMapper<ApArticle> {List<ApArticle> pageByOrder(@Param(value="start") Long start, @Param(value="size")Long size, @Param(value="channelId")Integer channelId);
}
xml文件应配置在和mapper平级的resources目录下或者修改yml中mybatis-plus的mapper映射路径
yml中修改如下(mybatis-plus和spring平级):
mybatis-plus:mapper-locations: classpath*:mapper/*.xmlxml文件中的内容:注意namespace要指定到需要配置的mapper上
<mapper namespace="com.jjw.article.mapper.ApArticleMapper"><select id="pageByOrder" resultType="com.jjw.article.pojo.ApArticle" parameterType="map">SELECT apa.* FROM ap_article apa LEFT JOIN ap_article_config aac on apa.id = aac.article_id<where><if test="channelId != null and channelId != 0">and apa.channel_id=#{channelId}</if>and aac.is_delete=0and aac.is_down=0</where>order by publish_time DESClimit #{start},#{size}</select>
</mapper>
结构如下:
调用方式:
apArticleMapper.pageByOrder(start,size,body.getChannelId());