上传图片
<form action="add" method="post" enctype="multipart/form-data"> 日期:<input type="date" name="date" value=""><br> 类型:<select name="t_id"> <c:forEach items="${types}" var="t"> <option value="${t.t_id}">${t.type} </c:forEach> </select> <br> 题目:<input type="text" name="title" onblur="ti()" value=""> <br> 图片:<input type="file" name="myfile" value=""> <br> <button>提交</button> </form>
@SuppressWarnings("deprecation") @RequestMapping("add") public Object add(MultipartFile myfile,HttpServletRequest request,Car car) throws IllegalStateException, IOException { String string = UUID.randomUUID().toString(); String realPath = request.getRealPath("/load/"); File file = new File(realPath+string); myfile.transferTo(file); car.setVivo(string); service.save(car); redisTemplate.opsForValue().set("car", car); System.err.println("保存入redis中"); kafkaTemplate.send("car", "car"); System.err.println("发送至卡夫卡"); return "redirect:findAll"; }