1、Entity
@Entity
@Data
public class Bookimplements Serializable{
@Id
@GeneratedValue
private long id;
private StringbookName;
private StringbookAuther;
private StringbookIntroduce;
private StringbookCover;
}
2、DAO
public interface BookRepositoryextends JpaRepository {
}
3、service
public interface BookService {
/**
* 获取所有 Book
*/
ListfindAll();
/**
* 获取 Book
*
* @param id 编号
*/
BookfindById(Long id);
}
@Service
public class BookServiceImplimplements BookService {
@Autowired
BookRepositorybookRepository;
@Override
public ListfindAll() {
return bookRepository.findAll();
}
@Override
public BookfindById(Long id) {
return bookRepository.findById(id).get();
}
}
4、Controller
@Service
public class BookServiceImplimplements BookService {
@Autowired
BookRepositorybookRepository;
@Override
public ListfindAll() {
return bookRepository.findAll();
}
@Override
public BookfindById(Long id) {
return bookRepository.findById(id).get();
}
}
5、index
<html xmlns:th="http://www.thymeleaf.org">
<html lang="zh-CN">
<script type="text/javascript" th:src="@{https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js}">
<link th:href="@{https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css}" rel="stylesheet"/>
<meta charset="UTF-8"/>
<title>书籍列表
p{
display:inline;
}
down{
margin-top:20px;
}
title{
font-size:25px;;
}
content{
padding-top:17px;
}
container{
width:800px;
}
bookCover{
height:150px;;
width:270px;;
}
<div class="media">
<div class="media-body">
<div class="container">
<div style="margin-left: -70px">
<img src="/img/000.png">
<div class="alert alert-success" th:each="Book:${bookList}">
<div class="top">
<div class="media">
<div class="media">
<div class="media-left">
<div class="pic">
<img th:src="@{${Book.bookCover}}">
<div class="media-right">
<div class="title">
<a th:href="@{/book/{bookId}(bookId=${Book.id})}" th:text="${Book.bookName}">
<div class="content">
<p th:text="${Book.bookIntroduce}">
</html>
<html xmlns:th="http://www.thymeleaf.org">
<html lang="zh-CN">
<script type="text/javascript" th:src="@{https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js}">
<link th:href="@{https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css}" rel="stylesheet"/>
<meta charset="UTF-8"/>
<title>书籍详情
<div class="media">
<div class="media-body">
<div class="container">
<div style="margin-left: -70px">
<img src="/img/001.png">
<img th:src="@{${book.bookCover}}">
<p th:text="${book.bookName}">
<p th:text="${book.bookAuther}">
<p th:text="${book.bookIntroduce}">
</html>
网友评论