mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-03 04:13:49 +08:00
add method
This commit is contained in:
parent
d57de90f66
commit
7525a9a2d1
@ -18,6 +18,8 @@
|
||||
* 【core 】 增加RadixUtil(pr#260@Gitee)
|
||||
* 【core 】 BeanUtil.getFieldValue支持获取字段集合(pr#254@Gitee)
|
||||
* 【core 】 DateConvert转换失败默认抛出异常(issue#I2M5GN@Gitee)
|
||||
* 【http 】 HttpServerRequest增加getParam方法
|
||||
* 【http 】 RootAction增加可选name参数,返回指定文件名称
|
||||
|
||||
### Bug修复
|
||||
* 【core 】 修复FileUtil.move以及PathUtil.copy等无法自动创建父目录的问题(issue#I2CKTI@Gitee)
|
||||
|
@ -26,6 +26,7 @@ import java.net.URI;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -296,6 +297,32 @@ public class HttpServerRequest extends HttpServerBase {
|
||||
return this.httpExchange.getRequestBody();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定名称的参数值,取第一个值
|
||||
* @param name 参数名
|
||||
* @return 参数值
|
||||
* @since 5.5.8
|
||||
*/
|
||||
public String getParam(String name){
|
||||
return getParams().get(name, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定名称的参数值
|
||||
*
|
||||
* @param name 参数名
|
||||
* @return 参数值
|
||||
* @since 5.5.8
|
||||
*/
|
||||
public List<String> getParams(String name){
|
||||
return getParams().get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取参数Map
|
||||
*
|
||||
* @return 参数map
|
||||
*/
|
||||
public ListValueMap<String, String> getParams() {
|
||||
if (null == this.paramsCache) {
|
||||
this.paramsCache = new ListValueMap<>();
|
||||
|
@ -371,11 +371,25 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @since 5.2.6
|
||||
*/
|
||||
public HttpServerResponse write(File file) {
|
||||
return write(file, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回文件给客户端(文件下载)
|
||||
*
|
||||
* @param file 写出的文件对象
|
||||
* @return this
|
||||
* @since 5.5.8
|
||||
*/
|
||||
public HttpServerResponse write(File file, String fileName) {
|
||||
final long fileSize = file.length();
|
||||
if(fileSize > Integer.MAX_VALUE){
|
||||
throw new IllegalArgumentException("File size is too bigger than " + Integer.MAX_VALUE);
|
||||
}
|
||||
final String fileName = file.getName();
|
||||
|
||||
if(StrUtil.isBlank(fileName)){
|
||||
fileName = file.getName();
|
||||
}
|
||||
final String contentType = ObjectUtil.defaultIfNull(HttpUtil.getMimeType(fileName), "application/octet-stream");
|
||||
BufferedInputStream in = null;
|
||||
try {
|
||||
|
@ -64,6 +64,7 @@ public class RootAction implements Action {
|
||||
@Override
|
||||
public void doAction(HttpServerRequest request, HttpServerResponse response) {
|
||||
final String path = request.getPath();
|
||||
|
||||
File file = FileUtil.file(rootDir, path);
|
||||
if (file.exists()) {
|
||||
if (file.isDirectory()) {
|
||||
@ -75,7 +76,8 @@ public class RootAction implements Action {
|
||||
}
|
||||
}
|
||||
} else{
|
||||
response.write(file);
|
||||
final String name = request.getParam("name");
|
||||
response.write(file, name);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user