Reputation: 98
i have i simple CRUD application that stores data to a database. I try to import date and time from a single input by a bootstrap datepicker. But i got some weird error.
Service
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)")
}
Controller
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 column is set to timestamp
I added the following code
Timestamp ts = new Timestamp(params.getDate("dt1").getTime())
and the erros in now this
URI
/Test/customer/save
Class
org.springframework.context.NoSuchMessageException
Message
No message found under code 'date.dt1.format' for locale 'en_US'.
Upvotes: 0
Views: 764
Reputation: 2188
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.
Upvotes: 1