如何在grails中正确保存双精度类型?
基本上,要保存的域不尊重浮点,因为它使它成为另一种格式 我有下一个域名如何在grails中正确保存双精度类型?,grails,groovy,double,double-precision,Grails,Groovy,Double,Double Precision,基本上,要保存的域不尊重浮点,因为它使它成为另一种格式 我有下一个域名 class Location { double latitude double longitude static belongsTo=[ product: Product ] static constraints = { latitude nullable:false, blank:false longitude nullable:false,
class Location {
double latitude
double longitude
static belongsTo=[ product: Product ]
static constraints = {
latitude nullable:false, blank:false
longitude nullable:false, blank:false
}
}
视图:
请求位置保存()的步骤
参数的到达方式类似于纬度参数=29.089177和经度参数=-110.961227
保存后,这些值存储在数据库中,如locationInstance.latitude=29089177和locationInstance.longitude=-110961227
要在视图中显示的内容类似于纬度=2.9089177E7和经度=-1.10961227E8
问题是,我有另一个主题类的项目,并且运行正常。
并尝试将属性和类型的名称更改为float和not resolved
谢谢 只需将其添加到conf/spring/resources.groovy中即可
beans = {
localeResolver(org.springframework.web.servlet.i18n.SessionLocaleResolver) {
defaultLocale = new Locale("es","MX")
java.util.Locale.setDefault(defaultLocale)
}
}
要保留坐标格式,请确保保存时不会更改。准备就绪!基本上,要保存的域不尊重浮点,因为它使其成为另一种格式,可以是什么?显示实际的
println参数
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}
}
}
beans = {
localeResolver(org.springframework.web.servlet.i18n.SessionLocaleResolver) {
defaultLocale = new Locale("es","MX")
java.util.Locale.setDefault(defaultLocale)
}
}