SpringDataJPA小练习

制作一个表格,通过点击其中一项进入另一个表格

显示效果

20180920190352.png
20180920190401.png

主要代码

controller类

@Controller
@RequestMapping(value = "/star")
public class StarController {
    private static final String STAR_DETAIL_PATH_NAME = "starDetail";
    private static final String STAR_LIST_PATH_NAME="starList";
    @Resource
    StarService starService;

    @GetMapping(value = "/all")
    public  String getStarList(ModelMap map){
        map.addAttribute("starList",starService.findAll());
        return STAR_LIST_PATH_NAME;
    }

    @GetMapping(value = "/{id}")
     public String getStar(@PathVariable Integer id,ModelMap map){
        map.addAttribute("star",starService.findById(id));
        return STAR_DETAIL_PATH_NAME;
       //change
    }

前端代码

<html xmlns:th="http://www.thymeleaf.org">
<html lang="zh-CN">
<head>
   <script type="text/javascript" th:src="@{https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js}"></script>
   <link th:href="@{https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css}" rel="stylesheet"/>
   <style>
       .pic{
           height: 200px;
           width:150px;
       }
   </style>
   <meta charset="UTF-8"/>
   <title>dj展示表</title>
</head>
<body>
<div class="container">
   <h3>Spring Data JPA练习 </h3>
   <legend>
       <strong>dj表</strong>
   </legend>
   <div class="col-md-4">
       <p th:text="${star.id}"></p>
       <img src="">
       <p th:text="${star.starInfo}"></p>
       <img th:src="@{${star.starImage}}" class="pic" >
       <p th:text="${star.starName}"></p>
       <p th:text="${star.starSex}"></p>
       <p th:text="${star.starWorks}"></p>
   </div>
</div>
</body>
</html>
<html lang="zh-CN">
<head>
    <script type="text/javascript" th:src="@{https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js}"></script>
    <link th:href="@{https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css}" rel="stylesheet"/>
    <meta charset="UTF-8"/>
    <title>dj列表</title>
<body>
<div class="container">
    <h3>Spring Data JPA练习 </h3>
    <table class="table table-hover table-condensed">
        <legend>
            <strong>dj表</strong>
        </legend>
        <thead>
        <tr>
            <th>编号</th>
            <th>简介</th>
            <th>名字</th>
            <th>性别</th>
            <th>作品</th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="star : ${starList}">
            <th scope="row" th:text="${star.id}"></th>
            <td th:text="${star.starInfo}"></td>
            <td><a th:href="@{/star/{starId}(starId=${star.id})}" th:text="${star.starName}"></a></td>
            <td th:text="${star.starSex}"></td>
            <td th:text="${star.starWorks}"></td>

        </tr>
        </tbody>
    </table>
</div>
</body>
</html>

完整代码

https://github.com/heiyeziran/JPA/tree/master/spring-data-jpa/src

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 46,992评论 6 342
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,099评论 19 139
  • 人,一个极其聪明的个体,有着健全的思维和能力,能够独立完成每天的生活所需,探知一切未知而又神秘的发现,感触在...
    皆非_lx阅读 229评论 0 0
  • 人海茫茫两两相望 会心一笑从此不忘 回想过往 时光悠长 酸甜苦辣 喜乐哀愁 岁月沧桑 等待绝望 执子之手 原是空想...
    旧时光夜未央阅读 213评论 0 2
  • 被撕裂的斑駁 塗上老舊顏色 不被在意的位置 低吟淺頌 無人唱和
    憨憨爹阅读 96评论 0 0