Java 类org.codehaus.jackson.map.util.JSONPObject 实例源码

项目:iwantplay    文件:PhoneGapWorkerController.java   
@RequestMapping(value="/singleactivitymsg.json", method=RequestMethod.GET)
@ResponseBody
public JSONPObject singleactivitymsg(HttpServletRequest request,
        HttpServletResponse response,String aid,@RequestParam String callback) throws Exception {
    //获取消息的变化值
    List<MsgDto> msgs = getMySaeMemcache().get(Constants.ACTIVITY_KEY + aid);
    JSONArray jsonArray = new JSONArray();
    if(msgs !=null) {
        for (int i=0;i<msgs.size();i++) {
            MsgDto msgDto = msgs.get(i);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("id", msgDto.getId());
            jsonObject.put("type", msgDto.getType());
            jsonObject.put("time", msgDto.getTime());
            jsonObject.put("username", msgDto.getUsername());
            jsonObject.put("content", msgDto.getContent());
            jsonArray.add(jsonObject);
        }
    }
    return new JSONPObject(callback, jsonArray);
}
项目:iwantplay    文件:PhoneGapLoginController.java   
@RequestMapping(value="/reg.json", method=RequestMethod.GET)
@ResponseBody
public JSONPObject reg(HttpServletRequest request,HttpServletResponse response,
        String username,String password,@RequestParam String callback) throws Exception {
    ModelAndView model = new ModelAndView();
    Admin hasAdmin = service.getAdmin(username);
    if(hasAdmin != null) {
        model.addObject("status", "1");
        return new JSONPObject(callback, model);
    }
    Admin admin = new Admin();
    admin.setName(username);
    admin.setPassword(password);
    int result = service.saveAdmin(admin);
    //注册成功后进行登录操作
    if(result > 0) {
        doLogin(username, password);
        model.addObject("status", "0");
    } else {
        model.addObject("status", "1");
    }
       return new JSONPObject(callback, model);
}
项目:iwantplay    文件:PhoneGapLoginController.java   
@RequestMapping(value="/login.json", method=RequestMethod.GET)
@ResponseBody
public JSONPObject login(HttpServletRequest request,HttpServletResponse response,
        String username,String password,@RequestParam String callback) throws Exception {
    ModelAndView model = new ModelAndView();
    Admin admin = service.getAdmin(username);
    if(admin == null) {
        model.addObject("status", "3");
    } else if(!password.equals(admin.getPassword())) {
        model.addObject("status", "2");
    } else if(!admin.isEffective()) {
        model.addObject("status", "1");
    } else {
        doLogin(username, password);
        // 登陆成功
        model.addObject("status", "0");
    }
       return new JSONPObject(callback, model);
}
项目:iwantplay    文件:PhoneGapSingleActivityMsgController.java   
@RequestMapping(value="/singleactivitymsg.json", method=RequestMethod.GET)
@ResponseBody
public JSONPObject index(HttpServletRequest request,String aid,String username,
        String passwordMD5,@RequestParam String callback) throws Exception {
    ModelAndView model = new ModelAndView();
    String islogin = isLogin(username,passwordMD5);
    if(!"1".equals(islogin)) {
        model.addObject("status","-1");
        return new JSONPObject(callback, model);
    }
    Activity activity = service.getActivityById(aid);
    if(activity == null || activity.getEndtime().compareTo(new Date()) <= 0) {
        return new JSONPObject(callback,model);
    }
    model.addObject("activity", activity);
    model.addObject("currentusername", username);
    HashMap<String, Object> paramMap = new HashMap<String, Object>();
    paramMap.put("aid", aid);
    paramMap.put("username", username);
    if(service.isUserInThisActivityGroup(paramMap)<=0 && !activity.getLeader().equals(username)) {
        return new JSONPObject(callback,model);
    }
    model.addObject("atime", JSTLFunction.getATimeByNow(activity.getEndtime()));
    return new JSONPObject(callback,model);
}
项目:iwantplay    文件:PhoneGapActivityController.java   
@RequestMapping(value="/getArroundActivities.json", method=RequestMethod.GET)
@ResponseBody
public JSONPObject getArroundActivities(HttpServletRequest request,HttpServletResponse response,
        String lng,String lat, int pageNo,@RequestParam String callback) throws Exception {
    ModelAndView model = new ModelAndView();
    String username = ""; //登陆用户
    String key;
    List<Activity> activities= service.getActivities(username,lng, lat,pageNo);
    for(Activity activity : activities) {
        activity.setAtimeForShow(JSTLFunction.getATimeByNow(activity.getEndtime()));
        key = Constants.ACTIVITY_GROUP_NUM + activity.getId();
        int currentNum = 1;
        if(getMySaeMemcache().get(key) != null) {
            currentNum = getMySaeMemcache().get(key);
        }
        activity.setAtimeForShow(JSTLFunction.getATimeByNow(activity.getEndtime()));
        activity.setGroupnum(currentNum);
    }
       model.addObject("activities", activities);
       return new JSONPObject(callback, model);
}
项目:iwantplay    文件:PhoneGapActivityController.java   
@RequestMapping(value="/mySponseActivity.json", method=RequestMethod.GET)
@ResponseBody
public JSONPObject mySponseActivity(HttpServletRequest request,HttpServletResponse response,
        String username,@RequestParam String callback) throws Exception {
    //查询自己发起的活动
    ModelAndView model = new ModelAndView();
    List<Activity> sponseActivities = service.getSponseActivities(username);
    String key;
    for(Activity activity : sponseActivities) {
        activity.setAtimeForShow(JSTLFunction.getATimeByNow(activity.getEndtime()));
        key = Constants.ACTIVITY_GROUP_NUM + activity.getId();
        int currentNum = 1;
        if(getMySaeMemcache().get(key) != null) {
            currentNum = getMySaeMemcache().get(key);
        }
        activity.setAtimeForShow(JSTLFunction.getATimeByNow(activity.getEndtime()));
        activity.setGroupnum(currentNum);
    }
    model.addObject("activities", sponseActivities);
       return new JSONPObject(callback, model);
}
项目:iwantplay    文件:PhoneGapActivityController.java   
@RequestMapping(value="/myPartinActivity.json", method=RequestMethod.GET)
@ResponseBody
public JSONPObject myPartinActivity(HttpServletRequest request,HttpServletResponse response,
        String username,@RequestParam String callback) throws Exception {
    //参与的活动
    ModelAndView model = new ModelAndView();
    List<Activity> partinActivities = service.getPartinActivities(username);
    String key;
    for(Activity activity : partinActivities) {
        activity.setAtimeForShow(JSTLFunction.getATimeByNow(activity.getEndtime()));
        key = Constants.ACTIVITY_GROUP_NUM + activity.getId();
        int currentNum = 1;
        if(getMySaeMemcache().get(key) != null) {
            currentNum = getMySaeMemcache().get(key);
        }
        activity.setAtimeForShow(JSTLFunction.getATimeByNow(activity.getEndtime()));
        activity.setGroupnum(currentNum);
    }
    model.addObject("activities", partinActivities);
       return new JSONPObject(callback, model);
}
项目:iwantplay    文件:PhoneGapActivityController.java   
@RequestMapping(value="/sponseInit.json", method=RequestMethod.GET)
@ResponseBody
public JSONPObject sponseInit(HttpServletRequest request,HttpServletResponse response,
        @RequestParam String callback) throws Exception {
    //参与的活动
    ModelAndView model = new ModelAndView();
    Map<String,String> yundongMap = ATypeDef.YUNDONGMAP;
    Map<String,String> xiuxianMap = ATypeDef.XIUXIANMAP;
    model.addObject("yundongMap", yundongMap);
    model.addObject("xiuxianMap", xiuxianMap);
    //获取当前时间
    SimpleDateFormat df = new SimpleDateFormat("HH");//设置日期格式
    String currentH = df.format(new Date());// new Date()为获取当前系统时间
    model.addObject("currentH", currentH);
       return new JSONPObject(callback, model);
}
项目:sword-ocean    文件:BaseController.java   
/**
 * 返回json对象,如果callback存在则支持jsonp,如果不存在则返回json
 * @param success
 * @param msg
 * @return
 */
