1. 程式人生 > >spring-boot返回json

spring-boot返回json

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