下载地址: Groovy-Eclipse
下载地址: Tomca-Eclipse
打开Eclipse,配置Tomcat
插件,如下图所示:
命名为WB8
,然后在项目的右键菜单里,添加Groovy支持!如下图所示:
配置好Tomcat,如下图所示:
Extra information
里输入JNDI数据源,例如:
<Resource
name="jdbc/wb_mysql"
auth="Container" type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
validationQuery="select 1" testWhileIdle="true" testOnBorrow="false"
url="jdbc:mysql://127.0.0.1:3306/wb?autoReconnect=true&allowMultiQueries=true&useUnicode=true&characterEncoding=utf-8&mysqlEncoding=utf8"
username="root" password="XXXXXX"
maxActive="20" maxIdle="10" maxWait="-1" />
在项目的根目录下新建一个web
目录,把压缩文件webbuilder.zip
里的/wb
目录下的所有东西复制到新建的web
下,最后的目录结构如下图所示:
Context
把WB8
项目的context
信息更新到Tomcat的tomcat8/conf/Catalina/localhost
目录下,如下图所示:
文件wb.xml
内容如:
<Context path="/wb" reloadable="true" docBase="C:\WJW_E\WJW_DATA\OpenSource\WebBuilder\eclipse_workspace\WB8\web" workDir="C:\WJW_E\WJW_DATA\OpenSource\WebBuilder\eclipse_workspace\WB8\work" >
<!-- Extra info begin -->
<Resource
name="jdbc/wb_mysql"
auth="Container" type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
validationQuery="select 1" testWhileIdle="true" testOnBorrow="false"
url="jdbc:mysql://127.0.0.1:3306/wb?autoReconnect=true&allowMultiQueries=true&useUnicode=true&characterEncoding=utf-8&mysqlEncoding=utf8"
username="root" password="XXXXXX"
maxActive="20" maxIdle="10" maxWait="-1" />
<!-- Extra info end -->
</Context>
groovy-all-X.X.X.jar
复制到WEB-INF/lib/
目录下
修改Java Build Path
,把WEB-INF/lib
目录下的所有jar文件添加到Libraries
中!如下图所示:
WEB-INF/web.xml
,在</filter-mapping>
行下面添加: <servlet>
<servlet-name>GroovyServlet</servlet-name>
<servlet-class>groovy.servlet.GroovyServlet</servlet-class>
<init-param>
<param-name>verbose</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>logGROOVY861</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>resource.name.regex</param-name>
<param-value>gdo$</param-value>
</init-param>
<init-param>
<param-name>resource.name.replacement</param-name>
<param-value>groovy</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>GroovyServlet</servlet-name>
<url-pattern>*.gdo</url-pattern>
</servlet-mapping>
WEB-INF/groovy/test.groovy
,(按照约定,WEB-INF/groovy
是groovy文件的根目录!)def builder = new groovy.json.JsonBuilder()
builder.people {
person {
firstName 'Guillame'
lastName 'Laforge'
// Named arguments are valid values for objects too
address(
city: 'Paris',
country: 'France',
zip: 12345,
)
married true
// a list of values
conferences 'JavaOne', '你好'
}
}
out << "一般输出:"+builder.toString()
out << "<br>\r\n格式化输出:"
out << builder.toPrettyString()
Wb.request
方法或者url
直接引用,然后在groovy里定义能访问的角色,以此来判断是否有执行权限!例如://xwl文件里
Wb.request({
url: 'test.gdo',
params: {
foo: 'abc',
bar: 123
},
success: function(response) {
app.textarea1.setValue(response.responseText);
Wb.info(response.responseText);
}
});
//groovy文件里
def needRoles=['default','admin']*.toUpperCase()
def currentRoles = com.wb.common.Session.getRoles(request).toList()*.toUpperCase()
//判断角色
//任一角色
if(!currentRoles.any { needRoles.contains(it) }) {
com.wb.util.SysUtil.accessDenied(request);
}
//或者 全部角色
if(!currentRoles.containsAll(needRoles)) {
com.wb.util.SysUtil.accessDenied(request);
}
Java Build Path
,把groovy文件的根目录WEB-INF/groovy
添加到Source
中,这样就可以进行断点调试了!如下图所示:
如下图所示:
输入http://localhost:8080/wb/
,进行开发,调试!