栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

如何通过Java实现时间轴过程解析

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何通过Java实现时间轴过程解析

这篇文章主要介绍了如何通过Java实现时间轴过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

1.需要添加FastJson的依赖处理数据。


   com.alibaba
   fastjson
   1.2.47

2.创建测试数据库和表。

3.创建entity、dao、service、controller各层,可以使用EasyCode快速生成(之前博客有教程),然后增减代码。

entity

private static final long serialVersionUID = 423496079020131231L;
  
  private Integer id;

  @JSonField(format = "yyyy-MM-dd HH:mm:ss")
  private Date time;
  
  private String content;


  public Integer getId() {
    return id;
  }

  public void setId(Integer id) {
    this.id = id;
  }

  public Date getTime() {
    return time;
  }

  public void setTime(Date time) {
    this.time = time;
  }

  public String getContent() {
    return content;
  }

  public void setContent(String content) {
    this.content = content;
  }

dao

  
  List getAllData();

service

  
  List getAllData();

serviceimpl

@Resource
  private InfoDao infoDao;

  
  public List getAllData(){
    return this.infoDao.getAllData();
  }

controller

@Resource
  private InfoDao infoDao;

  
  public List getAllData(){
    return this.infoDao.getAllData();
  }

mapper





  
    
    
    
  

  
  
    select * from ideatest.info order by time desc
  

4.前端js、css、html文件编写。

html




  
  时间轴
  
  
  



  
  


css

* {
  margin: 0;
  padding: 0;
}

.container {
  margin: 20px;
}

.container .time-line {
  position: relative;
  width: 0;
  border-right: 1px gray dashed;
}

.container .square {
  position: absolute;
  width: 10px;
  height: 10px;
  margin-left: -5px;
  background-color: gray;
}

.container .square .time {
  position: absolute;
  width: 300px;
  height: 30px;
  margin-top: -10px;
  margin-left: 20px;
  line-height: 30px;
}

.container .square .content {
  position: absolute;
  width: 300px;
  height: 60px;
  margin-top: 20px;
  margin-left: 20px;
  line-height: 60px;
}

js

$.ajax({
  url: "/info/getAllData",
  type: "GET",
  success: function(data) {
    success(data);
  }
});

function success(data) {
  var result = JSON.parse(data);
  $(".container .time-line").css({
    "height": result.length * 100 + "px"
  });
  for (var i = 0; i < result.length; i++) {
    var childNode = "" +
      ""+result[i].time+"" +
      "" + result[i].content + "" +
      "";
    $(".container .time-line").append(childNode);
  }
}

Ps:因为数据库的时区问题,所以可在数据库的连接URL后添加如下参数:

serverTimezone=Hongkong

5.效果展示

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/135122.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号