public Object render(boolean success,String msg){
    JSONObject obj = new JSONObject();
    if(success)
        obj = renderSuccess(msg);
    else {
        obj = renderFailed(msg);
    }
    if(StringUtils.isNotBlank(callback)){
        JSONPObject jsonp = new JSONPObject(callback,obj);
        return jsonp;
    }
    return obj;
}
项目:iwantplay    文件:PhoneGapSingleActivityController.java   
@RequestMapping(value="/singleactivityinit.json", method=RequestMethod.GET)
@ResponseBody
public JSONPObject index(HttpServletRequest request,String aid,String ret,String username,
        String passwordMD5,@RequestParam String callback) throws Exception {
    ModelAndView model = new ModelAndView();
    String islogin = isLogin(username,passwordMD5);
    if(!"1".equals(islogin)) {
        model.addObject("status","-1");
        return new JSONPObject(callback, model);
    }
    model.addObject("ret",ret);
    Activity activity = service.getActivityById(aid);
    if(activity == null || activity.getEndtime().compareTo(new Date()) <= 0 || "".equals(username)) {
        return new JSONPObject(callback,model);
    }
    model.addObject("activity", activity);
    model.addObject("atime", JSTLFunction.getATimeByNow(activity.getEndtime()));
    //查询该活动现在的所有成员情况
    List<ActivityGroup> group = service.getActivityGroup(activity.getId());
    model.addObject("group", group);
    if(group != null) {
        for(ActivityGroup ag : group) {
            if(ag.getUname().equals(username)) {
                model.addObject("hasBecomeGroup", "1");
                break;
            }
        }
    }
    if(activity.getLeader().equals(username)) {
        model.addObject("hasBecomeGroup", "1");
    }
    return new JSONPObject(callback,model);
}
项目:iwantplay    文件:PhoneGapLoginController.java   
@RequestMapping(value="/logout.json", method=RequestMethod.GET)
@ResponseBody
public JSONPObject logout(HttpServletRequest request,HttpServletResponse response,
        String username,String passwordMD5,@RequestParam String callback) throws Exception {
    ModelAndView model = new ModelAndView();
    doLogout(username,passwordMD5);
    //退出成功
    model.addObject("status", "0");
       return new JSONPObject(callback, model);
}
项目:iwantplay    文件:PhoneGapActivityController.java   
@RequestMapping(value="/submitActivity.json", method=RequestMethod.GET)
@ResponseBody
public JSONPObject submitActivity(HttpServletRequest request,HttpServletResponse response,
        Activity activity,String username,String passwordMD5,@RequestParam String callback) throws Exception {
    ModelAndView model = new ModelAndView();
    String islogin = isLogin(username,passwordMD5);
    if(!"1".equals(islogin)) {
        model.addObject("status","-1");
        return new JSONPObject(callback, model);
    }
    if(StringUtils.isEmpty(username)) {
        model.addObject("status", "-1");
        return new JSONPObject(callback, model);
    }
    activity.setLeader(username);
    //设置活动
    if(!"2".equals(activity.getAtype().substring(0, 1))) {
        activity.setActivityname(ATypeDef.getNameByAtype1(activity.getAtype().substring(1)));
    }
    Date now = new Date();
    activity.setEndtime(DateUtils.getEndDate(now, activity.getAtime()));
    if(StringUtils.isEmpty(activity.getAddrlng()) || StringUtils.isEmpty(activity.getAddrlat())) {
        activity.setAddrlng(activity.getLng());
        activity.setAddrlat(activity.getLat());
    }
    int result = service.saveActivity(activity);
    if(result > 0) {
        model.addObject("status", "0");
        model.addObject("aid", activity.getId());
        //将活动人数写入缓存
        long expireSeconds = (activity.getEndtime().getTime() - System.currentTimeMillis())/1000;
        getMySaeMemcache().set(Constants.ACTIVITY_GROUP_NUM + activity.getId(), 1, expireSeconds);
    } else {
        model.addObject("status", "1");
    }
    return new JSONPObject(callback, model);
}
项目:iwantplay    文件:PhoneGapSingleActivityController.java   
@RequestMapping(value="/partin.json", method=RequestMethod.GET)
@ResponseBody
public JSONPObject partin(HttpServletRequest request,HttpServletResponse response,
        String username,String passwordMD5,String aid,String ulng,String ulat,@RequestParam String callback) throws Exception {
    ModelAndView model = new ModelAndView();
    String islogin = isLogin(username,passwordMD5);
    if(!"1".equals(islogin)) {
        model.addObject("status","-1");
        return new JSONPObject(callback, model);
    }
    HashMap<String, Object> paramMap = new HashMap<String, Object>();
    paramMap.put("aid", aid);
    paramMap.put("username", username);
    if(service.isUserInThisActivityGroup(paramMap) > 0) {
        model.addObject("status","-2");
        return new JSONPObject(callback, model);
    }
    ActivityGroup ag = new ActivityGroup();
    ag.setAid(Integer.parseInt(aid));
    ag.setUlat(ulat);
    ag.setUlng(ulng);
    ag.setUname(username);
    int result = service.saveActivityGroup(ag);
    if(result > 0) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Map<String,String> groups = getMySaeMemcache().get(Constants.ACTIVITY_GROUP+aid);
        if(groups == null) {
            groups = new HashMap<String,String>();
        }
        groups.put(username, ag.getUlng()
                + "#" + ag.getUlat() + "#" + sdf.format(new Date()));
        getMySaeMemcache().set(Constants.ACTIVITY_GROUP+aid, groups,5000);
        //将活动人数写入缓存
        long expireSeconds = (service.getActivityById(aid).getEndtime().getTime() - System.currentTimeMillis())/1000;
        int currentNum = getMySaeMemcache().get(Constants.ACTIVITY_GROUP_NUM + aid);
        getMySaeMemcache().set(Constants.ACTIVITY_GROUP_NUM + aid, 
                (currentNum + 1), expireSeconds);
        model.addObject("status", "0");
    } else {
        model.addObject("status", "1");
    }
       return new JSONPObject(callback,model);
}
项目:xxl-incubator    文件:UtilDemoController.java   
/**
 * <pre>
 26、Jsonp接口开发
     功能简介:Jsonp接口开发
     方式1: JSONP (Jackson之JSONPObject方式)
            @RequestMapping(value = "/jsonp" )
            @ResponseBody
            public JSONPObject jsonp(String callback) {
                Map<String, Object> paramJsonObj = new HashMap<String, Object>();
                paramJsonObj.put("code", 200);
                paramJsonObj.put("msg", "终于成功了");
                // 封装JSONP
                return new JSONPObject(callback, paramJsonObj);
            }
    方式2: JSONP (SpringMVC4之MappingJacksonValue方式)
            @RequestMapping("/jsonp")
            @ResponseBody
            public MappingJacksonValue jsonp(String callback) {
                Map<String, Object> temp = new HashMap<String, Object>();
                temp.put("code", 200);
                temp.put("msg", "终于成功了");
                // 封装JSONP
                MappingJacksonValue mappingJacksonValue = new MappingJacksonValue(temp);
                mappingJacksonValue.setJsonpFunction(callback);
                return mappingJacksonValue;
            }
 </pre>
 */
@RequestMapping(value = "/jsonp" )
@ResponseBody
public JSONPObject jsonp(String callback) {
    Map<String, Object> paramJsonObj = new HashMap<String, Object>();
    paramJsonObj.put("code", 200);
    paramJsonObj.put("msg", "终于成功了");
    // 封装JSONP
    return new JSONPObject(callback, paramJsonObj);
}
项目:sword-ocean    文件:BaseController.java   
/**
 * 以json格式返回SimpleResult对象
 * @param obj
 * @param callback
 * @return
 */
public JSONPObject renderJsonP(Object obj,String callback){
    JSONObject jsonObject = renderJson(obj);
    JSONPObject jsonp = new JSONPObject(callback,jsonObject);
    return jsonp;
}