没想到使用 NetBeans 6.1 Beta 能很方便的开发基于数据库的REST应用。
在参考Database-Driven Applications With NetBeans IDE and MySQL之后,我也做了REST的应用测试,结果很令人兴奋,没有编写一行代码就让自己的第一个REST跑了起来,而且是基于 JPA的。
现总结如下:
先通过 Tools>Plugins>安装 RESTful Web Services插件。
创建一个Web应用,然后新建 Entity Classes from Database 和 RESTFul Web Services from Entity Classe。
使用GlassFish V2 部署此应用, 并通过 GlassFish Admin Console 在MySQLPool(需要你新建)的Additional Properties加入DatabaseName, User, Password 属性和属性值
最后, 点击右键选择 Test RESTFul Web Services, 你会获得如下的信息: (注: 我采用的是petstore中的account表).
1 /accounts/ACID/
(http://localhost:8080/WebApplication4/resources/accounts/ACID/)
2 /accounts/j2ee/
(http://localhost:8080/WebApplication4/resources/accounts/j2ee/)
点击连接 http://localhost:8080/WebApplication4/resources/accounts/j2ee/ 获得以下信息:
<account uri=”http://localhost:8080/WebApplication4/resources/accounts/j2ee/”>
<addr1>901 San Antonio Road</addr1>
<addr2>MS UCUP02-206</addr2>
<city>Palo Alto</city>
<country>USA</country>
<email>yourname@yourdomain.com</email>
<firstname>ABC</firstname>
<lastname>XYX</lastname>
<phone>555-555-5555</phone>
<state>CA</state>
<status>OK</status>
<userid>j2ee</userid>
<zip>94303</zip>
</account>