实体
package com.dao;
public class person {
private String name;
private Integer age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge(int i) {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
}
运行
package com.liwen;
import com.dao.person;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HellCotroller {
@RequestMapping("/hello")
public String Hello()
{
return "liwen good!";
}
@RequestMapping("/person")
public person getPerson()
{
person per = new person();
per.setAge(22);
per.setName("李玟");
return per;
}
}
package com.liwen;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Appmin {
public static void main(String[] args) {
SpringApplication.run(Appmin.class,args);
}
}
结果
![spring-boot返回json](http://i2.51cto.com/images/blog/201806/08/2f34e7782ebd0bc0621dad0cb6a948de.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)