idea安裝jerbel及文件上傳下載的實(shí)現(xiàn)示例
一、JRebel
1.1 Jrebel介紹
JRebel是一個(gè)Java開發(fā)工具,它是一款用于實(shí)時(shí)代碼重載的插件。它的主要功能是在不重新啟動(dòng)應(yīng)用程序的情況下,將修改后的Java代碼實(shí)時(shí)應(yīng)用到正在運(yùn)行的應(yīng)用程序中,從而加快開發(fā)周期,提高開發(fā)效率。
- 實(shí)時(shí)代碼重載:JRebel可以監(jiān)測(cè)開發(fā)人員對(duì)Java代碼的修改,并將這些修改實(shí)時(shí)應(yīng)用到正在運(yùn)行的應(yīng)用程序中,無需重新啟動(dòng)應(yīng)用程序。這樣,開發(fā)人員可以立即看到他們的代碼更改的效果,節(jié)省了重新編譯和部署的時(shí)間。
- 支持多種框架和服務(wù)器:JRebel支持多種Java框架和服務(wù)器,包括Spring、Hibernate、Java EE、Tomcat、Jetty等。無論是開發(fā)Web應(yīng)用程序還是企業(yè)級(jí)應(yīng)用程序,JRebel都可以與常用的開發(fā)框架和服務(wù)器集成,提供實(shí)時(shí)代碼重載的功能。
- 高度兼容性:JRebel與大多數(shù)Java開發(fā)工具和集成開發(fā)環(huán)境(IDE)兼容,如Eclipse、IntelliJ IDEA、NetBeans等。開發(fā)人員可以在他們喜歡的IDE中使用JRebel插件,無需切換到其他工具。
- 快速部署:JRebel可以加快應(yīng)用程序的部署速度,因?yàn)樗恍枰獙⑿薷暮蟮拇a應(yīng)用到運(yùn)行中的應(yīng)用程序,而不需要重新啟動(dòng)整個(gè)應(yīng)用程序。這對(duì)于大型應(yīng)用程序和復(fù)雜的部署環(huán)境特別有用。
- 支持多種開發(fā)場(chǎng)景:JRebel可以應(yīng)用于各種開發(fā)場(chǎng)景,包括本地開發(fā)、遠(yuǎn)程開發(fā)、云開發(fā)等。無論是單機(jī)開發(fā)還是分布式開發(fā),JRebel都可以提供實(shí)時(shí)代碼重載的功能。
總的來說,JRebel是一個(gè)強(qiáng)大的Java開發(fā)工具,它通過實(shí)時(shí)代碼重載的功能,使開發(fā)人員能夠在不重新啟動(dòng)應(yīng)用程序的情況下,快速應(yīng)用他們對(duì)Java代碼的修改。這大大提高了開發(fā)效率,減少了開發(fā)周期,使開發(fā)人員能夠更專注于代碼的編寫和調(diào)試。
1.2 Jrebel插件下載
首先我們要到idea的插件商店中下載jerbel插件

然后進(jìn)入gitup的開源網(wǎng)站,下載jerbel
Release v1.4 · ilanyu/ReverseProxy · GitHub
我用的是windows的就下載windows and64就行
下載到指定位置以后,雙擊啟動(dòng)服務(wù)

出現(xiàn)這個(gè)就是啟動(dòng)成功了
然后我們進(jìn)入idea,激活jerbel

點(diǎn)擊之后,會(huì)彈出激活界面

第一欄填入
http://localhost:8888/
后面接上GUID碼,這里也提供一個(gè)給大家,Create GUID online (guidgen.com)
第二欄是自己的電子郵箱
值得注意的是,我在填第一欄的地址的時(shí)候,使用127.0.0.1不可以,但是使用localhost就可以了,知道的大佬可以評(píng)論區(qū)指點(diǎn)指點(diǎn)
激活成功之后,我們就可以jerbel啟動(dòng)了
1.3 jerbel離線設(shè)置
因?yàn)槲覀兠恳淮问褂胑rble都需要啟動(dòng)服務(wù)太過麻煩,所以此時(shí)我們需要設(shè)置離線模式

