[1].[代码] web.xml
01 |
< servlet >
|
02 |
< servlet-name >RestServlet</ servlet-name >
|
03 |
< servlet-class >net.sf.serfj.RestServlet</ servlet-class >
|
04 |
< load-on-startup >5</ load-on-startup >
|
05 |
</ servlet >
|
06 |
|
07 |
< servlet-mapping >
|
08 |
< servlet-name >RestServlet</ servlet-name >
|
09 |
< url-pattern >/banks/*</ url-pattern >
|
10 |
</ servlet-mapping >
|
11 |
|
12 |
< servlet-mapping >
|
13 |
< servlet-name >RestServlet</ servlet-name >
|
14 |
< url-pattern >/accounts/*</ url-pattern >
|
15 |
</ servlet-mapping >
|
[2].[代码] serfj.properties
1 |
# Main package where looking for classes (controllers, serializers) |
2 |
main.package=net.sf.serfj. test
|
[3].[代码] Bank.java
01 |
public class Bank extends RestController {
|
02 |
@GET
|
03 |
public void index() {
|
04 |
// By default, this action redirects to index.jsp (or index.html or index.htm)
|
05 |
}
|
06 |
|
07 |
@GET
|
08 |
public void show() {
|
09 |
// Gets ID from URL /banks/1
|
10 |
String id = this .getId( "bank" );
|
11 |
|
12 |
// Gets account's ID from URL /banks/1/accounts/2
|
13 |
String accountId = this .getId( "account" );
|
14 |
|
15 |
// Gets the account
|
16 |
Account account = // Code that gets the account 2 from bank 1
|
17 |
|
18 |
// Put account into the request so the page will be able to use it
|
19 |
this .addObject2Request( "account" , account);
|
20 |
|
21 |
// By default, this action redirects to show.jsp (or show.html or show.htm)
|
22 |
}
|
23 |
|
24 |
@GET
|
25 |
public void newResource() {
|
26 |
// By default, this action redirects to new.jsp (or new.html or new.htm)
|
27 |
}
|
28 |
|
29 |
@GET
|
30 |
public void edit() {
|
31 |
// By default, this action redirects to edit.jsp (or edit.html or edit.htm)
|
32 |
}
|
33 |
|
34 |
@POST
|
35 |
public void create() {
|
36 |
// By default, this action redirects to create.jsp (or create.html or create.htm)
|
37 |
}
|
38 |
|
39 |
@PUT
|
40 |
public void update() {
|
41 |
// Gets bank's ID
|
42 |
String id = this .getId( "bank" );
|
43 |
|
44 |
Bank bank = // Code that gets the bank object
|
45 |
|
46 |
// Gets new name for the bank
|
47 |
String name = this .getStringParam( "name" );
|
48 |
|
49 |
// Updating the bank
|
50 |
// ... Code that updates the bank's information
|
51 |
|
52 |
// By default, this action redirects to update.jsp (or update.html or update.htm)
|
53 |
}
|
54 |
|
55 |
@DELETE
|
56 |
public void delete() {
|
57 |
// By default, this action redirects to delete.jsp (or delete.html or delete.htm)
|
58 |
}
|
59 |
|
60 |
@GET
|
61 |
public void someAction() {
|
62 |
// By default, this action redirects to someAction.jsp (or someAction.html or someAction.htm)
|
63 |
}
|
64 |
} |
[4].[代码] Account.java
01 |
public class Account extends RestController {
|
02 |
@GET
|
03 |
public void index() {
|
04 |
// By default, this action redirects to index.jsp (or index.html or index.htm)
|
05 |
}
|
06 |
|
07 |
@GET
|
08 |
public void show() {
|
09 |
// By default, this action redirects to show.jsp (or show.html or show.htm)
|
10 |
}
|
11 |
|
12 |
@GET
|
13 |
public void newResource() {
|
14 |
// By default, this action redirects to new.jsp (or new.html or new.htm)
|
15 |
}
|
16 |
|
17 |
@GET
|
18 |
public void edit() {
|
19 |
// By default, this action redirects to edit.jsp (or edit.html or edit.htm)
|
20 |
}
|
21 |
|
22 |
@POST
|
23 |
public void create() {
|
24 |
// By default, this action redirects to create.jsp (or create.html or create.htm)
|
25 |
// But I want to render another page!... easy
|
26 |
this .renderPage( "mypage.jsp" );
|
27 |
}
|
28 |
|
29 |
@PUT
|
30 |
public void update() {
|
31 |
// By default, this action redirects to update.jsp (or update.html or update.htm)
|
32 |
// But I want to render another page... from another controller!... easy
|
33 |
this .renderPage( "bank" , "another_page.jsp" );
|
34 |
}
|
35 |
|
36 |
@DELETE
|
37 |
public void delete() {
|
38 |
// By default, this action redirects to delete.jsp (or delete.html or delete.htm)
|
39 |
// Well, if something happens, I want to redirect to mypage.jsp
|
40 |
if (somethingHappens) {
|
41 |
this .renderPage( "mypage.jsp" );
|
42 |
} else {
|
43 |
// Default page
|
44 |
this .renderPage();
|
45 |
}
|
46 |
}
|
47 |
|
48 |
/**
|
49 |
* If this method is called as /accounts/1/accountBalance.xml, then the balance object will
|
50 |
* be serialized as an XML, whereas if it's called as /accounts/1/accountBalance.json, the
|
51 |
* object will be serialized as a JSON object.
|
52 |
*/
|
53 |
@POST
|
54 |
public Balance accountBalance() {
|
55 |
// Gets account's Id
|
56 |
String id = this .getId( "account" );
|
57 |
|
58 |
// Calculate balance
|
59 |
BalanceManager manager = new BalanceManager();
|
60 |
Balance balance = manager.getBalance(id);
|
61 |
this .serialize(balance);
|
62 |
}
|
63 |
} |
相关推荐
SerfJ 是一个最简单的框架用来开发Java的REST的Web应用。可帮助你开发优雅的MVC架构的应用,使用惯例重于配置的思路,无需配置文件和注解。
rest-framework-tutorial, REST框架教程的源代码 REST框架教程Django REST框架教程的源代码。
django-api-rest-and-angular, 将 Django Rest框架与AngularJS结合起来的一个示例库 带有 Django Rest框架和angularjs资源的 Django API这个示例项目是博客文章的伴侣,关于如何开始使用 Django Rest框架和 ...
NULL 博文链接:https://freesky-zh.iteye.com/blog/1773014
请先阅读:http://blog.csdn.net/maoxiang/archive/2009/09/14/4551434.aspx 用简单的Servlet实现REST框架。
django-rest-framework-jwt, Django REST框架的JSON网络令牌认证支持 REST框架JWT认证 Django REST框架的代价为的JSON Web令牌认证项目的完整文档在文档可用。概述这个包提供了对 Django REST框架框架的 JSON网络...
南方航空 Rest框架及实践 Rest框架及实践
2. 由于【1】的改动,使得只有以/rest开头的URL才能映射到某资源,使用rest服务时,必须要加上/rest。 3. 由于【1】的改动,RestComponent类注册application时将资源字符串加上了/rest。 4. 由于【1】的改动和本人...
Django REST框架示例 运行pipenv install来安装依赖项。 运行pipenv shell激活Python虚拟环境。 运行数据库迁移。 (此示例使用sqlite。) ./manage.py migrate 运行单元测试。 ./manage.py test 运行服务器 ./...
完整的rest项目示例,包括客户端通过Get方式、Post方式调用服务端的方法,简单易懂!
django-rest-framework-docs, Django Rest框架 v2.API端点的清单工具 ** 这里软件包不再被维护 **,请使用 Django REST 。( 0.1.7 ) =========================== Rest框架文档Rest框架文档是为 Django Rest框架v2...
aREST_UI, 面向aREST框架的嵌入式用户界面 aREST_UI 版本 1.1.1概述aREST UI是aREST框架的嵌入式 UI 。 目前与 Arduino Mega合作,由于使用WiFi芯片,WiFi屏蔽和以太网屏蔽功能。 它与Arduino屏蔽和WiFi屏蔽以及Ard
Django REST 框架/React快速入门
Django REST框架是用于构建Web API的功能强大且灵活的工具包。 Django REST框架很棒的Web浏览Web API。 有关该项目的完整文档,请访问https://www.django-rest-framework.org/。 资助REST框架是一个由合作资助的项目...
drf-react, 结合 Django Rest框架,使用 web service Django Rest框架 反应在 geezhawk.github.io 找到的教程示例代码。要自己尝试,请克隆 repo 并运行:npm installpip install -r requirements.txtexpo
rest_condition, Django rest框架的复杂权限流( http rest_conditiondjango-rest-framework的复杂权限流。安装安装最新版本的最简单方法是使用 pip/easy_install从PyPI中提取它:pip install rest_condit
django-rest-framework-proxy, Django Rest框架代理视图 Django Rest框架代理 提供将传入请求重定向到其他API服务器的视图。功能:伪装路径HTTP基本认证( 在API和后端API之间)令牌认证支持的方法:GET/POST/PUT/...
博客:使用iServer REST API发布工作空间(Java) (http://blog.csdn.net/supermapsupport/article/details/73201166) 的示例代码
Django REST框架的无密码验证
此存储库包含工作代码示例,这些示例演示了通过与PHP集成的CyberSource REST API。 使用示例代码 样本都是完全独立且独立的。 您可以分析它们以了解特定方法的工作原理,也可以将代码片段用作自己项目的起点。 ...