@RequestMapping(value = "/vacation/getVacation", method = RequestMethod.GET)
@ResponseBody
public String getVacation(HttpServletResponse response) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("id", 111);
map.put("title", "event1");
map.put("start", "2011-07-28");
map.put("url", "http://yahoo.com/");
String json = new Gson().toJson(map);
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
return json;
}
spring:
@ResponseBody @RequestBody. , HTTP ( ).
:
@RequestMapping(value = "/something", method = RequestMethod.PUT)
@ResponseBody
public String helloWorld() {
return "Hello World";
}
, :
response.getWriter().write(json);
, freemarker: spring mvc response.write ?
, ajax:
$(document).ready(function () {
var calendar = $('#calendar').fullCalendar({
editable: true,
eventSources: [{
url: '[@spring.url '/vacation/getVacation'/]',
type: 'GET',
data: {
start: 'start',
id: 'id',
title: 'title,'
},
error: function () {
alert('there was an error while fetching events!');
},
color: 'yellow',
textColor: 'black',
dataType: 'json'
}])
};)
};
, , , , . URL-, firebug.
, spring . InternalResourceViewResolver. :
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
, , , jsp.
, . , firebug , URL:
: eventSources: [{// URL: '/springway/vacation/getVacation', : 'GET', data: {start: 'start', id: 'id', title: 'title, '}
, , URL-. , firebug, , . URL- .
js:
url: '[@spring.url '/vacation/getVacation'/]',
url: '/vacation/getVacation',
@ spring.url, , , , .