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

猜你喜欢

转载自blog.51cto.com/357712148/2126585
今日推荐