一、图片路径配置
1、第一种方法:在配置文件里配置
#配置访问路径
web-file-path=D://teaPicture/
spring.resources.static-locations=file:${web-file-path}
2、第二种方法:写一个配置类
package com.tea.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Value("${web-file-path}")
private String filePath;
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
//临时文件目录
registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/resources/","classpath:/resources/","classpath:/static/","classpath:/public/","classpath:/web/","file:"+filePath);
WebMvcConfigurer.super.addResourceHandlers(registry);
}
}
注意:目录结构
二、mybatis的分页
1、在pom文件里引入分页包
<!--分页-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.5</version>
<exclusions>
<exclusion>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
2、使用分页的代码实例
1)service接口
package com.tea.service;
import com.tea.entity.HomeTea;
import com.tea.util.PageInfo;
public interface IHomeTeaService {
PageInfo<HomeTea> getHomeTea(HomeTea hometea, PageInfo<HomeTea> pageInfo);
}
2)service实现类
@Override
public PageInfo<HomeTea> getHomeTea(HomeTea hometea, PageInfo<HomeTea> pageInfo) {
Page<HomeTea> page = PageHelper.startPage(pageInfo.getPageNum(), pageInfo.getPageSize(), true);
List<HomeTea> hometeas = homeTeaMapper.getHomeTea(hometea);//这个的查询sql (select * from hometea where 1=1)
pageInfo.setTotal(page.getTotal());
pageInfo.setList(hometeas);
return pageInfo;
}