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;
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) ;
IPage< WebsiteCollection> pageInfo = websiteCollectionService. page ( page, queryWrapper) ;
List< WebsiteCollection> records = pageInfo. getRecords ( ) ;
records. forEach ( System. out: : println) ;
return renderOkWithMeta ( records, page. getTotal ( ) , page. getPages ( ) ) ;
}