我有一堆字符串
asdf v1.0
jkl v3.04
Run Code Online (Sandbox Code Playgroud)
我的所有字符串都是一组字符,后跟一个空格,然后是'v',然后是一个数字.我想从每个字符串中提取,在'v'之前的部分和在'v'之前的空格字符,以便:
asdf v1.0 becomes 'asdf'
jkl v3.04 becomes 'jkl'
Run Code Online (Sandbox Code Playgroud)
只需要一些帮助.我尝试takeWhile { it != 'v' }但最终在结果字符串中的'v'之前包含了我不想要的空格.
我有一个空白(全新的)Grails 2.3.8项目,我正在尝试学习如何使用导出插件,到目前为止我刚刚添加了这一行:
compile ":export:1.6"
Run Code Online (Sandbox Code Playgroud)
到我的BuildConfig.goovy和我的Config.groovy的一些mime类型:
grails.mime.types = [ // the first one is the default format
all: '*/*', // 'all' maps to '*' or the first available format in withFormat
atom: 'application/atom+xml',
css: 'text/css',
csv: 'text/csv',
form: 'application/x-www-form-urlencoded',
html: ['text/html','application/xhtml+xml'],
js: 'text/javascript',
pdf: 'application/pdf',
rtf: 'application/rtf',
excel: 'application/vnd.ms-excel',
ods: 'application/vnd.oasis.opendocument.spreadsheet',
json: ['application/json', 'text/json'],
multipartForm: 'multipart/form-data',
rss: 'application/rss+xml',
text: 'text/plain',
hal: ['application/hal+json','application/hal+xml'],
xml: ['text/xml', 'application/xml']
]
Run Code Online (Sandbox Code Playgroud)
并尝试运行该应用程序,但得到这些错误:
| Error Resolve error obtaining dependencies: Could not find artifact org.odftoolkit:odfdom- java:jar:0.8.5 in grailsCentral …Run Code Online (Sandbox Code Playgroud) 在阅读"Grails的权威指南"时,我对命令对象感到有些困惑.它们似乎是域类的包装,以协助验证,但这是通过内置约束进一步通过自定义验证器在域类中可用的功能,那么命令对象的确做什么以及我们需要它的动机是什么?
本书通过陈述来开始讨论命令对象
"有时某个特定的动作不需要域类的参与,但仍需要验证用户输入."
但是,它演示了关于Album域类的命令对象的声明和使用.因此,无论命令对象做什么,它仍然与域类密切相关.我确信我的困惑完全是由于我缺乏理解,所以我希望得到任何澄清.谢谢.
当我们在Grails甚至Spring中谈到命令对象时,它们是否与数据传输对象相同?意思是,命令对象是DTO企业设计模式实现的一个例子吗?如果没有,有什么区别?
例如,如何找到Spring Boot启动spring-boot-starter-data-jpa器依赖项带入项目的Hibernate版本?
在将 Hibernate 与 Spring Boot JPA 结合使用时,我注意到,当尝试在扩展 Spring 的 CrudRepository 接口的存储库工件中实现更新方法时,必须将要更新的整个实体对象传递给这样的更新方法。直观上这似乎很浪费,我想知道什么是一种干净的方法来让 Spring Data/JPA 假设只有那些传入的值需要更新,而那些未传入的值则保持不变。
这是目前的服务方法,
public void updateCustomer(Long id, Customer customer) throws Exception {
customerRepository.save(customer);
}
Run Code Online (Sandbox Code Playgroud) 我有一个函数返回多个这样的值:
def func1() {
return [val1, val2]
}
Run Code Online (Sandbox Code Playgroud)
如何将这些返回值分配给调用此函数的函数中的另一个变量.我想它会是这样的:
def funcThatCalledfunc1 {
def [x,y] = func1()
}
Run Code Online (Sandbox Code Playgroud)
我想最终x拥有价值val1和y价值val2.
我需要编写一个Groovy函数来检查两个给定的字符串是否匹配至少90%.我只是想知道是否有人知道我可以在Grails项目中使用的已经存在的这种实用方法.我还没有真正编写过这个方法,但理想情况下这就是它的工作方式:
def doStringsMatch(String str1, String str2) {
if (str1 and str2 match at least 90% or
str1 appears in str2 somewhere or
str2 appears in str1 somewhere)
return true
else
return false
}
Run Code Online (Sandbox Code Playgroud)
谢谢
我试图${project.version}在我的所有pom.xml文件中找到字符串,并用其他东西替换它.然而,IDEA的Find in path功能将此视为正则表达式,因此抱怨它是错误的.我想我需要一些转义字符,但找不到它们是什么.
这行代码:
def exists = (existingIndRecs.find{ existant -> existant.uniqueId == incomingRecord.uniqueId}????? ? true : false)
Run Code Online (Sandbox Code Playgroud)
在编译时导致此错误:
/FileImportService.groovy: 184: expecting ')', found '?????' @ line 184, column 100.
Id == incomingRecord.uniqueId}????? ? tr
^
Run Code Online (Sandbox Code Playgroud)
1错误
如果我评论这一行,文件中的其余776行代码编译就好了.我在Groovy Web控制台中尝试了这一行,没有问题.奇怪.
grails ×5
groovy ×4
spring ×2
spring-boot ×2
hibernate ×1
java ×1
regex ×1
spring-data ×1
spring-mvc ×1
string ×1