基本上要保存的域不尊重浮点,因为它会变成另一种格式
我有下一个域
class Location {
double latitude
double longitude
static belongsTo=[ product: Product ]
static constraints = {
latitude nullable:false, blank:false
longitude nullable:false, blank:false
}
}
看法:
<g:form class="form-horizontal" action="create" id="${locationInstance?.product?.id}" >
<fieldset>
<f:with bean="locationInstance">
<f:field property="lat"/>
<f:field property="lon"/>
</f:with>
</fieldset>
</g:form>
<button type="button" class="submit btn btn-primary">
<i class="icon-plus"></i>
<g:message code="default.add.label" args="[message(code: 'location.label', default:'Location')]" default="Add Map"/>
</button>
控制器:
import grails.converters.JSON
class LocationController {
def create() {
def model = [productInstance:Product.findByIdAndUser(params.remove("id"),negoexService.currentUser)]
def responseReturn = [success:false]
def redirectParams = [controller:"product", action:"list"]
if (!model.productInstance) {
responseReturn.message = message(code: "default.not.found.message", args: [message(code: "product.label", default: "Product"), params.id])
}else{
redirectParams.action = "edit"
redirectParams.id = model.productInstance.id
params.product = model.productInstance
params.remove("action")
params.remove("controller")
model.locationInstance = new Location(params)
println params // here are showed 29.089177 and -110.961227
println model.locationInstance.lat // out is 2.9089177E7
println model.locationInstance.lon // out is -1.10961227E8
if(request.method=="POST"){
if (model.locationInstance.save(flush: true)) {
responseReturn.success = true
responseReturn.message = message(code: "default.created.message", args: [message(code: "location.label", default: "Location"), model.locationInstance])
}else{
responseReturn.errors = model.locationInstance.errors.allErrors
}
}
}
withFormat {
html {
if(request.xhr && !model.productInstance){
render view:"/messageAjax", model:responseReturn
}else{
if(responseReturn.message){flash.message = responseReturn.message}
if(!model.productInstance || responseReturn.success){
redirect redirectParams
}else{
render view:"create"+(request.xhr?"Ajax":""), model:model
}
}
}
json {render responseReturn as JSON}
js {render responseReturn as JSON}
xml {render responseReturn as XML}
}
}
请求位置保存()
参数在保存后像 params.latitude=29.089177 和 params.longitude=-110.961227 一样到达,这些值像 locationInstance.latitude=29089177 和 locationInstance.longitude=-110961227 一样存储在数据库中。
要在视图中显示,如 latitude=2.9089177E7 和 longitude=-1.10961227E8
有什么问题,我有另一个主题类项目并且运行正常。并尝试将属性名称和类型更改为浮动而不是解析
谢谢!