package com.ic.core.impl;


import com.ic.core.enums.LogLevel;
import com.ic.core.mapper.JsonMapper;
import com.ic.core.model.DataResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.ContextLoader;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * Description:所有Controller的基类
 * 约定：
 *      1.除方法特殊说明外，其他的所有的参数以json字符串的形式，以inJson参数输入
 * Author: Charles
 * Date  : 2014/12/16
 */
public abstract class CoreController implements Serializable {

    /**
     * 日志对象
     */
    protected Logger log = LoggerFactory.getLogger(getClass());


    public void debug(String string){
        if(log.isDebugEnabled()){
            log.debug(string);
        }
    }

    public void info(String string) {
        if (log.isInfoEnabled()) {
            log.info(string);
        }
    }

    public void error(String string) {
        if (log.isErrorEnabled()) {
            log.error(string);
        }
    }

    /**
     * 客户端返回JSON字符串
     *
     * @param response
     * @param object
     * @return
     */
    protected String renderString(HttpServletResponse response, Object object) {
        return renderString(response, JsonMapper.toJsonString(object), "application/json");
    }


    protected String renderData(HttpServletResponse response,String code,String msg, Map<String,Object> data) {
        DataResponse dr=new DataResponse(code,msg,data);
        dr.setTranstime(null);
        return renderString(response, JsonMapper.toJsonString(dr), "application/json");
    }

    /**
     * 客户端返回字符串
     *
     * @param response
     * @param string
     * @return
     */
    protected String renderString(HttpServletResponse response, String string, String type) {
        try {
            response.reset();
            response.setContentType(type);
            response.setCharacterEncoding("utf-8");
            response.getWriter().print(string);
            return null;
        } catch (IOException e) {
            return null;
        }
    }

}

@@ -129,24 +129,59 @@
 taResponse;%0A
+import com.ic.core.utils.JSONUtil;%0A
 import org.a
@@ -302,32 +302,95 @@
 .LoggerFactory;%0A
+import org.springframework.web.bind.annotation.ModelAttribute;%0A
 import org.sprin
@@ -922,16 +922,605 @@
 ss());%0A%0A
+    protected HttpServletRequest request;%0A    protected HttpServletResponse response;%0A    protected Map%3CString,Object%3E param_map;%0A%0A    /**%0A     * %E6%89%A7%E8%A1%8C%E4%BB%BB%E6%84%8Fcontrollor%E9%A6%96%E5%85%88%E6%89%A7%E8%A1%8C%E6%AD%A4%E6%96%B9%E6%B3%95%EF%BC%8C%E7%94%A8%E6%9D%A5%E7%BB%9F%E4%B8%80%E5%A4%84%E7%90%86%E5%89%8D%E5%8F%B0%E8%AF%B7%E6%B1%82%E5%8F%82%E6%95%B0%0A     * @param request%0A     * @param response%0A     */%0A    @ModelAttribute%0A    protected void preparedParam(HttpServletRequest request, HttpServletResponse response)%0A    %7B%0A        this.request = request;%0A        this.response = response;%0A        String inJson = request.getParameter(%22inJson%22);%0A        param_map = JSONUtil.parseJSONString2Map(inJson);%0A        System.out.println(%22%E9%A6%96%E5%85%88%E6%89%A7%E8%A1%8C%E6%AD%A4%E6%96%B9%E6%B3%95%EF%BC%8C%E7%94%A8%E6%9D%A5%E7%BB%9F%E4%B8%80%E5%A4%84%E7%90%86%E5%89%8D%E5%8F%B0%E8%AF%B7%E6%B1%82%E5%8F%82%E6%95%B0%22);%0A    %7D%0A
 %0A    pub
@@ -1910,39 +1910,16 @@
 %0A     *%0A
-     * @param response%0A
      * @
@@ -1992,38 +1992,8 @@
 ing(
-HttpServletResponse response, 
 Obje
@@ -2029,34 +2029,24 @@
 enderString(
-response, 
 JsonMapper.t
@@ -2131,37 +2131,8 @@
 ata(
-HttpServletResponse response,
 Stri
@@ -2294,26 +2294,16 @@
 rString(
-response, 
 JsonMapp
@@ -2382,39 +2382,16 @@
 %0A     *%0A
-     * @param response%0A
      * @
@@ -2464,38 +2464,8 @@
 ing(
-HttpServletResponse response, 
 Stri

添加统一处理前台请求的方法，获取每次求请的request和response对象