springboot中使用分页,文件上传,jquery的具体步骤(持续更新)
分页:
pom.xml 加依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.1.2</version>
</dependency>
Service 里方法中
public PageInfo<User> findAll(int page,int size) {
PageHelper.startPage(page,size);
//源代码不变
PageInfo<User> model=new PageInfo<>(集合);
return model;
}
applicattion.yml中
#pagehelper分页插件
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
文件上传:
pom.xml中加依赖
<dependency>
<groupId>com.github.tobato</groupId>
<artifactId>fastdfs-client</artifactId>
<version>1.25.2-RELEASE</version>
</dependency>
总配置application.properties
#fastdfs2
fdfs.soTimeout=1500
fdfs.connectTimeout=600
fdfs.thumbImage.width=150
fdfs.thumbImage.height=150
fdfs.trackerList[0]=192.168.25.133:22122 #默认是22122的端口
fdfs.prefixpath= http://192.168.25.133/ #这是文件管理服务器ip
Controller中
@CrossOrigin(origins = "*", maxAge = 360)//设置上传最大值
@Controller
public class userAction {
@Value("${fdfs.prefixpath}")
private String prefixpath;
//图片上传
@RequestMapping("/upload")
@ResponseBody
public Map<String,Object> upload(MultipartFile file) throws Exception {
String exname = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1);
StorePath storePath = storageClient.uploadFile(file.getInputStream(), file.getSize(), exname, null);
String url = prefixpath + storePath.getFullPath();
System.out.println(url);
Map<String,Object> map=new HashMap<>();
map.put("urls",url);
System.out.println("----"+map.get("urls"));
return map;
}
html页面中
<body>
<form action="addUser" method="post">
<input type="hidden" id='photo' name='photo'/>
<table>
<tr>
<td>用户名</td>
<td><input type="text" name="uname"/></td>
</tr>
<tr>
<td>密码</td>
<td><input type="text" name="password"/></td>
</tr>
<tr>
<td>生日</td>
<td><input type="date" name="birthday"/></td>
</tr>
<tr>
<td>头像</td>
<td><input type='file' id='file' name='file' form="pff" />
<a id='yla' href='' target='_blank'><img id='ylm' src='' width="200px" height="200px"/></a>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="提交"/>
</td>
</tr>
</table>
</form>
<form id='pff' method="post" enctype="multipart/form-data" th:action="@{upload}">
</form>
</body>
<script type="text/javascript" src="/webjars/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript" src="/jquery.form.min.js"></script>
<script type="text/javascript">
$("#file").change(function(){
alert(this.value);
if(this.value!=''){
$('#pff').ajaxSubmit({
type:'post',
dataType:'json',
success:function(data){
alert(data.urls);
$("#yla").attr("href",data.urls);
$("#ylm").attr("src",data.urls);
$("#photo").attr("value",data.urls);
}
});
}
})
</script>
jQuery
pom.xml中加依赖
<!--jquer-->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>2.1.4</version>
</dependency>
html页面,引入
<script type="text/javascript" src="/webjars/jquery/2.1.4/jquery.min.js"></script>
springboot中使用分页,文件上传,jquery的具体步骤(持续更新)的更多相关文章
- Spring中MultipartHttpServletRequest实现文件上传
Spring中MultipartHttpServletRequest实现文件上传 转贴自:http://my.oschina.net/nyniuch/blog/185266 实现图片上传 用户必须能 ...
- ASP.NET 中对大文件上传的简单处理
在 ASP.NET 开发的过程中,文件上传往往使用自带的 FileUpload 控件,可是用过的人都知道,这个控件的局限性十分大,最大的问题就在于上传大文件时让开发者尤为的头疼,而且,上传时无法方便的 ...
- springboot(九)文件上传
在企业级项目开发过程中,上传文件是最常用到的功能.SpringBoot集成了SpringMVC,当然上传文件的方式跟SpringMVC没有什么出入.下面我们来创建一个SpringBoot项目完成单个. ...
- Springboot 一行代码实现文件上传 20个平台!少写代码到极致
大家好,我是小富~ 技术交流,公众号:程序员小富 又是做好人好事的一天,有个小可爱私下问我有没有好用的springboot文件上传工具,这不巧了嘛,正好我私藏了一个好东西,顺便给小伙伴们也分享一下,d ...
- struts2中简单的文件上传
2016-08-31 一. 文件上传 利用commons-fileupload-1.2.1.jar实现简单的上传文件,首先在页面上填写表单,记得加上enctype="multip ...
- SecureCRT中的ftp文件上传
原文地址:http://www.blogbus.com/jjuan-flake-logs/59745331.html SecureCRT与SshClient不同的就是,SecureCRT没有图形化的文 ...
- Spring中MultipartHttpServletRequest实现文件上传 生成缩略图
转贴自:http://my.oschina.net/nyniuch/blog/185266 实现图片上传 用户必须能够上传图片,因此需要文件上传的功能.比较常见的文件上传组件有Commons Fil ...
- ASP.NET中的FileUpload文件上传控件的使用
本篇文章教大家如何将客户端的图片或者文件上传到服务器: 无论是上传图片(.jpg .png .gif等等) 文档(word excel ppt 等等). 第一步:放入以下三个控件 Image控件,Fi ...
- SSM-SpringMVC-32:SpringMVC中灌顶传授文件上传
------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 我将用自认为最简单的语言,描述Springmvc的文件上传,来将老夫毕生功力灌顶传授给你 首先文件上传,又简至 ...
随机推荐
- JSTL之forEach的使用详解(简单的技术说得很详细)
在使用JSTL的核心标签库forEach之前,首先需要在JSP中通过taglib指令引入核心标签库: <%@ taglib uri="http://java.sun.com/jsp/j ...
- python 内存NoSQL数据库
python 内存NoSQL数据库 来自于网络,经过修改,秉承Open Source精神,回馈网络! #!/usr/bin/python #-*- coding: UTF-8 -*- # # memd ...
- printf函数压栈解惑
最近看到一些程序员的笔试题目,经常会考到printf函数的参数压栈问题,总体来讲就是参数从右向左依次压栈,再出栈,但是今天看到一个看似很简单的题目,却一直找不到头绪.题目如下: #include &l ...
- UNIX环境高级编程——select、poll和epoll
一.select select目前几乎在所有的平台上支持,其良好跨平台支持也是它的一个优点,事实上从现在看来,这也是它所剩不多的优点之一. select的一个缺点在于单个进程能够监视的文件描述符的数量 ...
- General Ledger Useful SQL Scripts
General Ledger Useful SQL Scripts – Oracle Applications 11i Contents GL Set of Books Configuration O ...
- Android万能适配器Adapter-android学习之旅(74)
万能适配器的代码的github地址是https://github.com/fengsehng/CommonAdapter 万能适配器的代码的github地址是https://github.com/fe ...
- 【Qt编程】基于Qt的词典开发系列<二>--本地词典的设计
我设计的词典不仅可以实现在线查单词,而且一个重大特色就是具有丰富的本地词典库:我默认加入了八个类型的词典,如下所示: 由于是本人是通信专业,因此加入了华为通信词典.电子工程词典,又由于我喜爱编程,也加 ...
- 程序员的视角:java 线程
在我们开始谈线程之前,不得不提下进程. 无论进程还是线程都是很抽象的概念,有一个关于进程和线程很形象的比喻能帮我们更好的理解. 进程就像个房子,房子是一个包含了特定属性的容器,例如空间大小.卧室数量等 ...
- java5后的并发池
本文可作为传智播客<张孝祥-Java多线程与并发库高级应用>视频的学习记录. 为什么需要并发池 之前写并发的时候 new Thread(new Runnable(){ public voi ...
- Android特效专辑(九)——仿微信雷达搜索好友特效,逻辑清晰实现简单
Android特效专辑(九)--仿微信雷达搜索好友特效,逻辑清晰实现简单 不知不觉这个春节也已经过完了,遗憾家里没网,没能及时给大家送上祝福,今天回到深圳,明天就要上班了,小伙伴们是不是和我一样呢?今 ...