如何将String转换为Date?
我试过这个:
@RequestMapping("/data/{data}")
String buscar(@PathVariable String data, Model model) {
model.addAttribute 'dataBuscar', data
def newDate = data
def df1 = new SimpleDateFormat("dd/MM/yyyy 00:00:00")
data = df1.parse(newDate)
model.addAttribute 'acessos', acessoService.buscar(data)
'acesso/acesso.index'
}
Run Code Online (Sandbox Code Playgroud)
但请告诉我这条消息:
Unparseable date: "12-01-2014"
java.text.DateFormat.parse(DateFormat.java:337)
java_text_DateFormat$parse.call(Unknown Source)
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
br.com.owse.labs.owsetime.controllers.AcessoController.buscar(AcessoController.groovy:63)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:118)
com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:52)
br.com.owse.delorean.web.filters.SitemeshSpringFilter.super$2$doFilter(SitemeshSpringFilter.groovy)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1085)
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:128)
br.com.owse.delorean.web.filters.SitemeshSpringFilter.doFilter(SitemeshSpringFilter.groovy:37)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96) …Run Code Online (Sandbox Code Playgroud) 这是我的一段代码.
def http = [100 : 'CONTINUE',200 : 'OK',400 : 'BAD REQUEST']
def listset = http.keySet()
log.info listset[0]
Run Code Online (Sandbox Code Playgroud)
我希望在这里,作为listset[0]= 100.
但是......
groovy.lang.MissingMethodException:
No signature of method: java.util.HashMap$KeySet.getAt()
is applicable for argument types: (java.lang.Integer) values: [0]
Possible solutions: getAt(java.lang.String), getAt(java.lang.String), putAt(java.lang.String, java.lang.Object), wait(), toSet(), sort() error at line: 32
Run Code Online (Sandbox Code Playgroud)
这有什么不对.. ??
我有一个自定义标记库,它返回一个布尔对象,以便我的GSP可以决定是否显示一段HTML.我想使用g:if标签检查这个布尔值,因为我还需要检查一些其他值(在taglib中不可访问).但是,我不知道如何从标签中实际调用taglib?
我试过了:
<g:if test="${<custom:tag/> && other.boolean}">
Run Code Online (Sandbox Code Playgroud)
但这会引发错误.
我也尝试过:
<g:if test="<custom:tag/> && ${other.boolean}">
Run Code Online (Sandbox Code Playgroud)
但这也会引发错误.
我用find代替:
find("from domain d where d.id=? AND d.name=?",[params.id, params.name])
Run Code Online (Sandbox Code Playgroud)
这给了我第一个匹配的结果.现在我看到有findWhere()用于:
Book.findWhere(author: params.author, title: params.title)
Run Code Online (Sandbox Code Playgroud)
还返回第一个匹配的结果集.什么是基本区别以及何时使用.
先感谢您.
我有一个grails应用程序,如果我通过它启动它,它运行正常
grails run-app
Run Code Online (Sandbox Code Playgroud)
在早期阶段,我已经将该应用程序部署到节点上的tomcat实例,并且没有遇到任何问题.然而,昨天我开始准备生产一切,并设置一个流浪盒来部署整个堆栈.突然发生了一件非常奇怪的事情:
我有一个方法
def checkEmail(String email)
Run Code Online (Sandbox Code Playgroud)
在我的RegisterController中,它调用静态方法
static String normalize(final String email) throws InvalidEmailAddressException
Run Code Online (Sandbox Code Playgroud)
在一个groovy类中,它放在我项目中相应包中的'/ src/groovy'下.
每当调用控制器中的checkEmail方法时,我都会看到以下异常:
2014-04-07 20:19:20,588 [http-bio-8080-exec-6] ERROR errors.GrailsExceptionResolver - IllegalAccessError occurred when processing request: [GET] /register/checkEmail
tried to access class com.getgrape.core.exception.InvalidEmailAddressException from class com.getgrape.authority.RegisterController. Stacktrace follows:
org.codehaus.groovy.grails.web.servlet.mvc.exceptions.ControllerExecutionException: Executing action [checkEmail] of controller [com.getgrape.authority.RegisterController] caused exception: Runtime error executing action
at grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter.doFilter(GrailsAnonymousAuthenticationFilter.java:53)
at grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter.doFilter(RequestHolderAuthenticationFilter.java:49)
at grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter.doFilter(MutableLogoutFilter.java:82)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: org.codehaus.groovy.grails.web.servlet.mvc.exceptions.ControllerExecutionException: Runtime error executing action
... 6 more
Caused by: java.lang.reflect.InvocationTargetException …Run Code Online (Sandbox Code Playgroud) 我正在研究Grails 1.3.6应用程序.我需要使用正则表达式来查找匹配的字符串.
它需要查找字符串是否包含除字母数字字符或" - "或"_"或"*"以外的任何字符串
示例字符串如下所示:
SDD884MMKG_JJGH1222
Run Code Online (Sandbox Code Playgroud)
到目前为止我想出的是,
String regEx = "^[a-zA-Z0-9*-_]+\$"
Run Code Online (Sandbox Code Playgroud)
上面的问题是它不会在字符串的结尾或开头搜索特殊字符.
我必须在"$"之前添加一个"\",否则会产生编译错误.
- Groovy:illegal string body character after dollar sign;
Run Code Online (Sandbox Code Playgroud)
任何人都可以建议在Groovy/Grails中使用更好的RegEx吗?
我有这样一段代码:
private String getUsername(PersonalAccount account) {
User usr = (User)account?.usr
String name = usr?.getName()
return name
}
Run Code Online (Sandbox Code Playgroud)
在PersonalAccount类中我们有字段:
SimpleUser usr
Run Code Online (Sandbox Code Playgroud)
用户扩展了SimpleUser
这意味着什么:?在这两行?
User usr = (User)account?.usr
String name = usr?.getName()
Run Code Online (Sandbox Code Playgroud) 使用Grails OAuth插件需要在Config.groovy中提供绝对回调URL.但是,每个环境都有不同的serverURL.
有没有办法从Config.groovy内部获取当前环境,这是我想要做的一个例子:
def devServerUrl = 'http://dev.example.com'
def prodServerUrl = 'http://prod.example.com'
def currentServerUrl = grailsApplication.metadata.environment == 'development' ? devServerUrl : prodServerUrl;
environments {
development {
grails {
serverURL = devServerUrl
}
}
production {
grails {
serverURL = prodServerUrl
}
}
}
oauth {
providers {
runkeeper {
api = RunKeeperApi
key = 'key'
secret = 'secret'
callback = currentServerUrl + '/oauth/runkeeper/callback'
}
}
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?谢谢!
commandObject当我提交表单时,我正在尝试使用它来验证我的数据.我可以在中验证hasMany关系吗commandObject?我的cenario是这样的.
牵引简单的classeswhith有很多关系:
class Book{
String nameBook
}
class Author{
String nameAuthor
static hasMany = [books:Book]
}
Run Code Online (Sandbox Code Playgroud)
很简单commandObject,我想在提交表单时验证hasMany.
@grails.validation.Validateable
class MyValidateCommand{
String nameAuthor
static hasMany = [books:Book]
static constraints = {
nameAuthor nullable:false
books nullable:false
}
}
Run Code Online (Sandbox Code Playgroud)
ps:我知道这个commandObject是错误的,它不编译.但我可以这样做吗?
我有一个从Groovy的HTTPBuilder返回的JSON对象.JSON包含一些表示为JSONNull对象的空值.问题是当我尝试在响应中渲染JSON时,我在尝试渲染JSONNull时出现错误.我得到的回复只是部分呈现的.我希望它呈现为"null".我该怎么做呢?
码:
render(contentType: "text/json") {
listOfJSONObjectsThatIncludeJSONNulls
}
Run Code Online (Sandbox Code Playgroud)
错误:
| Error 2013-09-17 11:33:56,965 [http-bio-8080-exec-4] ERROR errors.GrailsExceptionResolver - JSONException occurred when processing request: [GET] /my/action
Object is null. Stacktrace follows:
Message: Object is null
Line | Method
->> 69 | isEmpty in net.sf.json.JSONNull
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 199 | …Run Code Online (Sandbox Code Playgroud)