demo project for grails quick study
Tutorial:
GGTS -> File -> Grails Project
System.setProperty("socket.proxyHost", "192.168.1.4");
System.setProperty("socket.proxyPort", "5678");
Note: Change your proxy address accordingly
class Book {
String name
Date dateCreated
Date lastUpdated
static constraints = {
name blank: false, unique: true
dateCreated()
lastUpdated()
}
}
class BookController { static scaffold = true }
book.name.label = 书名
book.dateCreated.label = 入库时间
book.lastUpdated.label = 更新时间
// Spring security to auth users
compile ":spring-security-core:2.0-RC3"
// Bootstrap kickstart plugin
compile ":kickstart-with-bootstrap:1.1.0"
// Jetty embedded server
runtime ':war-exec:1.0.1'
Note: You can find more plugins at https://grails.org/plugins/ Remember to refresh your project through: Right click on project name -> Grails Tools -> Refresh Dependencies
s2-quickstart store User Role
kickstart
'/**': ['ROLE_ADMIN']
def init = { servletContext ->
if (User.count() != 0) {
return
}
user()
}
def user() {
def adminRole = new Role(authority: 'ROLE_ADMIN').save(flush: true)
def userRole = new Role(authority: 'ROLE_USER').save(flush: true)
def admin = new User(username: 'admin', password: 'admin').save(flush: true)
def user = new User(username: 'user', password: 'user').save(flush: true)
UserRole.create(admin, adminRole, true)
UserRole.create(user, userRole, true)
}
"/" {
controller = 'book'
action = { 'index' }
view = { 'index' }
}
<sec:ifLoggedIn>
<ul class="nav navbar-nav navbar-right">
<li><g:link controller="user" action="index">
<g:message code="user.label" default="User" />
</g:link></li>
<li><g:link controller="book" action="index">
<g:message code="book.label" default="Book" />
</g:link></li>
<g:render template="/_menu/admin"/>
<g:render template="/_menu/info"/>
<li><g:link controller="logout" action="index">
<g:message code="security.signoff.label" default="Logout" />
</g:link></li>
</ul>
</sec:ifLoggedIn>
grails.plugin.springsecurity.logout.postOnly = false
class Book {
String name
User user
Date dateCreated
Date lastUpdated
static constraints = {
name blank: false, unique: true
user blank: true, nullable: true
dateCreated()
lastUpdated()
}
}
@Override // Override toString for a nicer / more descriptive UI
public String toString() {
return username;
}