class PhotoController {
def index = {
def baseFolder = grailsAttributes.getApplicationContext().getResource("/").getFile().toString()
def imagesFolder = baseFolder + '/images/sps'
def imageList1 = new File(imagesFolder).list()
[imageList:imageList1]
}
}
Run Code Online (Sandbox Code Playgroud)
以上列出了非jpg文件.我怎么能避免这种情况?!
您可以在文件夹上调用eachFileMatch方法:
def imageList1 = []
new File(imagesFolder).eachFileMatch(~/.*?\.jpg/) { imageList1 << it }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
247 次 |
| 最近记录: |