如何制作一个只有在没有错误(来自gsp)的情况下才执行的逻辑块?
此外,在创建用户后,我将如何使用Spring Security Core插件自动登录他们?
这取决于错误,例如,如果服务器端验证失败您可以将错误作为布尔值返回给您的gsp,如:
try {
xyzService.saveAndUpdateStatistics(stats)
redirect(controller:'statistic', action:'stats')
} catch(ValidationException vex) {
Boolean error = true
render(view: "stats", model:[stats:stats,error:error])
}
那么你可以简单地使用之类的东西
<g:if test="${!error}">
<g:textField name="noError" value="no-Error" />
</g:if>
第二个问题是,为什么要用springsecuritycore插件来记录它们?每次您使用springssecurity或其他我会使用的方法创建新用户时使用Apache log4j 的日志插件
def user = new User()
user.save(flush: true, failOnError: true)
log.info "User saved : "+user
http://grails.org/doc/2.2.x/ref/Plug-ins/logging.html
http://grails.org/doc/1.1.x/guide/3.%20Configuration.html#3.1.2%20Logging
http://grails-plugins.github.io/grails-spring-security-core/docs/manual/guide/6%20Helper%20Classes.html