春季启动仅返回花括号。

huangapple 未分类评论42阅读模式
英文:

Spring boot retuns only culry braces

问题

以下是代码的中文翻译:

Entity

@Entity
@Table(name = "tbl_book")
@Data
@Getter
@Setter
@ToString
public class Book {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private long id;

    @Column(name="sku")
    private String sku;

    @Column(name="name")
    private String name;

    @Column(name="description")
    private String description;

    @Column(name="unit_price")
    private BigDecimal unitPrice;

    @Column(name="image_url")
    private String imageUrl;

    @Column(name="active")
    private boolean active;

    @Column(name="units_in_stock")
    private int unitsInStock;

    @Column(name="date_created")
    private Date createdOn;

    @Column(name="last_updated")
    private Date updatedOn;

    @ManyToOne
    @JoinColumn(name="category_id",nullable=false)
    private BookCategory category;
}

Controller

@RestController
@RequestMapping(path="/api/v1")
public class BookController {

    @Autowired
    public BookService bookService;

    @GetMapping("/books")
    public ResponseEntity<List<Book>> getAllBooks() {
        return new ResponseEntity<>(bookService.getAllBooks(), HttpStatus.OK);
    }
}

Service

@Service
public class BookService {

    @Autowired
    public BookRepository bookRepository;

    public List<Book> getAllBooks(){
        List<Book> books = bookRepository.findAll();
        System.out.println("books:" + books);
        return books;
    }
}

日志(LOG)部分未提供具体翻译内容,仅包含数据库查询日志和一些输出信息。

请注意,你可以将上述代码粘贴到Java开发环境中以运行它,但由于代码中的特殊字符已经被转义,你可能需要手动恢复这些特殊字符以便代码正常工作。如果有任何其他问题或需要进一步的帮助,请告诉我。

英文:

Entity

@Entity
@Table(name = &quot;tbl_book&quot;)
@Data
@Getter
@Setter
@ToString
public class Book {

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private long id;
	
	@Column(name=&quot;sku&quot;)
	private String sku;
	
	@Column(name=&quot;name&quot;)
	private String name;
	
	@Column(name=&quot;description&quot;)
	private String description;
	
	@Column(name=&quot;unit_price&quot;)
	private BigDecimal unitPrice;
	
	@Column(name=&quot;image_url&quot;)
	private String imageUrl;
	
	@Column(name=&quot;active&quot;)
	private boolean active;
	
	@Column(name=&quot;units_in_stock&quot;)
	private int unitsInStock;
	
	@Column(name=&quot;date_created&quot;)
	private Date createdOn;
	
	@Column(name=&quot;last_updated&quot;)
	private Date updatedOn;
	
	@ManyToOne
	@JoinColumn(name=&quot;category_id&quot;,nullable=false)
	private BookCategory category;

}

Controllar

@RestController
@RequestMapping(path=&quot;/api/v1&quot;)
public class BookController {

@Autowired
	public BookService bookService;

@GetMapping(&quot;/books&quot;)
	public ResponseEntity&lt;List&lt;Book&gt;&gt; getAllBooks() {
		return new ResponseEntity&lt;&gt;(bookService.getAllBooks(),HttpStatus.OK);
	}
}

Service

@Service
public class BookService {

	@Autowired
	public BookRepository bookRepository;
	
	public List&lt;Book&gt; getAllBooks(){
		List&lt;Book&gt; books = bookRepository.findAll();
		System.out.println(&quot;books:&quot;+books);
		return books;
	}
	
}

Output

LOG

Hibernate: select book0_.id as id1_0_, book0_.active as active2_0_, book0_.category_id as categor11_0_, book0_.date_created as date_cre3_0_, book0_.description as descript4_0_, book0_.image_url as image_ur5_0_, book0_.name as name6_0_, book0_.sku as sku7_0_, book0_.unit_price as unit_pri8_0_, book0_.units_in_stock as units_in9_0_, book0_.last_updated as last_up10_0_ from tbl_book book0_
Hibernate: select bookcatego0_.id as id1_1_0_, bookcatego0_.category_name as category2_1_0_ from tbl_category bookcatego0_ where bookcatego0_.id=?
books:[in.kunjyadav.onlinebookstore.model.Book@3c5934ee, in.kunjyadav.onlinebookstore.model.Book@49280d55, in.kunjyadav.onlinebookstore.model.Book@dbe2143, in.kunjyadav.onlinebookstore.model.Book@63997579, in.kunjyadav.onlinebookstore.model.Book@1692c3a0, in.kunjyadav.onlinebookstore.model.Book@1f593682, in.kunjyadav.onlinebookstore.model.Book@6391b813, in.kunjyadav.onlinebookstore.model.Book@4b0b3ba5, in.kunjyadav.onlinebookstore.model.Book@4b846ea7, in.kunjyadav.onlinebookstore.model.Book@1dbfbc73]

Please help...

答案1

得分: 0

提供这个 @EnableJpaRepositories(basePackages = &quot;your.package&quot;) 给你的配置类。

英文:

Provide this @EnableJpaRepositories(basePackages = &quot;your.package&quot;) to your config class.

huangapple
  • 本文由 发表于 2020年4月5日 22:32:24
  • 转载请务必保留本文链接:https://java.coder-hub.com/61044223.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定