小编Rou*_*oul的帖子

Spring MVC将对象转换为REST服务中的JSON

我正在尝试使用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)

java rest spring json spring-mvc

13
推荐指数
3
解决办法
9万
查看次数

在ColdFusion中返回JSON数据作为响应

我在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)

coldfusion json

6
推荐指数
1
解决办法
6130
查看次数

如何使用CFHTTP使用action = PATCH进行HTTP调用(ColdFusion 10)

我正在集成iCIMS的REST API,发现一些REST API调用需要http动词PATCH.但是,似乎ColdFusion 10不支持这一点.有没有办法解决?

coldfusion cfhttp

3
推荐指数
1
解决办法
929
查看次数

标签 统计

coldfusion ×2

json ×2

cfhttp ×1

java ×1

rest ×1

spring ×1

spring-mvc ×1