[二]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