[二]SpringBoot 之 简单的接口

(1)编写一个实体类Demo

package me.shijunjie.entity;

public class Demo {
    private long id;

    private String name;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    
    
}

(2)编写Controller

package me.shijunjie.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import me.shijunjie.entity.Demo;

@RestController
@RequestMapping("/demo")
public class DemoController {
     
    @RequestMapping("/testDemo")
    public Demo getDemo(){

       Demo demo = new Demo();

       demo.setId(1);

       demo.setName("Shijunjie");

       return demo;

    }
}

(3)运行并测试

 

 

 

posted @ 2017-02-14 16:19  GodTelMe  阅读(3463)  评论(0编辑  收藏  举报