SpringBoot集成Mybatis-Plus

1、引入maven依赖

<dependency>
	<groupId>mysql</groupId>
	<artifactId>mysql-connector-java</artifactId>
	<version>5.1.37</version>
</dependency>
<dependency>
	<groupId>com.alibaba</groupId>
	<artifactId>druid-spring-boot-starter</artifactId>
	<version>1.1.10</version>
</dependency>
<dependency>
	<groupId>com.baomidou</groupId>
	<artifactId>mybatis-plus-core</artifactId>
	<version>3.1.2</version>
</dependency>
<dependency>
	<groupId>com.baomidou</groupId>
	<artifactId>mybatis-plus-boot-starter</artifactId>
	<version>3.1.2</version>
</dependency>

2、修改配置文件

#mybatis-plus config
mybatis-plus.mapper-locations=classpath*:/com/zbjt/datahome/api/center/mapper/xml/*.xml
mybatis-plus.type-aliases-package=com.zbjt.datahome.api.center.entity
mybatis-plus.configuration.map-underscore-to-camel-case: true
#控制台打印语句
#mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl

#mysql
spring.datasource.url=jdbc:mysql://10.200.73.54:3306/hybase_secondmark?useUnicode=true&useSSL=false&characterEncoding=utf-8
spring.datasource.username=dp
spring.datasource.password=dp
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.type: com.alibaba.druid.pool.DruidDataSource

3、开始编码

3.1、接口
import com.baomidou.mybatisplus.extension.service.IService;
import com.zbjt.datahome.api.center.entity.fazhibao.WebsiteCollection;

import java.util.List;

/**
 * @author pss
 * @Description:uthCustomer,channel
 * @date 2020/7/27 17:40
 */
public interface WebsiteCollectionService extends IService<WebsiteCollection> {
    public List<WebsiteCollection> getDataBymediaId(String authCustomer, String channel);
}
3.2、实现类
@Service
public class FazhibaoCollectionServiceImpl extends ServiceImpl<FazhibaoCollectionMapper, FazhibaoLog> implements FazhibaoCollectionService {

    @Autowired
    private FazhibaoCollectionMapper fazhibaoCollectionMapper;

    @Override
    public List<FazhibaoLog> getCollection(String authCustomer, String channel) {
        return fazhibaoCollectionMapper.getCollection(authCustomer,channel);
    }
}
3.3、mapper文件
@Mapper
public interface FazhibaoCollectionMapper extends BaseMapper<FazhibaoLog> {
    List<FazhibaoLog> getCollection(String authCustomer, String channel);
}
3.4、xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.zbjt.datahome.api.center.mapper.other.EdmDimCsReportThreeChannelThreeTypeListMMapper">


    <select id="selectPageVo"
            resultType="com.zbjt.datahome.api.center.entity.other.EdmDimCsReportThreeChannelThreeTypeListM">
        SELECT
        DISTINCT ON (title) id, department, title, publish_date as publishDate,
        channel_name AS channelName,department_ratio AS departmentRatio,summary_month AS summaryMonth,
        fgd_author AS fgdAuthor,fgd_author_ids AS fgdAuthorIds
        FROM
        edm_dim_cs_report_three_channel_three_type_list_m
        WHERE
        summary_month = #{summaryMonth}
        ORDER BY
        title,id DESC
    </select>

</mapper>
3.5、controller调用
@Autowired
    private WebsiteCollectionService websiteCollectionService;

    @Autowired
    private FazhibaoCollectionService fazhibaoCollectionService;

    @GetMapping(value = "/test")
    public ResponseEntity<ApiResult> test(@RequestParam(value = "pageSize", required = true) int pageSize,
                                          @RequestParam(value = "pageNum", required = true) int pageNum,
                                          @RequestParam(value = "auth_customer", required = true) String authCustomer,
                                          @RequestParam(value = "channel", required = true) String channel){
        Page<WebsiteCollection> page = new Page<WebsiteCollection>(pageNum,pageSize);
        QueryWrapper<WebsiteCollection> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("channel", channel);
        queryWrapper.eq("auth_customer", authCustomer);
        // List<WebsiteCollection> dataBymediaId = websiteCollectionService.list(queryWrapper);
        IPage<WebsiteCollection> pageInfo = websiteCollectionService.page(page, queryWrapper);
        List<WebsiteCollection> records = pageInfo.getRecords();
        records.forEach(System.out::println);
        return renderOkWithMeta(records, page.getTotal(), page.getPages());
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值