Browse Source

网络参数相关API

pull/11/head
richie 5 years ago
parent
commit
e010aae0a1
  1. 119
      src/main/java/com/fanruan/api/net/NetworkKit.java
  2. 51
      src/test/java/com/fanruan/api/net/NetworkKitTest.java

119
src/main/java/com/fanruan/api/net/NetworkKit.java

@ -0,0 +1,119 @@
package com.fanruan.api.net;
import com.fr.data.NetworkHelper;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-08-15
* 网络请求参数相关的工具类
*/
public class NetworkKit {
/**
* 生成一个打印输出器
*
* @param res HTTP响应
* @return 打印输出器
* @throws java.io.IOException 如果无法创建输出器则抛出此异常
*/
public static PrintWriter createPrintWriter(HttpServletResponse res) throws IOException {
return NetworkHelper.createPrintWriter(res);
}
/**
* 生成一个打印输出器
*
* @param res HTTP响应
* @param charsetName 编码
* @return 打印输出器
* @throws java.io.IOException 如果无法创建输出器则抛出此异常
*/
public static PrintWriter createPrintWriter(HttpServletResponse res, String charsetName) throws IOException {
return NetworkHelper.createPrintWriter(res, charsetName);
}
/**
* 写出指定的模板
*
* @param resource 模板路径
* @param response HTTP响应
* @param map 用于替换模板中参数的的参数集
* @throws java.io.IOException 如果无法创建输出器则抛出此异常
*/
public static void writeOutTemplate(String resource, HttpServletResponse response, Map<String, Object> map) throws IOException {
NetworkHelper.writeOutTemplate(resource, response, map);
}
/**
* 把HTTP请求中指定名字的参数值转化为整数参数为空或不是整数则返回-1
*
* @param req HTTP请求
* @param paraName 参数名
* @return 整型参数值
*/
public static int getHTTPRequestIntParameter(HttpServletRequest req, String paraName) {
return NetworkHelper.getHTTPRequestIntParameter(req, paraName);
}
/**
* 把HTTP请求中指定名字的参数值转化为整数
*
* @param req HTTP请求
* @param paraName 参数名
* @param defaultValue 默认值
* @return 返回req中参数的整数值参数为空或不是整数则返回defaultValue
*/
public static int getHTTPRequestIntParameter(HttpServletRequest req, String paraName, int defaultValue) {
return NetworkHelper.getHTTPRequestIntParameter(req, paraName, defaultValue);
}
/**
* 从http请求中获取sessionID
*
* @param req HTTP请求
* @return session编号
*/
public static String getHTTPRequestSessionIDParameter(HttpServletRequest req) {
return NetworkHelper.getHTTPRequestSessionIDParameter(req);
}
/**
* 把HTTP请求中指定名字的参数值转化为布尔值
*
* @param req HTTP请求
* @param paraName 参数名
* @return 布尔类型的参数值
*/
public static boolean getHTTPRequestBoolParameter(HttpServletRequest req, String paraName) {
return NetworkHelper.getHTTPRequestBoolParameter(req, paraName);
}
/**
* 获取HTTP请求中指定名字的参数值
*
* @param req HTTP请求
* @param paraName 参数名
* @return 字符型参数值
*/
public static String getHTTPRequestParameter(HttpServletRequest req, String paraName) {
return NetworkHelper.getHTTPRequestParameter(req, paraName);
}
/**
* 获取第一个不为空的参数
*
* @param req HTTP请求
* @param paraNames 参数列表
* @return 字符型参数值
*/
public static String getHTTPRequestParameter(HttpServletRequest req, String... paraNames) {
return NetworkHelper.getHTTPRequestParameter(req, paraNames);
}
}

51
src/test/java/com/fanruan/api/net/NetworkKitTest.java

@ -0,0 +1,51 @@
package com.fanruan.api.net;
import com.fanruan.api.Prepare;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-08-15
* 待补充
*/
public class NetworkKitTest extends Prepare {
@Test
public void createPrintWriter() {
}
@Test
public void testCreatePrintWriter() {
}
@Test
public void writeOutTemplate() {
}
@Test
public void getHTTPRequestIntParameter() {
}
@Test
public void testGetHTTPRequestIntParameter() {
}
@Test
public void getHTTPRequestSessionIDParameter() {
}
@Test
public void getHTTPRequestBoolParameter() {
}
@Test
public void getHTTPRequestParameter() {
}
@Test
public void testGetHTTPRequestParameter() {
}
}
Loading…
Cancel
Save