| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- package com.fdkankan.ucenter.common;
- import com.fdkankan.common.util.DateEditor;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.propertyeditors.StringTrimmerEditor;
- import org.springframework.data.domain.PageRequest;
- import org.springframework.data.domain.Sort;
- import org.springframework.data.domain.Sort.Direction;
- import org.springframework.util.StringUtils;
- import org.springframework.web.bind.WebDataBinder;
- import org.springframework.web.bind.annotation.InitBinder;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.io.*;
- import java.util.Date;
- public class BaseController {
- @Autowired
- protected HttpServletRequest request;
- @Autowired
- protected HttpServletResponse response;
- @InitBinder
- protected void initBinder(WebDataBinder webDataBinder) {
- webDataBinder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
- webDataBinder.registerCustomEditor(Date.class, new DateEditor(true));
- }
- /**
- * 带参重定向
- *
- * @param path
- * @return
- */
- protected String redirect(String path) {
- return "redirect:" + path;
- }
- /**
- * 不带参重定向
- *
- * @param response
- * @param path
- * @return
- */
- protected String redirect(HttpServletResponse response, String path) {
- try {
- response.sendRedirect(path);
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
- }
- public static void output(HttpServletResponse resp, File file) {
- OutputStream os = null;
- BufferedInputStream bis = null;
- byte[] buff = new byte[1024];
- try {
- os = resp.getOutputStream();
- bis = new BufferedInputStream(new FileInputStream(file));
- int i = 0;
- while ((i = bis.read(buff)) != -1) {
- os.write(buff, 0, i);
- os.flush();
- }
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- try {
- bis.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- protected String getToken(){
- return request.getHeader("token");
- }
- }
|