layui如何上传图片
发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,这篇文章给大家分享的是有关layui如何上传图片的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。layui上传与bootstrap上传相似,只是不需要下插件,layui自带的
千家信息网最后更新 2026年11月01日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安全错误
数据库的锁怎样保障安全
互联网络科技
互联网为科技
互联网下的科技发展
互联网科技公司发展
紫鲸互联网科技
互联网科技视频
中盈科技互联网信息有限公司
金融科技与互联网金融相同和不同
电子科技大学互联网创业大赛
乌苏新华互联网科技做什么的
爱医互联网络科技
众安科技工业互联网合作
互联网第三次科技革命特征
广州有谷有贝互联网科技有限公司
互联网科技包装股
张家口科技产业互联网平台
美国五大互联网科技公司市值多少
互联网科技和医药行业
互联网科技的前景
互联网科技大会大佬
云南咖啡
互联网核心科技是什么
科技类互联网
上海致骋互联网科技
广州凡科互联网科技
互联网科技大会
互联网 科技馆
互联网媒体平台算高科技产业
互联网公司黑科技创始人
互联网科技和法律行业