我正在尝试使用Spring MVC创建一个REST服务,如果我返回一个普通的字符串,它正在工作.我的要求是返回Java对象的JSON字符串.不知道如何通过隐式转换实现这一点.
这是我的代码:
StudentService.java
package com.spring.schoolmanagement.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.spring.schoolmanagement.dao.CourseDAOImpl;
import com.spring.schoolmanagement.dao.StateDAOImpl;
import com.spring.schoolmanagement.dao.StudentDAOImpl;
import com.spring.schoolmanagement.model.Student;
@Controller
@RequestMapping("/rest/student")
public class StudentService {
@Autowired
private CourseDAOImpl courseService;
@Autowired
private StudentDAOImpl studentService;
@Autowired
private StateDAOImpl stateService;
@RequestMapping(value = "/{id}", method = RequestMethod.GET, headers = "Accept=*/*")
@ResponseBody
public Student home(@PathVariable int id) {
return this.studentService.getById(id);
}
@RequestMapping(method = RequestMethod.GET, headers = "Accept=*/*")
@ResponseBody
public List<Student> getAll() throws Exception {
return this.studentService.getAll(); …Run Code Online (Sandbox Code Playgroud) 我在ICIMS API工作.我需要在ICIMS服务器的cfm页面调用中返回JSON数据和标题中的一些特定数据.
这里的回应应该是:
响应工作流状态将PUSH事件更改为平台:
HTTP/1.1 303 See Other
Location: http://xx.xx.xx.xx:8085/selectpackage?systemHash=101
Content-Type: application/json
{
"userMessage":"Confirm or modify package.",
}
Run Code Online (Sandbox Code Playgroud)
提前致谢.
回答:
> <cfset contentString = '{"userMessage": "Confirm or modify package."}'
> />
>
> <cfheader name="Location"
> value="http://xx.xx.xx.xx:8085/selectpackage?systemHash=101" />
> <cfcontent type="application/json" variable="#toBinary( toBase64( contentString ) )#" />
Run Code Online (Sandbox Code Playgroud) 我正在集成iCIMS的REST API,发现一些REST API调用需要http动词PATCH.但是,似乎ColdFusion 10不支持这一点.有没有办法解决?