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的文件上传,来将老夫毕生功力灌顶传授给你 首先文件上传,又简至 ...
随机推荐
- JUI/DWZ 分页 Servlet
分页介绍 参考:官方用户手册中的"分页组件" 分页思路服务器返回当前页的数据,总条数,再由js来生成分页标签.分页是配合服务器端来处理的, 不是存js做的分页. 因 ...
- java程序的加载过程
昨天笔试阿里有个求java程序加载过程的题目很是复杂,回来研究了好久才有点明白,整理一下.原题代码如下,判断输出: public class StaticTest { public static in ...
- JAVA之旅(六)——单例设计模式,继承extends,聚集关系,子父类变量关系,super,覆盖
JAVA之旅(六)--单例设计模式,继承extends,聚集关系,子父类变量关系,super,覆盖 java也越来越深入了,大家加油吧!咱们一步步来 一.单例设计模式 什么是设计模式? JAVA当中有 ...
- 【翻译】Ext JS 5的平板支持
原文:Ext JS 5 Tablet Support Ext JS已被公认为桌面Web应用程序的领先框架.自从平板开始在全球挑战PC的销售,无论是个人还是企业,电脑横向的应用已经产生急剧的变化.Sen ...
- 【测试】Gunicorn , uWSGI同步异步测试以及应用场景总结
最近使用uwsgi出了一些问题,于是测试下Gunicorn测试对比下 环境 一颗cpu 1g内存 Centos系统 Django作为后端应用,Gunicorn默认模式和异步模式,响应基本是无阻塞类型 ...
- nginx 的编译参数详解
内容有些多,一眼看来难免头昏脑胀,但坚持看完,相信你一定会有所收获. nginx参数: --prefix= 指向安装目录 --sbin-path 指向(执行)程序文件(nginx) --conf-pa ...
- 【单片机】基于有方GPRS的智能电梯控制系统
前一篇文章<时钟及温度的显示>中所介绍的作品,是作为一个单片机新手在暑假学了一个月的单片机之后,做的第一个综合性作品,涵盖了二极管.蜂鸣器.数码管.液晶屏.按键.时钟芯片.温度传感器的控制 ...
- ffdshow 源代码分析 9: 编解码器有关类的总结
===================================================== ffdshow源代码分析系列文章列表: ffdshow 源代码分析 1: 整体结构 ffds ...
- 超过1个G免费资源,16套质量超高风格多样的移动UIKIT
编者按:前两天发了一篇价值4000元的收费可商用Web 模版,今天来一波同样高质量的的App UI KIT,包括音乐/餐厅/运动等等类型的App,无论是下载来学习还是商用(对的可商用!)都不容错过,@ ...
- 写论文如何做相关工作(realted work)的调研
1.找一篇目标研究领域的中文综述,读懂,对该领域有了些基本的了解,如何找到好的综述,就是要关注一些大牛的实验组的综述和进展: 2.找该中文综述引用的外文文献来看,通常是一些比较经典的文献 3.找这些外 ...