If you are just beginning out in Grails development, the creation of custom codecs can greatly increase productivity. Codecs help you code/decode (funny that) strings. Grails ships with a bunch of them already, but when you feel like you want to create you own, greate a groovy class file (extension .groovy), with the name ending in "Codec" in your projects graips-app/utils folder. Remember that if you want to place these files in packages, you will need to create the additional folder structure to match the package structure. A sample codec structure is shown below. This file would be in the folder grails-app/utils/org/mycompany/:
package org.mycompany
import /* imports here */
class SampleCodec{
static encode = { str ->
/* Coding data goes here */
}
static decode = { str ->
/* Decoding data goes here */
}
}
Once you start your grails app, Spring will inject the methods encodeAsSample() and decodeSample() to the Java.lang.String class.
Start creating custom hash codes for your passwords now!
No comments:
Post a Comment