Java tutorial
/******************************************************************************* * Copyright (c) 2005, 2014 * * Licensed under the Apache License, Version 2.0 (the "License"); *******************************************************************************/ package com.xyxy.platform.examples.showcase.demos.web; import java.util.Collections; import java.util.Map; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import com.xyxy.platform.modules.core.mapper.JsonMapper; import com.xyxy.platform.modules.core.web.MediaTypes; import com.fasterxml.jackson.databind.util.JSONPObject; /** * JsonP?Mashup ?, ?. * ??mappertoJsonP()?JSONPObject. * * */ @Controller public class MashupServerController { private static final String DEFAULT_JQUERY_JSONP_CALLBACK_PARM_NAME = "callback"; private JsonMapper mapper = new JsonMapper(); @RequestMapping(value = "/web/mashup", produces = MediaTypes.JAVASCRIPT_UTF_8) @ResponseBody public String mashup1(@RequestParam(DEFAULT_JQUERY_JSONP_CALLBACK_PARM_NAME) String callbackName) { // ??JSON. Map<String, String> map = Collections.singletonMap("content", "<p>?</p>"); // . return mapper.toJsonP(callbackName, map); } @RequestMapping(value = "/web/mashup2", produces = MediaTypes.JAVASCRIPT_UTF_8) @ResponseBody public JSONPObject mashup2(@RequestParam(DEFAULT_JQUERY_JSONP_CALLBACK_PARM_NAME) String callbackName) { // ??JSON. Map<String, String> map = Collections.singletonMap("content", "<p>?</p>"); // . return new JSONPObject(callbackName, map); } }