Recently, when maintaining a Java project, grails was exposed. This framework is simple and efficient. to familiarize yourself with the overall process, take the common membership as an example to illustrate the overall process.
Install
Install JDK
Grails.org downloads the package and creates environment variables according to readme instructions. grails-V verifies whether the package is normal.
See http://www.cnblogs.com/2018/archive/2011/04/17/2010877.html
Create a membership
There are implemented frameworks in. net available for use, and grails also has similar plug-ins. The spring security core plug-in used in this article is used as an example.
Create a project
$ Grails create-app bookstore
$ CD bookstore
Create users and roles: Install plug-ins and execute plug-in scripts to create management content
$ Grails install-plugin spring-security-core
$ Grails s2-quickstart com. testapp User Role
In this case, domain views controllers under grails-app creates the corresponding MVC content
Create a test Controller
$ Grails create-controller com. testapp. Secure
Grails-APP/controllers/COM/testapp/securecontroller. Groovy
@ Secured: Security indicates the security of the entire controller and method.
Grails-APP/controllers/securecontroller. Groovy
Import grails. plugins. springsecurity. Secured
@ Secured (['Role _ admin'])
Class securecontroller {
Def Index = {
Render 'Secure access only'
}
}
Attach role initialization and restrictions
Grails-APP/CONF/Bootstrap. Groovy
Import com. testapp. Role
Import com. testapp. User
Import com. testapp. userrole
Class Bootstrap {
Def springsecurityservice
Def init = {servletcontext->
Def adminrole = new role (authority: 'Role _ admin'). Save (flush: True)
Def userrole = new role (authority: 'Role _ user'). Save (flush: True)
String Password = springsecurityservice. encodepassword ('Password ')
Def testuser = new user (username: 'me', enabled: True, password: password)
Testuser. Save (flush: True)
Userrole. Create testuser, adminrole, true
Assert user. Count () = 1
Assert role. Count () = 2
Assert userrole. Count () = 1
}
}
Run
Grails run-app
Http: // localhost: 8080/bookstore/secure at this time, you need to log on, enter me/password to see the displayed content
Membership Management
Execute grails generate-all to generate user role interfaces and controllers. The following uses a plug-inSpring Security UIIntegrated membership management
Spring Security UIInstallation: Install the dependent plug-in first
Grails install-plugin mail 0.9
Grails install-plugin jquery
Grails install-plugin jquery-UI
Grails install-plugin famfamfam
Grails install-plugin spring-security-UI
0.9 indicates that a version is installed.
The following grails run-app after running:
Main Interface
User Management search interface
User editing page
The configuration directory of the grails project after the above configuration is complete
Integrated search searchable plug-in Installation
Full-text search generally uses Lucene. The searchable plug-in makes it easier to integrate Lucene.
0.6-An error occurred while running the container in snapshot. grails install-plugin searchable cannot be directly installed. perform the following steps:
1. download searchable https://svn.codehaus.org/grails-plugins/grails-searchable/branches/0_5_5_1/grails-searchable-0.5.5.1.zip
2. Installation: grails install-plugin ../grails-searchable-0.5.5.1.zip
Create search content
Grails create-Domain-class Book
Package bookstore
Class book {
Static searchable = true
String ISBN
String title
String content
Date createdat
Static constraints = {
ISBN blank: false, unique: True
Title blank: false
}
}
Generate page and Controller
Grails generate-All bookstore. Book
Run
Grails run-app
BookContent creation
Http: // localhost: 8080/bookstore/book/List
BookContent Search
Modify Homepage
Grails-app \ conf \ urlmappings. Groovy
"/" (View: "/Index") maps the file views \ index. GSP. If you need to change the file, modify the file.
Package
The above execution uses a memory-based database, and the actual deployment environment generally uses databases such as MySQL.
Configure the database in conf \ datasource. Groovy
Place the JDBC driver in the lib directory
Run the grails war package application and deploy the bookstore \ target \ bookstore-0.1.war to Tomcat.
The running effect is similar to the above
Reference
Official reference
Http://grails.org/
Http://grails.org/plugins/ plug-in Directory
Searchable reference
Http://grails.org/plugin/searchable
Https://svn.codehaus.org/grails-plugins/grails-searchable/trunk/ http://grails.org/Searchable+Plugin+-+Quick+start
Summary
Grails simplifiesProgramThe structure and organization of Java, coupled with the characteristics of Dynamic Language, greatly improve the efficiency and convenience, and hope to develop better in the Java World.