Commit 3ccf5c0e502d26f3e6418a123f7e3be676dd9cc7
1 parent
db5fea92
新增内容编码/解码方便插件集成使用
Showing
2 changed files
with
40 additions
and
1 deletions
ruoyi-common/src/main/java/com/ruoyi/common/utils/ServletUtils.java
1 | 1 | package com.ruoyi.common.utils; |
2 | 2 | |
3 | 3 | import java.io.IOException; |
4 | +import java.io.UnsupportedEncodingException; | |
5 | +import java.net.URLDecoder; | |
6 | +import java.net.URLEncoder; | |
4 | 7 | import javax.servlet.http.HttpServletRequest; |
5 | 8 | import javax.servlet.http.HttpServletResponse; |
6 | 9 | import javax.servlet.http.HttpSession; |
7 | 10 | import org.springframework.web.context.request.RequestAttributes; |
8 | 11 | import org.springframework.web.context.request.RequestContextHolder; |
9 | 12 | import org.springframework.web.context.request.ServletRequestAttributes; |
13 | +import com.ruoyi.common.constant.Constants; | |
10 | 14 | import com.ruoyi.common.core.text.Convert; |
11 | 15 | |
12 | 16 | /** |
... | ... | @@ -143,4 +147,40 @@ public class ServletUtils |
143 | 147 | String ajax = request.getParameter("__ajax"); |
144 | 148 | return StringUtils.inStringIgnoreCase(ajax, "json", "xml"); |
145 | 149 | } |
150 | + | |
151 | + /** | |
152 | + * 内容编码 | |
153 | + * | |
154 | + * @param str 内容 | |
155 | + * @return 编码后的内容 | |
156 | + */ | |
157 | + public static String urlEncode(String str) | |
158 | + { | |
159 | + try | |
160 | + { | |
161 | + return URLEncoder.encode(str, Constants.UTF8); | |
162 | + } | |
163 | + catch (UnsupportedEncodingException e) | |
164 | + { | |
165 | + return StringUtils.EMPTY; | |
166 | + } | |
167 | + } | |
168 | + | |
169 | + /** | |
170 | + * 内容解码 | |
171 | + * | |
172 | + * @param str 内容 | |
173 | + * @return 解码后的内容 | |
174 | + */ | |
175 | + public static String urlDecode(String str) | |
176 | + { | |
177 | + try | |
178 | + { | |
179 | + return URLDecoder.decode(str, Constants.UTF8); | |
180 | + } | |
181 | + catch (UnsupportedEncodingException e) | |
182 | + { | |
183 | + return StringUtils.EMPTY; | |
184 | + } | |
185 | + } | |
146 | 186 | } |
... | ... |