package com.lc.controller;
import java.util.HashMap;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class HelloController {
@RequestMapping("/app/hello")
@ResponseBody
public Map<String,String> hello(){
Map<String,String> m=new HashMap<>();
m.put(“hello”, “hello”);
return m;
}
}
本文介绍了一个使用SpringBoot框架创建的简单RESTful API示例,通过一个HelloController控制器展示如何返回JSON格式的数据。该示例使用了Java语言,并且在控制器中定义了一个映射到/app/hello路径的方法,通过@ResponseBody注解将Map类型的数据直接转换为JSON响应。
46万+





