| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- package com.mes.controller.barcode;
- import java.io.UnsupportedEncodingException;
- import java.net.URLEncoder;
- import org.springframework.http.HttpHeaders;
- import org.springframework.http.HttpStatus;
- import org.springframework.http.MediaType;
- import org.springframework.http.ResponseEntity;
- import org.springframework.ui.ModelMap;
- public class BaseController
- {
- protected static final String defultCharset = "UTF-8";
- private static final String SUCCESS = "success";
- private static final String ERROR = "error";
- private static final String ERROR_CODE = "errCode";
- private static final String CONTENT = "content";
- private static final String ERROR_MESSAGE = "exceptionInfo";
- protected String decodeUnicodeString(String param)
- {
- try
- {
- return new String(param.getBytes("utf-8"), "UTF-8"); } catch (UnsupportedEncodingException e) {
- }
- return param;
- }
- protected ModelMap success()
- {
- return new ModelMap("success", Boolean.valueOf(true));
- }
- protected ModelMap success(Object content) {
- return success().addAttribute("content", content);
- }
- protected ModelMap error() {
- return new ModelMap("error", Boolean.valueOf(true));
- }
- protected ModelMap error(String errMsg) {
- return error().addAttribute("exceptionInfo", errMsg);
- }
- protected ModelMap error(int errCode, String errMsg) {
- return error(errMsg).addAttribute("errCode", Integer.valueOf(errCode));
- }
- protected ResponseEntity<byte[]> outputStream(String fileName, byte[] bytes)
- {
- HttpHeaders headers = new HttpHeaders();
- headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
- try {
- headers.setContentDispositionFormData("attachment", URLEncoder.encode(fileName, "UTF-8"));
- } catch (UnsupportedEncodingException localUnsupportedEncodingException) {
- }
- return new ResponseEntity(bytes, headers, HttpStatus.CREATED);
- }
- }
|