Single table query and paging according to time

1,yml perhaps properties Medium configuration data source , Just configure your own database .
mybatis-plus: mapper-locations: ../mapper/*.xml configuration: log-impl:
org.apache.ibatis.logging.stdout.StdOutImpl // This is for printing on the console SQL sentence .

2, Import Mybatis-Plus Dependency of , What I use here is 3.4.0 Version of , You must pay attention to the dependent version number here ,3.4.0 in the future , The configuration of the paging plug-in has been updated . Here's an emphasis , If the built-in paging plug-in fails , Check the version and configuration first .
<!--MyBatis-plus to configure --> <dependency> <groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId> <version>3.4.0</version>
3, Create a new config, this config write Mybatis-Plus Plug in configuration for ,MP There are many plug-in configurations for , Here is the paging configuration .
/** * be careful @MapperScan, use springboot If , The startup class is to scan the data layer , If only MP For data *
Library operation , In the startup class @MapperScan No need to write , Just write here . * */ @Configuration
@MapperScan("com.tiktang.dao") public class MybatisPlusConfig { /** *
IPage The page of uses an interceptor , Belongs to physical paging , The benefit is that when processing large amounts of data , Fast query speed . * Interested students can see what is physical paging and logical paging . * @return
*/ @Bean public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
// towards Mybatis Add a paging interceptor to the filter chain interceptor.addInnerInterceptor(new
PaginationInnerInterceptor(DbType.MYSQL)); return interceptor; } @Bean public
ConfigurationCustomizer configurationCustomizer() { return configuration ->
configuration.setUseDeprecatedExecutor(false); } }
4, Entity class of single table entity object , Fields in your own database , This step is omitted .

5, Procedure steps , I usually write first Mapper.xml,Mapper,service,serviceImpl,controller. According to this step , The first thing to write is Mapper.xml, But it is a single table operation , Again MP frame , No more writing Mapper.xml Yes .

//News Is an entity class @Repository public interface NewsMapper extends BaseMapper<News> { }
//News As entity ,page Is the current page ,pageSize How many per page public interface NewsService { IPage<News>
queryNewsList(Integer page, Integer pageSize); }
@Service public class NewsServiceImpl implements NewsService { @Autowired
private NewsMapper newsMapper; @Override public IPage<News>
queryNewsList(Integer page, Integer pageSize) { // Page<News> page1 = new
Page<>(page,pageSize); // Here is a time sequence QueryWrapper<News> queryWrapper = new
QueryWrapper<>(); queryWrapper.orderByDesc("news_time");
//MP Self contained selectPage method , Interested students , You can take a look at the source code IPage<News> iPage =
newsMapper.selectPage(new Page<>(page, pageSize), queryWrapper); return iPage;
} }
@GetMapping("/newsList") public Result<News> queryNewsList(@RequestParam
Integer page, @RequestParam Integer pageSize){ IPage<News> iPage =
newsService.queryNewsList(page, pageSize); return
Result.ok().data("iPage",iPage); }
Result Is my own encapsulated result set , I will write about returning the unified result set again when I have time .

Query this single table and sort by time .

@GetMapping("/getCompanyInvest") public Result getCompanyInvest(@RequestParam
String companyId, @RequestParam Integer currentPage, @RequestParam Integer
pageNumber){ QueryWrapper<CompanyInvest> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("company_id",companyId); Page<CompanyInvest> page = new
Page<>(currentPage,pageNumber); IPage<CompanyInvest> companyInvestIPage =
companyInvestMapper.selectPage(page,queryWrapper); Map<String,Object> map = new
HashMap<>(); map.put(" Sub page of company investment information ",companyInvestIPage); return
Result.ok().data(map); }

Daily Recommendation
views 251
views 217
views 200