实体类
package com.itheima.entity;
import jdk.jfr.DataAmount;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.util.Date;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Component
@ConfigurationProperties(prefix = "book")
public class Book {
private int id;
private String bookName;
private String author;
private String description;
private String press;
private Date createDate;
private int inventory;
private int typeId;
private String bookCode;
private String picturePath;
private double price;
private int salesNumber;
private int saleState;
}
yml文件
book:
id: 2
bookName: springBoot企业级开发教程
author: heima
description: 这是一段描述
press: 人民邮电出版社
createDate: 2021/07/12
控制层:
package com.itheima.controller;
import com.itheima.entity.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.sql.DataSource;
@RestController
public class HelloController {
@Autowired
private DataSource dataSource;
@Autowired
private Book book;
@GetMapping("hello")
public Book hello(){
System.out.println("dataSource = "+dataSource);
return book;
}
}
?respose:
?
?
|