Grails基础

1.更改 Jetty 所使用的端口

   (1).临时进行更改
grails -Dserver.port=9090 run-app 

   (2).持久更改,可以从 $GRAILS_HOME/scripts/Init.groovy 中找出以 serverPort 开头的那一行,并更改值:
serverPort = System.getProperty('server.port') ? 
             System.getProperty('server.port').toInteger() : 9090


2.记忆登录前的访问功能

    def auth() { 
        if(!session.userId) { 
            def originalRequestParams = [controller:controllerName, action:actionName] 
            originalRequestParams.putAll(params) 
            session.originalRequestParams = originalRequestParams
            
            redirect(controller:'user',action:'login') 
            return false 
        } 
    } 

    def login = { 
        if (request.method == "GET") { 
            session.userId = null 
            def user = new User() 
        } 
        else { 
            def user = User.findByUserIdAndPassword(params.userId, params.password) 
            if (user) { 
                session.userId = user.userId 

                def redirectParams = 
                    session.originalRequestParams ? session.originalRequestParams : 
                        [controller:'race'] 
                redirect(redirectParams) 
            } 
            else { 
                flash['message'] = 'Please enter a valid user ID and password' 
            } 
        } 
    } 

    def logout = { 
        session.userId = null 
        flash['message'] = 'Successfully logged out' 
        redirect(controller:'race', action:'search') 
    } 


为控制器添加拦截器
def beforeInterceptor = [action:this.&auth, except:['login', 'logout']] 


3.formatDate与formatNumber
<g:formatDate date="${race.startDateTime}" format="yyyy-MMM-dd HH:mm"/>
//带星期的:
<g:formatDate date="${it.startDateTime}" format="EEE, MMM d, yyyy"/>
//带上下午的:
<g:formatDate date="${it.startDateTime}" format="h:mm a z"/>

<g:formatNumber number="${it.distance}" format="##0.0 mi"/>
<g:formatNumber number="${it.cost}" format="\$0.00"/>

你可能感兴趣的:(java,Flash,grails,groovy)