Grails3.x版本中,默认情况下url的请求都需要进行controller跳转,如果想要直接访问src/main/webapp下的静态资源(css、js、html等),需要以下几步设置:
1.在src/main/webapp下创建html,如test.html
2.在UrlMappings.groovy文件中进行如下设置:
class UrlMappings {
static excludes = [
'/diagram-viewer/*',
'/editor-app/*'
]
static mappings = {
"/$controller/$action?/$id?(.$format)?" {
constraints {
// apply constraints here
}
}
"/"(view: "/index")
"500"(view: '/error')
"404"(view: '/notFound')
}
}
重点在于excludes,表示声明中的文件无需进行mapping映射过滤
3.在application.yml中添加"grails:resources:pattern:'/**'"。
该设置可有可无,如果无当前设置,静态文件访问路径为:项目名/static/test.html,加入当前设置后static路径可忽略。