我這里是因?yàn)槲乙呀?jīng)開啟了,沒開啟只有一個(gè)按鈕,是off開頭的,點(diǎn)擊開啟就好了
開啟之后我們?cè)俅螁?dòng)jerble就不需要再次啟動(dòng)服務(wù)了
值得注意的是,我們?cè)陉P(guān)閉程序之前,需要先關(guān)閉tomcat,再關(guān)閉服務(wù),這樣離線使用時(shí),我們就不需要再去開啟jerbel了
二、文件的上傳和下載操作
2.1 導(dǎo)入pom依賴
<commons-fileupload.version>1.3.3</commons-fileupload.version>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>${commons-fileupload.version}</version>
</dependency>2.2 配置文件上傳解析器
在spring-mvc.xml文件中添加文件上傳解析器。
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- 必須和用戶JSP 的pageEncoding屬性一致,以便正確解析表單的內(nèi)容 -->
<property name="defaultEncoding" value="UTF-8"></property>
<!-- 文件最大大小(字節(jié)) 1024*1024*50=50M-->
<property name="maxUploadSize" value="52428800"></property>
<!--resolveLazily屬性啟用是為了推遲文件解析,以便捕獲文件大小異常-->
<property name="resolveLazily" value="true"/>
</bean>這段代碼配置了一個(gè)名為"multipartResolver"的Bean,用于處理文件上傳。通過設(shè)置"defaultEncoding"屬性、"maxUploadSize"屬性和"resolveLazily"屬性,可以指定文件上傳時(shí)的字符編碼、最大上傳大小和延遲文件解析的行為。這樣,Spring框架在處理文件上傳時(shí)會(huì)根據(jù)這些配置進(jìn)行相應(yīng)的解析和限制。
2.3、指定文件上傳的表單
文件上傳的表單指定enctype屬性為multipart/form-data
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<base href="${pageContext.request.contextPath }" rel="external nofollow" rel="external nofollow" >
<title>文件上傳</title>
</head>
<body>
<form action="/file/upload" method="post" enctype="multipart/form-data">
<label>編號(hào):</label><input type="text" name="id" readonly="readonly" value="${param.id}"/><br/>
<label>圖片:</label><input type="file" name="imgFile"/><br/>
<input type="submit" value="上傳圖片"/>
</form>
</body>
</html>2.4、設(shè)置項(xiàng)目的映射地址
2.5、編寫控制器
package com.liwen.web;
import com.liwen.biz.UploadImgBiz;
import com.liwen.model.UploadImg;
import com.liwen.utils.PageBean;
import com.liwen.utils.PropertiesUtil;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.List;
/**
* @author 云村小威
* @site blog.csdn.net/Justw320
* @create 2023-09-10 16:50
*/
@Controller
@RequestMapping("/file")
public class UploadImgController {
@Autowired
private UploadImgBiz uploadImgBiz;
/*新增方法*/
@RequestMapping("/add")
public String save(UploadImg uploadImg, HttpServletRequest request) {
uploadImgBiz.insertSelective(uploadImg);
return "redirect:list";
}
/*刪除方法*/
@RequestMapping("/del/{id}")
public String del(@PathVariable("id") Integer id) {
uploadImgBiz.deleteByPrimaryKey(id);
return "redirect:/file/list";
}
/*修改方法*/
@RequestMapping("/edit")
public String edit(UploadImg uploadImg, HttpServletRequest request) {
uploadImgBiz.updateByPrimaryKeySelective(uploadImg);
return "redirect:list";
}
/*查詢方法*/
@RequestMapping("/list")
public String list(UploadImg uploadImg, HttpServletRequest request) {
PageBean pageBean = new PageBean();
pageBean.setRequest(request);
List<UploadImg> uploadImgs = uploadImgBiz.listPager(uploadImg, pageBean);
// ModelAndView modelAndView = new ModelAndView();
// modelAndView.addObject("UploadImgs", UploadImgs);
// modelAndView.addObject("pageBean", pageBean);
// modelAndView.setViewName("UploadImg/list");
request.setAttribute("uploadImgs", uploadImgs);
request.setAttribute("pageBean", pageBean);
return "file/list";
}
/*數(shù)據(jù)回顯*/
@RequestMapping("/preSave")
public String preSave(UploadImg uploadImg, HttpServletRequest request) {
if (uploadImg != null && uploadImg.getId() != null && uploadImg.getId() != 0) {
UploadImg img = uploadImgBiz.selectByPrimaryKey(uploadImg.getId());
request.setAttribute("img", img);
}
return "file/edit";
}
/*圖片上傳*/
@RequestMapping("upload")
public String upload(UploadImg img,MultipartFile imgFile) throws IOException {
//讀取配置文夾本地路徑和服務(wù)器路徑
String dir = PropertiesUtil.getValue("dir");
String server = PropertiesUtil.getValue("server");
//利用MultipartFile類接受前端傳遞到后臺(tái)的文件
System.out.println("文件名:"+imgFile.getOriginalFilename());
System.out.println("文件類型:"+imgFile.getContentType());
//將文件轉(zhuǎn)成流寫入到服務(wù)器
FileUtils.copyInputStreamToFile(imgFile.getInputStream(),new File(dir+imgFile.getOriginalFilename()));
//通過對(duì)象將圖片保存到數(shù)據(jù)庫(kù)
img.setImg(server+imgFile.getOriginalFilename());
uploadImgBiz.updateByPrimaryKeySelective(img);
return "redirect:list";
}
/*文件下載*/
@RequestMapping("/download")
public ResponseEntity<byte[]> download(UploadImg uploadImg, HttpServletRequest req){
try {
//先根據(jù)文件id查詢對(duì)應(yīng)圖片信息
UploadImg img = this.uploadImgBiz.selectByPrimaryKey(uploadImg.getId());
String diskPath = PropertiesUtil.getValue("dir");
String reqPath = PropertiesUtil.getValue("server");
//上面獲取的數(shù)據(jù)庫(kù)地址,需要轉(zhuǎn)換才能下載成本地路徑
String realPath = img.getImg().replace(reqPath,diskPath);
String fileName = realPath.substring(realPath.lastIndexOf("/")+1);
//下載關(guān)鍵代碼
File file=new File(realPath);
HttpHeaders headers = new HttpHeaders();//http頭信息
String downloadFileName = new String(fileName.getBytes("UTF-8"),"iso-8859-1");//設(shè)置編碼
headers.setContentDispositionFormData("attachment", downloadFileName);
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
//MediaType:互聯(lián)網(wǎng)媒介類型 contentType:具體請(qǐng)求中的媒體類型信息
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers, HttpStatus.OK);
}catch (Exception e){
e.printStackTrace();
}
return null;
}
}2.6、jsp頁(yè)面
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="w" uri="http://jsp.veryedu.cn" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link
rel="external nofollow"
rel="stylesheet">
<script
src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.0/js/bootstrap.js"></script>
<base href="${pageContext.request.contextPath }" rel="external nofollow" rel="external nofollow" >
<title>博客列表</title>
<style type="text/css">
.page-item input {
padding: 0;
width: 40px;
height: 100%;
text-align: center;
margin: 0 6px;
}
.page-item input, .page-item b {
line-height: 38px;
float: left;
font-weight: 400;
}
.page-item.go-input {
margin: 0 10px;
}
</style>
</head>
<body>
<form class="form-inline"
action="/file/list" method="post">
<div class="form-group mb-2">
<input type="text" class="form-control-plaintext" name="name"
placeholder="請(qǐng)輸入用戶名稱">
</div>
<button type="submit" class="btn btn-primary mb-2">查詢</button>
<a class="btn btn-primary mb-2" href="/file/preSave" rel="external nofollow" >新增</a>
</form>
<table class="table table-striped">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">用戶</th>
<th scope="col">圖片</th>
</tr>
</thead>
<tbody>
<c:forEach var="i" items="${uploadImgs }">
<tr>
<td>${i.id }</td>
<td>${i.name }</td>
<td>
<img src="${i.img }" style="width: 200px;height: 100px;">
</td>
<td>
<a href="/file/preSave?id=${i.id}" rel="external nofollow" >修改</a>
<a href="/file/del/${i.id}" rel="external nofollow" >刪除</a>
<a href="/page/file/upload?id=${i.id}" rel="external nofollow" >圖片上傳</a>
<a href="/file/download?id=${i.id}" rel="external nofollow" >圖片下載</a>
</td>
</tr>
</c:forEach>
</tbody>
</table>
<!-- 這一行代碼就相當(dāng)于前面分頁(yè)需求前端的幾十行了 -->
<w:page pageBean="${pageBean }"></w:page>
</body>
</html>三、多文件上傳
3.1、控制層
//多文件上傳
@RequestMapping("/uploads")
public String uploads(HttpServletRequest req, Student student, MultipartFile[] files){
try {
StringBuffer sb = new StringBuffer();
for (MultipartFile cfile : files) {
//思路:
//1) 將上傳圖片保存到服務(wù)器中的指定位置
String dir = PropertiesUtil.getValue("dir");
String server = PropertiesUtil.getValue("server");
String filename = cfile.getOriginalFilename();
FileUtils.copyInputStreamToFile(cfile.getInputStream(),new File(dir+filename));
sb.append(filename).append(",");
}
System.out.println(sb.toString());
} catch (Exception e) {
e.printStackTrace();
}
return "redirect:list";
}3.2、jsp
<a href="${pageContext.request.contextPath }/page/student/uploads" rel="external nofollow" >多文件上傳</a>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<form action="${pageContext.request.contextPath }/student/uploads" method="post" enctype="multipart/form-data">
<input type="file" name="files" multiple>
<button type="submit">上傳</button>
</form>
</body>
</html>到此這篇關(guān)于idea安裝jerbel及文件上傳下載的實(shí)現(xiàn)示例的文章就介紹到這了,更多相關(guān)idea安裝jerbel及文件上傳下載內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
修改Android應(yīng)用的樣式的一些關(guān)鍵點(diǎn)解析
這篇文章主要介紹了修改Android應(yīng)用的樣式的一些關(guān)鍵點(diǎn),即對(duì)影響外觀的theme跟style的相關(guān)修改,需要的朋友可以參考下2015-12-12
Springboot第三方j(luò)ar打不進(jìn)jar里的問題分析及解決
文章介紹了如何解決在Maven項(xiàng)目中無法從maven倉(cāng)庫(kù)找到的第三方j(luò)ar包問題,通過將這些jar包添加到本地庫(kù),使用特定的命令設(shè)置groupId、artifactId、版本號(hào)、包類型和文件路徑,此方法適用于在Windows環(huán)境下的操作,并需要安裝Maven環(huán)境變量2025-10-10
深入解析Java編程中面向字節(jié)流的一些應(yīng)用
這篇文章主要介紹了Java編程中面向字節(jié)流的一些應(yīng)用,是Java入門學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下2015-10-10
將SpringBoot項(xiàng)目的HTTP站點(diǎn)改為HTTPS的全過程
本文介紹了如何在Spring Boot項(xiàng)目中實(shí)現(xiàn)HTTPS請(qǐng)求,首先,創(chuàng)建一個(gè)Spring Boot項(xiàng)目并編寫一個(gè)BasicController.java文件,然后,配置application.yaml文件以支持HTTPS,接著,使用Java自帶的keytool工具生成一個(gè)免費(fèi)的HTTPS證書,需要的朋友可以參考下2026-02-02
Java 實(shí)戰(zhàn)交易平臺(tái)項(xiàng)目之寵物在線商城系統(tǒng)
讀萬卷書不如行萬里路,只學(xué)書上的理論是遠(yuǎn)遠(yuǎn)不夠的,只有在實(shí)戰(zhàn)中才能獲得能力的提升,本篇文章手把手帶你用Java實(shí)現(xiàn)一個(gè)寵物在線商城系統(tǒng),大家可以在過程中查缺補(bǔ)漏,提升水平2021-11-11
java中Statement 與 PreparedStatement接口之間的關(guān)系和區(qū)別
這篇文章主要介紹了java中Statement 與 PreparedStatement接口之間的關(guān)系和區(qū)別,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07
解決@Validated注解無效,嵌套對(duì)象屬性的@NotBlank無效問題
這篇文章主要介紹了解決@Validated注解無效,嵌套對(duì)象屬性的@NotBlank無效問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-10-10
Springboot JPA 枚舉Enum類型存入到數(shù)據(jù)庫(kù)的操作
這篇文章主要介紹了Springboot JPA 枚舉Enum類型存入到數(shù)據(jù)庫(kù)的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2021-01-01

