springboot返回的json数据

1.搭建好springboot框架(可参考springboot入门)

 

 

2.新建一个pojo类,用来封装测试数据

public class City {

private Long id;
private Long provinceId;
private String cityName;
private String description;
...
}

 

3.编写controller层,请求映射

  

@RequestMapping("/city")
	public City getCity(){
		City c = new City();
		c.setId(1L);
		c.setProvinceId(021L);
		c.setCityName("上海");
		c.setDescription("国际化大都市");
		return  c;
}

 

 4.测试(由于没有写请求方式,springboot默认采用get请求),浏览器地址栏输入

 

  http://localhost:8080/city

  

   
springboot返回的json数据_第1张图片
 

 结论:

       

       (1)springboot 使用@RestController默认返回的数据类型是json


springboot返回的json数据_第2张图片
 

  (2) springboot默认的请求方式为get (地址栏请求可知)

       

   

 

   

  

 

 

你可能感兴趣的:(springboot)