Springboot框架实现图片上传显示并保存地址到数据库

本文介绍了如何在Springboot应用中实现图片上传,并将图片地址保存到数据库。通过配置application.properties,创建实体类、Controller、Service、DAO等组件,实现了从上传到展示的完整流程。访问路径为http://localhost:8080/product/index。
摘要由CSDN通过智能技术生成

1.在application.properties.xml中配置

# SpringBoot框架实现图片上传显示并保存地址到数据库
#spring boot上传文件大小限制
spring.http.multipart.max-file-size=200MB
spring.http.multipart.max-request-size=200MB

2.创建物品实体类productModel

package com.lyancafe.material.model;

/**
* @author scy 2018/8/22
*/
public class ProductModel {

private Integer id;
private String image;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getImage() {
return image;
}

public void setImage(String image) {
this.image = image;
}

@Override
public String toString() {
return "ProductModel{" +
"id=" + id +
", image='" + image + '\'' +
'}';
}
}

3.创建ProductController

package com.lyancafe.material.controller;

import com.lyancafe.material.bo.ProductService;
import com.lyancafe.material.model.ProductModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.UUID;

/**
* @author scy 2018/8/22
*/
@Controller
@RequestMapping("product")
public class ProductController {

@Autowired
private ProductServ
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值