码迷,mamicode.com
首页 > 编程语言 > 详细

spring-boot返回json

时间:2018-06-08 21:58:01      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:spring-boot返回json

实体
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

标签:spring-boot返回json

原文地址:http://blog.51cto.com/357712148/2126585

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!