layui如何上传图片
发表于:2025-02-07 作者:千家信息网编辑
千家信息网最后更新 2025年02月07日,这篇文章给大家分享的是有关layui如何上传图片的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。layui上传与bootstrap上传相似,只是不需要下插件,layui自带的
千家信息网最后更新 2025年02月07日layui如何上传图片
这篇文章给大家分享的是有关layui如何上传图片的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
layui上传与bootstrap上传相似,只是不需要下插件,
layui自带的已够用 先看一下前台界面,这里是用到的上传头像
先点击开始上传,头像上传至服务器中,
返回json添加至form表单中,与其他数据一起提交
先看一下jsp界面
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>个人资料
与Controller交互的.do
package com.supermanager.controller;import java.io.File;import java.io.IOException;import java.util.Date;import java.util.List;import java.util.Random;import javax.annotation.Resource;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpSession;import org.springframework.context.annotation.Scope;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.ModelAttribute;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.ResponseBody;import org.springframework.web.multipart.MultipartFile;import com.supermanager.entity.LogsInfo;import com.supermanager.entity.RoleInfo;import com.supermanager.entity.StoragesInfo;import com.supermanager.entity.UserInfo;import com.supermanager.service.LogsService;import com.supermanager.service.RoleInfoService;import com.supermanager.service.StoragesService;import com.supermanager.service.UserInfoService;import net.sf.json.JSONArray;@Controller@Scope("prototype")public class UserInfoController { @Resource private UserInfoService userInfoService; @Resource private LogsService logService; @Resource private RoleInfoService roleInfoService; @Resource private StoragesService storagesService; /** * 修改个人资料 * @param session * @param file * @param ui * @return * @throws IOException * @throws IllegalStateException */ @RequestMapping(value="updatePersonalById") public @ResponseBody String updatePersonal(@RequestParam("file") MultipartFile file,@ModelAttribute UserInfo ui,HttpServletRequest request) throws IllegalStateException, IOException{ String oldName = file.getOriginalFilename(); String path = request.getServletContext().getRealPath("/upload/"); String fileName = changeName(oldName); String rappendix = "upload/" + fileName; fileName = path + "/" + fileName; File file1 = new File(fileName); file.transferTo(file1); String str = "{\"code\": 0,\"msg\": \"\",\"data\": {\"src\":\"" + rappendix + "\"}}"; return str; } public static String changeName(String oldName){ Random r = new Random(); Date d = new Date(); String newName = oldName.substring(oldName.indexOf('.')); newName = r.nextInt(99999999) + d.getTime() + newName; return newName; } @RequestMapping(value="updatePersonalByIdSuccess") public String updatePersonalByIdSuccess(@ModelAttribute UserInfo ui){ UserInfo uif = userInfoService.FindUserByUserId(ui.getUserId()); ui.setRoleId(uif.getRoleId()); ui.setUserSex(uif.getUserSex()); ui.setUserAge(uif.getUserAge()); int a = userInfoService.Update(ui); if(a!=0){ return "redirect:exitSystem.do"; } return "error"; } }
感谢各位的阅读!关于"layui如何上传图片"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
头像
图片
个人
个人资料
内容
密码
更多
界面
篇文章
资料
不错
实用
相似
前台
只是
地址
够用
姓名
插件
数据
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
信息集成软件开发服务
ios 英雄联盟手游服务器
上海甘客网络技术
服务器配置域名解析
榆次商场大屏互动软件开发公司
只适用于数据库表的索引
pywebio 数据库
轻量应用服务器2核4g能干什么
女孩学网络安全
自建网页数据库管理系统
滨州医学院网络技术考什么
江苏扬州服务器如何
宝德网络安全
客户管理系统 数据库
软件开发 人力资源管理
24核心服务器CPU
数据库添加字段sql语句
黄石网络安全公司
包职院网络安全规划
计算机网络技术专业能否报考一建
数据库软件叫什么意思
笔记本电脑设置为打印机服务器
服务器管理入口
服务器上的内容安全吗
世通网络技术
虎牙贱圣龙珠服务器怎么进
学软件开发给钱吗
网络安全意识培训包含哪些内容
软件开发风险策划
手机国家税务软件开发票