Play Framework Cookbook (play框架食谱...)2

本文介绍了一种使用注解来定义路由的方法,详细解释了如何通过注解实现控制器调用及HTTP方法映射,并展示了如何使用curl进行测试。

Installing and enabling the module should not leave any open questions for you at this point. 

在安装开启模块这一点上,你应该别留下任何模糊的问题。

As you can see in the controller, it is now filled with annotations that resemble the entries in the routes.conf file,

 正如你所看到的在控制器中,它现在充满了注释,就像于进入了routes.conf(路由配置)文件,

which you could possibly have deleted by now for this example.

或许现在这个例子已经被你删除了.

However, then your application will not start, so you have to have an empty file at least.

然而,你的程序将为此无法启动,所以你至少要有一个空白文件。

The @ServeStatic annotation replaces the static command in the routes file.

在路由文件中,@ServeStatic注释代替了静态命令

 The @StaticRoutes annotation is just used for grouping several @ServeStatic annotations and could be left out in this example.

这个@StaticRoutes注释只是用来划分出几个@ServeStatic注解,其实,在这例子中可以忽略。

Each controller call now has to have an annotation in order to be reachable. 

现在,为了达到每个控制器调用,不得不都有了一个注释。

The name of the annotation is the HTTP method, or @Any, if it should match all HTTP methods.

注释的名字是HTTP方法,,或者@Any,如果它需要匹配所有的HTTP方法。

 Its only mandatory parameter is the value, 

它的唯一强制性参数是这个值

which resembles the URI—the second field in the routes.conf. 

就像在路由配置中的第二个属性URI

All other parameters are optional. Especially interesting is the priority parameter, 

所有其他参数都是可选的。特别令人注意的是参数优先级,

which can be used to give certain methods precedence. 

可给某些方法优先权。

This allows a lower prioritized catch-all controller like in the preceding example, 

这样就允许一个较低的优先权捕获所有控制器,就像在之前的例子中那样。

but a special handling is required if the URI is called with the PUT method. 

但是一种特殊处理是必需的,那就是如果URI已被PUT方法调用。

You can easily check the correct behavior by using curl, 

通过使用curl,你可以很容易检查正确的行为。

a very practical command line HTTP client:

一个非常实用的HTTP客户端命令行:

(来自百度:cURL是一个利用URL语法在命令行下工作的文件传输工具。它支持文件的上传和下载,所以是综合传输工具,但按传统,习惯称cURL为下载工具。cURL支援的通讯协定有FTP、FTPS、HTTP、HTTPS...)

curl -v localhost:9000/
This command should give you a result similar to this:
> GET / HTTP/1.1
> User-Agent: curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0 
OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18
> Host: localhost:9000
> Accept: */*
>
< HTTP/1.1 403 Forbidden
< Server: Play! Framework;1.1;dev
< Content-Type: text/html; charset=utf-8
< Set-Cookie: PLAY_FLASH=;Path=/
< Set-Cookie: PLAY_ERRORS=;Path=/
< Set-Cookie: PLAY_SESSION=0c7df945a5375480993f51914804284a3bb
ca726-%00___ID%3A70963572-b0fc-4c8c-b8d5-871cb842c5a2%00;Path=/
< Cache-Control: no-cache
< Content-Length: 32
<
<h1>Reserved for administrator</h1>


You can see the HTTP error message and the content returned. You can trigger a PUT request 
in a similar fashion:
curl -X PUT -v localhost:9000/
> PUT / HTTP/1.1
> User-Agent: curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0 
OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18
> Host: localhost:9000
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: Play! Framework;1.1;dev
< Content-Type: text/plain; charset=utf-8
< Set-Cookie: PLAY_FLASH=;Path=/
< Set-Cookie: PLAY_ERRORS=;Path=/
< Set-Cookie: PLAY_SESSION=f0cb6762afa7c860dde3fe1907e8847347
6e2564-%00___ID%3A6cc88736-20bb-43c1-9d43-42af47728132%00;Path=/
< Cache-Control: no-cache
< Content-Length: 16
Secret news here
As you can see now, the priority has voted the controller method for the PUT method which is 
chosen and returned.

基于NSGA-III算法求解微电网多目标优化调度研究(Matlab代码实现)内容概要:本文围绕基于NSGA-III算法的微电网多目标优化调度展开研究,重点介绍了如何利用该先进多目标进化算法解决微电网系统中多个相互冲突的目标(如运行成本最小化、碳排放最低、供电可靠性最高等)的协同优化问题。文中结合Matlab代码实现,详细阐述了NSGA-III算法的基本原理、在微电网调度模型中的建模过程、约束条件处理、目标函数设计以及仿真结果分析,展示了其相较于传统优化方法在求解高维、非线性、多目标问题上的优越性。同时,文档还提供了丰富的相关研究案例和技术支持背景,涵盖电力系统优化、智能算法应用及Matlab仿真等多个方面。; 适合人群:具备一定电力系统基础知识和Matlab编程能力的研究生、科研人员及从事能源优化领域的工程技术人员;尤其适合正在进行微电网调度、多目标优化算法研究或撰写相关论文的研究者。; 使用场景及目标:①掌握NSGA-III算法的核心思想及其在复杂能源系统优化中的应用方式;②学习如何构建微电网多目标调度模型并利用Matlab进行仿真求解;③为科研项目、毕业论文或实际工程提供算法实现参考和技术支撑。; 阅读建议:建议读者结合文中提供的Matlab代码实例,逐步调试运行并深入理解算法流程与模型构建细节,同时可参考文档中列出的其他优化案例进行横向对比学习,以提升综合应用能力。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值