小編給大家分享一下怎么通過Java實現(xiàn)時間軸過程,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
成都創(chuàng)新互聯(lián)公司主營呼蘭網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,成都app開發(fā),呼蘭h5重慶小程序開發(fā)搭建,呼蘭網(wǎng)站營銷推廣歡迎呼蘭等地區(qū)企業(yè)咨詢
1.需要添加FastJson的依賴處理數(shù)據(jù)。
<dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.47</version> </dependency>
2.創(chuàng)建測試數(shù)據(jù)庫和表。
3.創(chuàng)建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
/** * 獲取所有數(shù)據(jù) * @return */ List<Info> getAllData();
service
/** * 獲取所有數(shù)據(jù) * @return */ List<Info> getAllData();
serviceimpl
@Resource private InfoDao infoDao; /** * 獲取所有數(shù)據(jù) * @return */ public List<Info> getAllData(){ return this.infoDao.getAllData(); }
controller
@Resource private InfoDao infoDao; /** * 獲取所有數(shù)據(jù) * @return */ public List<Info> getAllData(){ return this.infoDao.getAllData(); }
mapper
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.example.dao.InfoDao"> <resultMap type="com.example.entity.Info" id="InfoMap"> <result property="id" column="id" jdbcType="INTEGER"/> <result property="time" column="time" jdbcType="TIMESTAMP"/> <result property="content" column="content" jdbcType="VARCHAR"/> </resultMap> <!-- 查詢所有數(shù)據(jù) --> <select id="getAllData" resultMap="InfoMap"> select * from ideatest.info order by time desc </select> </mapper>
4.前端js、css、html文件編寫。
html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>時間軸</title> <link rel="stylesheet" href="../static/css/tl.css"/> <script type="text/javascript" src="../static/jquery-3.4.1.js"></script> <script src="../static/js/tl.js"></script> </head> <body> <div class="container"> <div class="time-line"> </div> </div> </body> </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 = "<div class='square' style='top:" + i * 100 + "px'>" + "<div class='time'>"+result[i].time+"</div>" + "<div class='content'>" + result[i].content + "</div>" + "</div>"; $(".container .time-line").append(childNode); } }
Ps:因為數(shù)據(jù)庫的時區(qū)問題,所以可在數(shù)據(jù)庫的連接URL后添加如下參數(shù):
serverTimezone=Hongkong
5.效果展示
看完了這篇文章,相信你對“怎么通過Java實現(xiàn)時間軸過程”有了一定的了解,如果想了解更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!
本文名稱:怎么通過Java實現(xiàn)時間軸過程
網(wǎng)頁路徑:http://www.rwnh.cn/article20/jeedjo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供、標(biāo)簽優(yōu)化、域名注冊、移動網(wǎng)站建設(shè)、定制開發(fā)、定制網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)