1.分页PageHelper
1.导入jar包:
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>3.4.2-fix</version>
</dependency>
2.在Mybatis配置xml中配置拦截器插件:
<plugins>
<plugin interceptor="com.github.pagehelper.PageHelper">
<property name="dialect" value="mysql"></property>
</plugin>
</plugins>
3.service层代码:
//在查询前面添加PageHelper
PageHelper.startPage(page,rows);
List<TbItem> items=mapper.selectByExample(example);
//得到分页数据的详细信息对象
PageInfo<TbItem> info=new PageInfo<>(items);
//获得总条数
long total=info.getInfo();
2.文件上传
1.添加jar包:
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
2.配置文件springmvc:
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8"></property>
<property name="maxUploadSize" value="5242880"></property>
</bean>
3.controller代码:
//图片服务器URL地址
private String IMAGE_SERVER_URL;
public String picUpload(MultipartFile uploadFile){
//创建FastDFS客户端
FastDFSClient fastDfs=new FastDFSClient("classpath:conf/fast.conf");
//获取文件名
String fileName = uploadFile.getOriginalFilename();
//获取后缀名
String ext = fileName.substring(fileName.lastIndexOf(".")+1);
//上传文件返回文件名不包括域名
String paths = fastDfs.uploadFile(uploadFile.getBytes(), ext);
//组合图片的全路径
String path = IMAGE_SERVER_URL+paths;
// }
1.导入jar包:
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>3.4.2-fix</version>
</dependency>
2.在Mybatis配置xml中配置拦截器插件:
<plugins>
<plugin interceptor="com.github.pagehelper.PageHelper">
<property name="dialect" value="mysql"></property>
</plugin>
</plugins>
3.service层代码:
//在查询前面添加PageHelper
PageHelper.startPage(page,rows);
List<TbItem> items=mapper.selectByExample(example);
//得到分页数据的详细信息对象
PageInfo<TbItem> info=new PageInfo<>(items);
//获得总条数
long total=info.getInfo();
2.文件上传
1.添加jar包:
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
2.配置文件springmvc:
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8"></property>
<property name="maxUploadSize" value="5242880"></property>
</bean>
3.controller代码:
//图片服务器URL地址
private String IMAGE_SERVER_URL;
public String picUpload(MultipartFile uploadFile){
//创建FastDFS客户端
FastDFSClient fastDfs=new FastDFSClient("classpath:conf/fast.conf");
//获取文件名
String fileName = uploadFile.getOriginalFilename();
//获取后缀名
String ext = fileName.substring(fileName.lastIndexOf(".")+1);
//上传文件返回文件名不包括域名
String paths = fastDfs.uploadFile(uploadFile.getBytes(), ext);
//组合图片的全路径
String path = IMAGE_SERVER_URL+paths;
// }