首页 技术 正文
技术 2022年11月23日
0 收藏 457 点赞 4,828 浏览 2753 个字

分页:

  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>

  


    					
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,999
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,511
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,357
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,140
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848