package com.lxyz.controller;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Created by 18761 on 2017/12/22.
*/
public class BaseController {
/**
* @param binder
*/
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
/**
* @param binder
*/
@InitBinder("pagination")
public void paginationBinder(WebDataBinder binder) {
binder.setFieldDefaultPrefix("pagination.");
}
/**
* 输出流. 缓冲区大小为1024.
*
* @param response
* @param input 输入流.本方法会自动关闭流对象,不需要独立关闭.
* @throws java.io.IOException 流出错.
* @see #outputStream(javax.servlet.http.HttpServletResponse,
* java.io.InputStream, int)
*/
protected void outputStream(HttpServletResponse response, InputStream input) throws IOException {
outputStream(response, input, 1024);
}
/**
* 输出流
*
* @param response
* @param input 输入流.本方法会自动关闭流对象,不需要独立关闭.
* @param bufferSize 缓冲区大小.
* @throws java.io.IOException 流出错.
*/
protected void outputStream(HttpServletResponse response, InputStream input, int bufferSize) throws IOException {
OutputStream out = null;
try {
out = response.getOutputStream();
byte[] bs = new byte[1024];
int s;
while ((s = input.read(bs)) >= 0) {
out.write(bs, 0, s);
}
out.flush();
} catch (IOException ex) {
ex.printStackTrace();
} finally {
try {
if (input != null) {
input.close();
}
if (out != null) {
out.close();
}
} catch (IOException ex) {
throw ex;
}
}
}
/**
* 绘制临时文件
* @param network_resource_file_path
* @param tempFile
*/
public void drawingFile(String network_resource_file_path,File tempFile){
InputStream inStream = null;
FileOutputStream fos = null;
try{
URL url = new URL(network_resource_file_path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5 * 1000);
inStream = new BufferedInputStream(conn.getInputStream());
fos = new FileOutputStream(tempFile);
byte[] data = castInputStreamToByteArray(inStream);
fos.write(data);
}catch(Exception ex){
ex.printStackTrace();
} finally {
try {
if (fos != null) {
fos.close();
}
if (inStream != null) {
inStream.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* @param inStream
* @return
* @throws Exception
*/
public byte[] castInputStreamToByteArray(InputStream inStream) throws Exception {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = inStream.read(buffer)) != -1) {
outStream.write(buffer, 0, len);
}
inStream.close();
return outStream.toByteArray();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
手机网页版angularjs上拉加载下拉刷新,左滑右滑 (120个子文件)
BaseController.class 4KB
BaseController.class 4KB
FactoryController.class 4KB
FactoryController.class 4KB
Pagination.class 4KB
Pagination.class 4KB
FactoryServiceImpl.class 2KB
FactoryServiceImpl.class 2KB
FileUtils.class 2KB
FileUtils.class 2KB
Question.class 2KB
Question.class 2KB
People.class 961B
People.class 961B
IFactoryService.class 396B
IFactoryService.class 396B
bootstrap.css 123KB
bootstrap.css 123KB
swiper.min.css 19KB
swiper.min.css 19KB
styles.css 2KB
styles.css 2KB
angular-pull-to-refresh.min.css 763B
angular-pull-to-refresh.min.css 763B
angular-pull-to-refresh.tpl.html 142B
angular-pull-to-refresh.tpl.html 142B
anguarJsAndAjax.iml 4KB
aspectjweaver-1.8.10.jar 1.84MB
jackson-databind-2.8.9.jar 1.18MB
spring-context-4.3.9.RELEASE.jar 1.09MB
spring-core-4.3.9.RELEASE.jar 1.07MB
spring-webmvc-4.3.9.RELEASE.jar 894KB
spring-web-4.3.9.RELEASE.jar 801KB
spring-beans-4.3.9.RELEASE.jar 745KB
hibernate-validator-5.4.1.Final.jar 744KB
httpclient-4.5.3.jar 730KB
fastjson-1.2.44.jar 526KB
spring-jdbc-4.3.9.RELEASE.jar 418KB
jstl-1.2.jar 405KB
spring-aop-4.3.9.RELEASE.jar 372KB
httpcore-4.4.6.jar 316KB
jackson-core-2.8.9.jar 276KB
spring-tx-4.3.9.RELEASE.jar 261KB
commons-codec-1.9.jar 258KB
spring-expression-4.3.9.RELEASE.jar 257KB
commons-io-2.2.jar 170KB
aspectjrt-1.8.10.jar 116KB
commons-fileupload-1.3.3.jar 69KB
jboss-logging-3.3.0.Final.jar 65KB
classmate-1.3.1.jar 63KB
validation-api-1.1.0.Final.jar 62KB
commons-logging-1.2.jar 60KB
jackson-annotations-2.8.0.jar 54KB
BaseController.java 4KB
FactoryController.java 3KB
Pagination.java 2KB
FactoryServiceImpl.java 2KB
FileUtils.java 1KB
Question.java 1KB
People.java 601B
IFactoryService.java 282B
img00.jpg 346KB
img00.jpg 346KB
img03.jpg 335KB
img03.jpg 335KB
img04.jpg 324KB
img04.jpg 324KB
img01.jpg 324KB
img01.jpg 324KB
img02.jpg 321KB
img02.jpg 321KB
angular.min.js 156KB
angular.min.js 156KB
swiper.min.js 109KB
swiper.min.js 109KB
TweenMax.min.js 90KB
TweenMax.min.js 90KB
jquery.min.js 82KB
jquery.min.js 82KB
angular-touch.js 26KB
angular-touch.js 26KB
angular-animate.min.js 25KB
angular-animate.min.js 25KB
angular-touch.min.js 4KB
angular-touch.min.js 4KB
angular-pull-to-refresh.js 4KB
angular-pull-to-refresh.js 4KB
angular-pull-to-refresh.min.js 2KB
angular-pull-to-refresh.min.js 2KB
ng-infinite-scroll.min.js 860B
ng-infinite-scroll.min.js 860B
angular-pull-to-refresh.tpl.js 354B
angular-pull-to-refresh.tpl.js 354B
test.json 2KB
test.json 2KB
test.json 2KB
test4.jsp 5KB
test4.jsp 5KB
test.jsp 4KB
test.jsp 4KB
共 120 条
- 1
- 2
资源评论
scaling_heights
- 粉丝: 264
- 资源: 49
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功