我有一个简单的CRUD应用程序,可以将数据存储到数据库中。 我尝试通过bootstrap datepicker从单个输入中导入日期和时间。但我得到了一些奇怪的错误。
服务
def insertAction(String id, String name,String thl,Timestamp dt1){
def sql = new Sql(dataSource)
sql.execute("INSERT INTO mn (id, name, thl, dt1) VALUES (${id as long},$name,${thl as long},$dt1)")
}
控制器
def save() {
println params
[customer: customerService.insertAction(params.id,params.name,params.thl,params.dt1)]
redirect action: "list"
}
GSP
<div class='col-md-4'>
<div class="form-group">
<label class="control-label col-sm-2" for ="dt1">Date :</label>
<div class='input-group date' id="dt1">
<input id="" name="dt1" type='datetime' class="form-control" >
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
<script type="text/javascript">
$('#dt1').datetimepicker({
});
</script>
Postgres列设置为时间戳
我添加了以下代码
Timestamp ts = new Timestamp(params.getDate("dt1").getTime())
和现在的错误
URI
/Test/customer/save
Class
org.springframework.context.NoSuchMessageException
Message
No message found under code 'date.dt1.format' for locale 'en_US'.
答案 0 :(得分:1)
Inside your controller:
Timestamp ts = new Timestamp(params.getDate("dt1").getTime())
[customer: customerService.insertAction(params.id,params.name,params.thl,ts)]
As by default when you get a variable using params.key
, value is of String type. You need to manually convert it to desired type.