我想要发表评论的时候获得时间,并且将时间赋给数据库表的time
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
<style>
.el-table .warning-row {
background: oldlace;
}
.el-table .success-row {
background: #f0f9eb;
}
style>
head>
<body>
<div id="app">
<template>
<div class="demo-type" >
<div style="text-align: right">
<el-avatar src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png">el-avatar>
div>
div>
template>
<div style="text-align: right">${user.username}div>
<el-row>
<el-button type="info" @click="dialogVisible = true" plain>吐槽el-button>
el-row>
<el-dialog
:visible.sync="dialogVisible"
width="30%"
>
<el-form ref="form" :model="comment" label-width="80px">
<el-form-item label=${user.username}>
el-form-item>
<%-- <el-form-item>--%>
<%-- <el-input type="hidden" v-model="comment.time">el-input>--%>
<%-- el-form-item>--%>
<el-form-item label="吐槽">
<el-input type="textarea" v-model="comment.comment">el-input>
el-form-item>
<el-form-item label="话题">
<el-input v-model="comment.topic">el-input>
el-form-item>
el-form>
<span slot="footer" class="dialog-footer">
<el-button type="primary" @click="onSubmit">吐槽一下el-button>
<el-button @click="dialogVisible = false">取 消el-button>
span>
el-dialog>
<template>
<el-table
:data="tableData"
style="width: 100%"
:row-class-name="tableRowClassName">
<el-table-column
prop="username"
label="用户名"
align="center"
width="180">
el-table-column>
<el-table-column
prop="comment"
align="center"
label="评论">
el-table-column>
<el-table-column
prop="topic"
align="center"
label="话题" width="180">
el-table-column>
<el-table-column
prop="support"
align="center"
label="支持" width="180">
el-table-column>
<el-table-column
prop="time"
label="日期"
align="center"
width="180">
el-table-column>
<el-table-column
label="操作"
align="center"
width="180">
<el-row>
<el-button type="primary">修改el-button>
<el-button type="danger">删除el-button>
el-row>
el-table-column>
el-table>
template>
div>
<script src="js/vue.js">script>
<script src="element-ui/lib/index.js">script>
<link rel="stylesheet" href="element-ui/lib/theme-chalk/index.css">
<script src="js/axios-0.18.0.js">script>
<script>
new Vue({
el: "#app",
mounted() {
this.selectAll();
},
methods: {
//查询所有的方法
selectAll(){
var _this = this;
//页面加载后,发送异步请求获取数据
axios({
method: "get",
url: "http://localhost:8080/web-demo/selectAllServlet"
}).then(function (resp) {
_this.tableData = resp.data;
})
},
tableRowClassName({row, rowIndex}) {
if (rowIndex === 1) {
return 'warning-row';
} else if (rowIndex === 3) {
return 'success-row';
}
return '';
},
// addcomment(){
// console.log(this.comment) ;
// },
onSubmit() {
//console.log('submit!');
// <%--this.username = ${user.username};--%>
var _this = this;
axios({
method: "post",
url:"http://localhost:8080/web-demo/addServlet",
data:_this.comment
}).then(function (resp){
if(resp.data == "success"){
//添加成功
//关闭窗口
_this.dialogVisible = false;
//查询所有
_this.selectAll();
}
})
}
}, data() {
return {
//评论数据
comment:{
id:"",
username:"${user.username}",
comment:'',
topic:'',
support:'0',
time:""
},
//添加对话框是否展示
dialogVisible: false,
tableData: [{
}]
}
}
})
script>
body>
html>
数据库字段默认添加时间为当前时间,不用指定这个字段插入
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',