SpringBoot整合TomCat實(shí)現(xiàn)本地圖片服務(wù)器代碼解析
后臺(tái)控制層:
public static final String HEAD_IMG_DIR = "D:/upload/"; // 本地存放圖片路徑
//圖片上傳
@RequestMapping("/upload")
@ResponseBody
public String upload(MultipartFile file) {
//文件真實(shí)上傳名字
String filename = file.getOriginalFilename();
//文件大小
Long size = file.getSize();
String contentType = file.getContentType();
//文件臨時(shí)儲(chǔ)存到本地
String folder = HEAD_IMG_DIR;
//生成保存的文件名字,這個(gè)名字要存到數(shù)據(jù)庫(kù)中
String uuid = UUID.randomUUID().toString();
try {
file.transferTo(new File(folder + uuid));
} catch (IOException e) {
e.printStackTrace();
}
return uuid; // 返回給前臺(tái) uuid 需和信息一起存到數(shù)據(jù)庫(kù)
}
Tomcat:
打開(kāi)server.xml配置文件,在文件中加上以下代碼
<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note: A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level.
Documentation at /docs/config/service.html
-->
<!--配置TomCat本地服務(wù)器-->
<Service name="newtest">
<!--分配8020端口 -->
<Connector port="8020"
protocol="HTTP/1.1"
connectionTimeout="20000"
URIEncoding="GBK"
redirectPort="8443" />
<Engine name="newtest" defaultHost="localhost">
<!--name為項(xiàng)目訪問(wèn)地址 此配置的訪問(wèn)為http://localhost:8020 appBase配置tomcat下wabapps下的路徑-->
<Host name="localhost" appBase="D://TomCat//webapps" unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<!--資源地址--> <!-- 就是訪問(wèn)http://localhost:8020這個(gè)地址就是到D://upload這個(gè)目錄下 -->
<Context path="" docBase="D://upload" debug="0" reloadable="false"/>
</Host>
</Engine>
</Service>
<Service name="Catalina">
前臺(tái)頁(yè)面:
url: 'http://127.0.0.1:8020/',
<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;">
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
一文詳細(xì)springboot實(shí)現(xiàn)MySQL數(shù)據(jù)庫(kù)的整合步驟
Spring Boot可以很方便地與MySQL數(shù)據(jù)庫(kù)進(jìn)行整合,下面這篇文章主要給大家介紹了關(guān)于springboot實(shí)現(xiàn)MySQL數(shù)據(jù)庫(kù)的整合步驟,文中通過(guò)圖文以及代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-03-03
Java關(guān)于后端怎么去接收Date、LocalDateTime類型的參數(shù)詳解
這篇文章主要介紹了java關(guān)于后端怎么去接收Date、LocalDateTime類型的參數(shù),文中有詳細(xì)的代碼流程,對(duì)我們學(xué)習(xí)或工作有一定的參考價(jià)值,需要的朋友可以參考下2023-06-06
動(dòng)態(tài)配置Spring Boot日志級(jí)別的全步驟
這篇文章主要給大家介紹了關(guān)于動(dòng)態(tài)配置Spring Boot日志級(jí)別的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Spring Boot具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04
springboot無(wú)法加載yml配置文件的解決方案
在Spring?Boot項(xiàng)目中,嘗試加載yml配置文件時(shí)遇到問(wèn)題,通過(guò)一系列排查步驟發(fā)現(xiàn)配置文件未被打包到j(luò)ar文件中,導(dǎo)致無(wú)法加載,添加`spring-boot-maven-plugin`依賴后,配置文件被打包,問(wèn)題解決2024-12-12
Windows下Java調(diào)用OCR進(jìn)行圖片識(shí)別
這篇文章主要為大家詳細(xì)介紹了Windows下Java調(diào)用OCR進(jìn)行圖片識(shí)別,通過(guò)Tesseract-OCR對(duì)圖片進(jìn)行識(shí)別,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-12-12
JavaFX實(shí)現(xiàn)UI美觀效果代碼實(shí)例
這篇文章主要介紹了JavaFX實(shí)現(xiàn)UI美觀效果代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-07-07
Java實(shí)戰(zhàn)之兼職平臺(tái)系統(tǒng)的實(shí)現(xiàn)
這篇文章主要介紹了如何利用Java編寫(xiě)一個(gè)兼職平臺(tái)系統(tǒng),采用到的技術(shù)有Springboot、SpringMVC、MyBatis、ThymeLeaf等,感興趣的小伙伴可以了解一下2022-03-03

