[二]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)运行并测试

 

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM