我认为用几个例子可以更好地解释我的问题......
获取http://myservice/myresource/?name=xxx&country=xxxx&_page=3&_page_len=10&_order=name asc
也就是说,一方面我有条件( name=xxx&country=xxxx ),另一方面我有影响查询的参数( _page=3&_page_len=10&_order=name asc )
现在,我想使用一些特殊的前缀(在这种情况下为“_”)来避免条件和参数之间的冲突(如果我的资源有“order”属性怎么办?)
有一些标准方法来处理这些情况吗?
--
我找到了这个例子(只是挑一个) http://www.peej.co.uk/articles/restful-delicious.html
获取http://del.icio.us/api/peej/bookmarks/?tag=mytag&dt=2009-05-30&start=1&end=2
但在这种情况下,条件字段已经定义(没有开始或结束属性)
我正在寻找一些通用的解决方案......
-- 编辑,一个更详细的例子来澄清
每一项都完全独立......假设我的资源是客户,并且(幸运的是)我的数据库中有数百万个客户。
所以网址可能是这样的
http://myservice/customers/?country=argentina,last_operation=2009-01-01..2010-01-01
它应该给我所有去年购买过任何东西的阿根廷客户
现在,我想使用此服务来构建浏览页面,或者使用 ajax 填充组合,因此想法是添加一些元数据来控制我应该获取哪些信息
要构建浏览页面,我会添加
http://...,_page=1,_page_len=10,_order=状态,名称
并使用 ajax 填充自动建议组合
http://...,_page=1,_page_len=100,_order=状态,名称,名称=what_ever_type_the_user *
用与用户输入的内容相匹配的前 100 个客户来填充组合...
我的问题是是否有某种标准(书面或非书面)方式以restfull url 方式编码此类内容......
我想为函数库文件运行单元测试...
也就是说,我没有一个类,它只是一个带有辅助函数的文件...
例如,我在〜/ www/test创建了一个php项目
和一个文件〜/ www/test/lib/format.php
<?php
function toUpper( $text ) {
return strtoupper( $text );
}
function toLower( $text ) {
return strtolower( $text );
}
function toProper( $text ) {
return toUpper( substr( $text, 0, 1 ) ) . toLower( substr( $text, 1) );
}
?>
Run Code Online (Sandbox Code Playgroud)
工具 - >创建PHPUnit测试给出了以下错误:
Sebastian Bergmann的PHPUnit 3.4.5.
在"/home/sas/www/test/lib/format.php"中找不到类"格式".
现在,如果我编码(手工!)文件〜/ www/test/tests/lib/FormatTest.php
<?php
require_once 'PHPUnit/Framework.php';
require_once dirname(__FILE__).'/../../lib/format.php';
class FormatTest extends PHPUnit_Framework_TestCase {
protected function setUp() {}
protected function tearDown() {}
public function testToProper() {
$this->assertEquals( …Run Code Online (Sandbox Code Playgroud) 我有一个包含超过300,000条记录的表,大小约为1.5 GB
在那张桌子里,我有三个varchar(5000)字段,其余的是小字段.
在发布时update,将这三个字段设置为''.
收缩(数据库和文件)后,数据库使用与以前几乎相同的空间...
DBCC SHRINKDATABASE(N'DataBase' )
DBCC SHRINKFILE (N'DataBase' , 1757)
DBCC SHRINKFILE (N'DataBase_log' , 344)
Run Code Online (Sandbox Code Playgroud)
有关如何回收磁盘空间的任何想法?
我有一个带有以下签名的方法
public static ActionDefinition reverse(String action, Map<String, Object> args)
Run Code Online (Sandbox Code Playgroud)
我有返回以下内容的方法:
public static Map<String, String> toMap(String value)
Run Code Online (Sandbox Code Playgroud)
有没有什么方法可以将toMap的输出转换为反向使用,例如:
ActionDefinition ad = reverse("Action.method", toMap("param1=value1,param2=value2"));
Run Code Online (Sandbox Code Playgroud)
我需要做点什么
(Map<String, Object>) toMap("param1=value1,param2=value2");
Run Code Online (Sandbox Code Playgroud)
但我无法做到这一点
我也试过以下方法
public static Map<String, String> toMap(String value) {
Map<String, Object> source = toMap(value);
Map<String, String> map = new LinkedHashMap<String, String>();
for(Map.Entry<String, Object> entry: source.entrySet()) {
map.put(entry.getKey(), (String) entry.getValue());
}
return map;
}
Run Code Online (Sandbox Code Playgroud)
但我想由于类型擦除,我得知该方法是重复的...
任何的想法?
-
编辑
我忘了声明我无法改变反向方法,正如许多人所建议的那样......
我有一个Brand类,有几个产品
在产品类中,我希望对品牌有一个参考,如下所示:
case class Brand(val name:String, val products: List[Product])
case class Product(val name: String, val brand: Brand)
Run Code Online (Sandbox Code Playgroud)
我怎么能把这些课程打包?
我的意思是,除非我有品牌,否则我无法创造产品
除非我有产品清单(因为Brand.products是val),否则我无法创建品牌
建模这种关系的最佳方法是什么?
我需要将以下库定义为依赖项:
网址:http://deploy.cloud.testmx.com:8081 / nexus/content / groups/public /
用户:testmx
传递:testmx @ testmx
groupId:testmx
artifactId:testmxcommons
版本:1.0.0-SNAPSHOT
所以我定义了以下项目/ Build.scala
import sbt._
import Keys._
import PlayProject._
object ApplicationBuild extends Build {
val appName = "testmxproject"
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
"mysql" % "mysql-connector-java" % "5.1.18",
"testmx" % "testmxcommons" % "1.0.0-SNAPSHOT"
)
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
credentials += ("testmx public", "deploy.cloud.testmx.com:8081", "testmx", "testmx@testmx"),
resolvers += "testmx public" at "http://deploy.cloud.testmx.com:8081/nexus/content/groups/public/"
) …Run Code Online (Sandbox Code Playgroud) 我一直在看计算机数据库示例,我注意到为了重用计算机解析器,list方法使用Computer.withCompany解析器,它返回一个元组(计算机,公司)
在我必须处理的情况下,而不是对计算机的id的引用,我希望有一个Computer对象,就像这样
case class Computer(id:Pk [Long] = NotAssigned,name:String,introduction:Option [Date],停止:Option [Date],company:Company)
所以我在想如何实现以下内容(当然是seudocode)
val simple = {
get[Pk[Long]]("computer.id") ~
get[String]("computer.name") ~
get[Option[Date]]("computer.introduced") ~
get[Option[Date]]("computer.discontinued") ~
get[Company]("company.*") map {
case id~name~introduced~discontinued~company => Computer(id, name, introduced, discontinued, company)
}
}
Run Code Online (Sandbox Code Playgroud)
显然,棘手的部分是如何解决getCompany
任何的想法???
我有以下行动
def save() = Action(parse.json) { implicit request =>
request.body.asOpt[IdeaType].map { ideatype =>
ideatype.save.fold(
errors => JsonBadRequest(errors),
ideatype => Ok(toJson(ideatype))
)
}.getOrElse (JsonBadRequest("Invalid type of idea entity"))
}
Run Code Online (Sandbox Code Playgroud)
我想测试一下
Web服务正常运行,如下所示:
curl -X post "http://localhost:9000/api/types"
--data "{\"name\": \"new name\", \"description\": \"new description\"}"
--header "Content-type: application/json"
Run Code Online (Sandbox Code Playgroud)
正确返回新资源
{"url":"/api/types/9","id":9,"name":"new name","description":"new description"}
Run Code Online (Sandbox Code Playgroud)
我正试着用它来测试它
"add a new ideaType, using route POST /api/types" in {
running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
val json = """{"name": "new name", "description": "new description"}"""
val Some(result) = routeAndCall(
FakeRequest(
POST,
"/api/types",
FakeHeaders(Map("Content-Type" …Run Code Online (Sandbox Code Playgroud) 我有以下方法
def show[E: Writes, T: Writes](block: RequestWithUser[AnyContent] => Either[E, T]): Action[AnyContent] = {
withErr(block)
}
Run Code Online (Sandbox Code Playgroud)
我从控制器中使用这个:
def show(id: Long) = CrudAuthAction.show { request =>
IdeaType.findByIdWithErr(id)
}
Run Code Online (Sandbox Code Playgroud)
我希望请求方法是可选的,所以我为同一个方法定义了另一个签名:
def show[E: Writes, T: Writes](block: => Either[E, T]): Action[AnyContent] = {
withErr(request => block)
}
Run Code Online (Sandbox Code Playgroud)
它工作正常,我可以省略请求参数
但是当我尝试用其他方法做同样的事情时
def list[T: Writes](block: RequestWithUser[AnyContent] => T): Action[AnyContent] = {
fromRequest(block)
}
def list[T: Writes](block: => T): Action[AnyContent] = {
fromRequest(request => block)
}
Run Code Online (Sandbox Code Playgroud)
当我想这样使用它时:
def list = CrudAuthAction.list { request =>
IdeaType.find(request.queryString)
}
Run Code Online (Sandbox Code Playgroud)
它告诉我请求缺少参数类型,我必须像这样指定:
def list …Run Code Online (Sandbox Code Playgroud) 我正在寻找客户端 JavaScript 缓存库
理想情况下,这是我想要的功能列表
我找到了一些选项,但它们似乎不是特别活跃
SO 的相关问题也有点古老......
https://github.com/monsur/jscache(这是最有前途的一个)
http://www.dustindiaz.com/javascript-cache-provider
http://sourceforge.net/projects/jsoc/
https://github.com/jeromeetienne/MicroCache.js/blob/master/microcache.js
scala ×4
anorm ×1
caching ×1
casting ×1
client-side ×1
dependencies ×1
friendly-url ×1
generics ×1
java ×1
javascript ×1
netbeans ×1
oop ×1
pagination ×1
parsing ×1
php ×1
phpunit ×1
polymorphism ×1
relationship ×1
rest ×1
sbt ×1
specs2 ×1
testing ×1
unit-testing ×1