springboot注入语法

application.properties

server.port=8989
server.servlet.context-path=/springboot_day3
name=xiaoguo

控制器调用

package com.baizhi.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("hello")
public class HelloController {

    @Value("${name}")
    private String name;

    @GetMapping("hello")
    public String hello(){
        System.out.println("name="+name);
        return  "hello springboot_day3";
    }
}

 

posted @ 2020-06-08 21:56  生如逆旅,一苇以航  阅读(184)  评论(0编辑  收藏  举报