- 浏览: 110659 次
- 性别:
- 来自: 济南
最新评论
-
anttu:
groovy -
MeltingSnower:
基于ext的?
grails +zkoss -
mymelon:
代码能不能放出来看看啊。
grails +zkoss -
dellsoft:
用的csc365kl 写道请问你的控制层是怎么处理的 是用的g ...
grails +zkoss -
csc365kl:
请问你的控制层是怎么处理的 是用的grails的 还是 zk的 ...
grails +zkoss
使用hibernate 的自定义主键
import org.hibernate.SessionFactory
class PersonController {
SessionFactory sessionFactory
def index = { redirect(action:list,params:params) }
// the delete, save and update actions only accept POST requests
static allowedMethods = [delete:'POST', save:'POST', update:'POST']
def list = {
params.max = Math.min( params.max ? params.max.toInteger() : 10, 100)
[ personInstanceList: Person.list( params ), personInstanceTotal: Person.count() ]
}
def show = {
def personInstance = Person.findById( params.id.toString() )
if(!personInstance) {
flash.message = "Person not found with id ${params.id}"
redirect(action:list)
}
else { return [ personInstance : personInstance ] }
}
def delete = {
def personInstance = Person.get( params.id )
if(personInstance) {
try {
personInstance.delete()
flash.message = "Person ${params.id} deleted"
redirect(action:list)
}
catch(org.springframework.dao.DataIntegrityViolationException e) {
flash.message = "Person ${params.id} could not be deleted"
redirect(action:show,id:params.id)
}
}
else {
flash.message = "Person not found with id ${params.id}"
redirect(action:list)
}
}
def edit = {
def personInstance = Person.get( params.id )
if(!personInstance) {
flash.message = "Person not found with id ${params.id}"
redirect(action:list)
}
else {
return [ personInstance : personInstance ]
}
}
def update = {
def personInstance = Person.get( params.id )
if(personInstance) {
if(params.version) {
def version = params.version.toLong()
if(personInstance.version > version) {
personInstance.errors.rejectValue("version", "person.optimistic.locking.failure", "Another user has updated this Person while you were editing.")
render(view:'edit',model:[personInstance:personInstance])
return
}
}
personInstance.properties = params
if(!personInstance.hasErrors() && personInstance.save()) {
flash.message = "Person ${params.id} updated"
redirect(action:show,id:personInstance.id)
}
else {
render(view:'edit',model:[personInstance:personInstance])
}
}
else {
flash.message = "Person not found with id ${params.id}"
redirect(action:edit,id:params.id)
}
}
def create = {
def personInstance = new Person()
personInstance.properties = params
return ['personInstance':personInstance]
}
def save = {
def session = sessionFactory.getCurrentSession()
def tx = session.beginTransaction()
def personInstance = new Person(params)
Psnbbm psnbbm = Psnbbm.findBySPrefix("CKNM")
Long curId = psnbbm.curValue
int nmLength = psnbbm.nmLength
personInstance.id = (curId+1).toString().padLeft(9,"0")
if(!personInstance.hasErrors() && personInstance.save()) {
psnbbm.curValue = curId+1
psnbbm.save()
tx.commit()
flash.message = "Person ${personInstance.id} created"
redirect(action:show,id:personInstance.id)
}
else {
tx.rollback()
render(view:'create',model:[personInstance:personInstance])
}
}
}
def session = sessionFactory.getCurrentSession()
def tx = session.beginTransaction()
def personInstance = new Person(params)
Psnbbm psnbbm = Psnbbm.findBySPrefix("CKNM")
Long curId = psnbbm.curValue
int nmLength = psnbbm.nmLength
personInstance.id = (curId+1).toString().padLeft(9,"0")
if(!personInstance.hasErrors() && personInstance.save()) {
psnbbm.curValue = curId+1
psnbbm.save()
tx.commit()
flash.message = "Person ${personInstance.id} created"
redirect(action:show,id:personInstance.id)
}
自定义的编码表
class Psnbbm { String sPrefix Long curValue int nmLength String description static constraints = { } }
class Person { String id String foo static mapping = { id column: "id", generator: "assigned" version false } def beforeInsert = { } }
方式二、
class Pwcity implements Serializable{ String id String fchs String feng String fzip String faircode String ftype Long forder = 0 String fctry Date dateCreated Date lastUpdated static constraints = { // fid(nullable:false,uinque:true,size:0..10) fchs(nullable:false,size:0..20) feng(nullable:false,size:0..40) fzip(nullable:false,size:0..10) faircode(nullable:false,size:0..10) ftype(nullable:false,size:0..8) fctry(nullable:false,size:0..20) } static mapping = { autoTimestamp false table 'PWCITY' version false // id composite :['fid'] id column: 'CITY_ID' ,sqlType:'varchar(10)',generator:'assigned',unique:'true' fchs column: 'CITY_ZHS' feng column: 'CITY_ENG' fzip column: 'CITY_ZIP' faircode column: 'CITY_AIRCODE' ftype column: 'CITY_TYPE' forder column: 'CITY_ORDER' fctry column: 'CITY_CTRY' dateCreated column: 'YGZD_CRTIME' lastUpdated column: 'YGZD_UPTIME' } public void setId(String s) { id = s.padLeft(10,"0") } public String getId() { return id } def beforeInsert() { dateCreated = new Date() lastUpdated = new Date() } def beforeUpdate() { lastUpdated = new Date() } }
发表评论
-
Rescheduling a Quartz job programatically
2012-02-14 11:34 0In our current project we fa ... -
1.4M
2011-06-23 20:44 8141.4 版本后,如果用代理上网,需要设置代理,才能让grail ... -
groovy Ip地址表达式
2011-04-28 18:55 1563 -
change the default locale
2011-04-13 19:37 946... -
groovy
2010-08-09 14:40 1157def urls = ["ip1" ... -
grails + jquery grid plugin
2010-03-14 09:52 1510Jquery Grid Json 格式方法 http ... -
grails +zkoss 开发总结
2010-03-14 09:42 1507zk component develop 一、)jav ... -
grails 开发总结
2010-03-14 09:40 1586在使用grails 开发的过程,一些总结,随笔 ... -
grails +zkoss
2010-01-09 16:58 1265基于grails+zkoss应用 1)登录窗口 2)主 ... -
grails 跟踪 sql
2009-05-14 15:53 1027http://www.piragua.com/2009/06/ ... -
grails 原始sql
2009-05-09 22:13 1224import groovy.sql.Sql; c ... -
hibernate custom generator
2009-05-09 20:54 1021public class CustomIdSequenceGe ... -
grails 1.1 Gorm 部分新特性提前知道
2008-10-30 17:21 1807说明:grails 1.1部分新特性,我只是看 grails ... -
grailsflow
2008-10-30 16:43 2413grailsflow 具体地址 http:/ ... -
grails 根据数据库自动生产 domains
2008-07-04 17:25 2893GenerateDataabase.groovy impo ... -
grails 导出 excel
2008-07-04 17:21 6497用 poi 来导出 excel 文件 import or ... -
grails war 包定制
2008-07-04 17:18 1463在config.groovy 下面配置 grails.war ... -
grails datasource 中配置数据源用户名称和密码 加密
2008-07-04 17:16 2428在datasource.groovy password = Y ... -
grails 自定义 validator
2008-07-04 17:05 1123http://www.zorched.net/2008/01/ ... -
grails services transaction
2008-07-02 15:26 1603在 graisl 应用中,默认情况下,services 的事务 ...
相关推荐
Grails Grails Grails Grails Grails
The definitive guide to grails 2 英文版 书和随书代码, 学习grails必备
Grails Cometed. The best web push
详细介绍grails框架的奥秘,英文版你值得拥有
Grails权威指南Grails权威指南Grails权威指南Grails权威指南Grails权威指南Grails权威指南
grails参考文档 The Grails Framework - Reference Documentation Authors: Graeme Rocher, Marc Palmer Version: 1.0.3
Grails项目的应用越来越多,而对于初学者来说,在Eclipse下搭建Grails项目是一个难题,这个文档将教会你如何搭建Grails项目,希望对你有所帮助。
Grails入门指南中文pdf -- 针对grails1.0.4更新,附加idea8 开发grails的流程
The Grails Framework - Reference Documentation
First-time developers are amazed at how quickly you can get a page-centric MVC web site up and running thanks to the scaffolding and convention over configuration that Grails provides. Advanced web ...
在学习任何东西之前,最重要的是培养兴趣,Groovy世界最耀眼的技术之一--Grails相信大家早已耳闻,我将通过Grails实战系列文章 向您展现Grails的迷人风采,使您感受到Grails的魅力,以至疯狂地爱上Grails,并坠入...
Grails1.1中文文档
grails+Xfire webservice
详细讲解grails开发环境配置。 详细讲解grails连接mysql数据库,crud开发
grails-2.1.zip.001
Grails专为下一代JavaWeb应用程序而设计的框架,其借助于Groovy动态语言,使Web开发变得简单而方便。Grails尽量为更多现有的Java项目创建一个全面的框架(不仅局限于视图处理),这和当前一些Java框架提供给用户的一...
Grails 中文 参考手册
Grails 1.3.7英文版官方参考手册,学习Grails的权威指南