我正在探索Play框架2,我必须说我印象深刻!只有一件事我无法解决(暂时),那就是搜索实现.
他们在Play 2中工作吗?
我来自Spring和Seam这个Hibernate Search很常见的世界.有没有实现?你如何玩2个人实现你的搜索功能?
由于我渴望在我的Play 2项目中使用弹性搜索,我已阅读 http://www.elasticsearch.org/guide/reference/java-api/并添加了依赖项:
Build.scala:
import sbt._
import Keys._
import PlayProject._
object ApplicationBuild extends Build {
val appName = "test"
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
// Add your project dependencies here,
"mysql" % "mysql-connector-java" % "5.1.18",
"org.elasticsearch" % "elasticsearch" % "0.19.10"
)
val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings(
// Add your own project settings here
resolvers += Resolver.url("GitHub Play2-elasticsearch Repository", url("http://cleverage.github.com/play2-elasticsearch/releases/"))(Resolver.ivyStylePatterns)
)
}
Run Code Online (Sandbox Code Playgroud)
找到并下载dependecy,检查播放依赖项:
Here are the resolved dependencies of your application:
+-------------------------------------------------------------------+---------------------------------------------------------+------------------------------------+
| …Run Code Online (Sandbox Code Playgroud) 我正在尝试发出http请求.代码如下所示:
NSString *urlString = [NSString stringWithString:@"http://www.foo.se/bartojson.php?venue=47497"];
NSLog(@"retain %d urlString %@", [urlString retainCount], urlString );
NSURL *url = [NSURL URLWithString:urlString];
[urlString release];
NSString *jsonString = [NSString stringWithContentsOfURL:url];
NSDictionary *httpResult = [jsonString JSONValue];
Run Code Online (Sandbox Code Playgroud)
在浏览器中调用页面时,结果如下所示:
{"name":"test","description":"这是一个测试." ,"评论":[{"等级":"5","描述":"不错"},{"等级":"3","描述":"非常好!"}}}
但是从代码中调用它时我得到了这个:
Error Domain = org.brautaset.JSON.ErrorDomain Code = 3 UserInfo = 0x582640"密钥期望的对象值:评论"
对于指向新词典的评论似乎存在一些问题.你能帮我理解这个错误信息吗?
好!正如标题所述,我在使用服务帐户时遇到了一些严重的身份验证问题.所以,让我们从一开始就开始,因为我觉得我已经尝试了一切!
服务设置为:

Drive SDK设置:

服务帐户Api访问:

如此处所述的Api客户端访问权限:http://support.google.com/a/bin/answer.py? hl = zh-CN&answer = 162106

代码:
public static void callSpreadsheetApi() {
GoogleCredential credential = null;
try {
credential = new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId("2363XXXXXX19.apps.googleusercontent.com")
.setServiceAccountScopes(DriveScopes.DRIVE, "https://spreadsheets.google.com/feeds", "https://docs.google.com/feeds")
.setServiceAccountPrivateKeyFromP12File(new File("/Users/stevesmith/Desktop/c02e064935d33c3389f6ab1dbf9ea747a5bdaac5-privatekey.p12"))
.setServiceAccountUser("steve.smith@reco.se")
.build();
} catch (GeneralSecurityException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Drive drive = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).build();
com.google.api.services.drive.model.File file = new com.google.api.services.drive.model.File();
file.setTitle("test");
file.setMimeType("application/vnd.google-apps.spreadsheet");
Drive.Files.Insert insert = null;
try {
insert = drive.files().insert(file);
file = insert.execute();
} …Run Code Online (Sandbox Code Playgroud) 我正在用Ebean构建一个Play2应用程序.我创建了一个服务类,其中包含一个通过id列表获取场地的方法:
public static List<Venue> getVenuesForIds(List<Long> list){
ArrayList<Venue> venues = new ArrayList<Venue>();
String sql = "select c.id, c.name from Company c where in (:ids)";
List<SqlRow> sqlRows =
Ebean.createSqlQuery(sql).setParameter("ids", list).findList();
for(SqlRow row : sqlRows) {
venues.add(new Venue(row.getLong("id"), row.getString("name")));
}
return venues;
}
Run Code Online (Sandbox Code Playgroud)
但是我得到了:
[PersistenceException: Query threw SQLException:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'in (201639091,201637666)' at line 1 Query was: select c.id, c.name from …Run Code Online (Sandbox Code Playgroud) 这是我的模板:
@(smsReviewForm: Form[SmsReview], grades: Seq[Grade])
@styles = {
}
@scripts = {
}
@import mobile.mobileMain
@import helper._
@mobileMain(Messages("reco.index.title"), styles, scripts) {
<div id="header">
<p class="floatleft"><img src="@routes.Assets.at("images/mobile/general/reco.png")" alt="Reco" /></p>
<div class="clear"></div>
</div>
@helper.form(routes.Sms.submit) {
@helper.inputText(
smsReviewForm("lastname"),
'_label -> "Label",
'_id -> "lastname"
)
<div class="actions">
<input type="submit" class="btn primary" value="Submit">
</div>
}
}
Run Code Online (Sandbox Code Playgroud)
使用常规时@import helper._,我的应用程序中生成的html看起来像play 2.1文档中的示例:
<dl class=" " id="lastname_field">
<dt><label for="lastname">Label</label></dt>
<dd>
<input type="text" id="lastname" name="lastname" value="">
</dd>
<dd class="info">Required</dd>
</dl>
Run Code Online (Sandbox Code Playgroud)
如果我使用@import helper.twitterBootstrap._它看起来像:
<div …Run Code Online (Sandbox Code Playgroud) 我目前正在解析非常大的xml文件> 40 MB.我刚刚开始使用scala进行开发,所以我浏览了一些好的库,并偶然发现了Scala Scales,它似乎非常擅长处理大文件.
我读过:http: //scala-scales.googlecode.com/svn/sites/scales/scales-xml_2.9.1/0.2/ScalesXmlIntro.html,http : //scala-scales.googlecode.com/svn/sites/秤/秤-xml_2.9.2/0.4.4/PullParsing.html
然后测试了pullXml函数,以确保正确导入所有库.
val pull = pullXml(new FileReader("/Users/mycrazyxml/tmp/large.xml"))
while( pull.hasNext ){
pull.next match {
case Left( i : XmlItem ) =>
// Handle XmlItem
Logger.info("XmlItem: "+i)
case Left( e : Elem ) => {
// Handle Element
Logger.info("Element: "+e)
}
case Right(endElem) =>
// Handle endElement
Logger.info("Endelement: "+endElem)
}
}
Run Code Online (Sandbox Code Playgroud)
这导致整个文件打印到控制台!太好了!现在是时候创建对象并保存到数据库了,但是我很难掌握如何以一种好的方式做到这一点.我真的需要一些如何做到这一点的好例子.
例如.以下XML具有多个Enterprise元素,这些元素可以包含一个或多个LocalUnit.这里的想法是使用LocalUnits数组创建一个Enterprise对象.当endElement是Enterprise的结束标记时,使用带有LocalUnits的Enterprise对象调用save方法.
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Info SYSTEM "info.dtd">
<Info>
<Enterprise>
<RegNo>12345678</RegNo>
<Address>
<StreetInfo>
<StreetName>Infinite Loop</StreetName>
<StreetNumber>1</StreetNumber>
</StreetInfo>
</Address>
<EName>
<Legal>Crazy Company</Legal> …Run Code Online (Sandbox Code Playgroud) 我正在浏览:http: //www.playframework.com/documentation/2.1.1/ScalaJsonCombinators并搜索在执行读写操作时如何排除值.它可能在那里,但我找不到它.
所以,假设我有一个案例类预订,有一堆参数,一个creationTime和bookingId.当从对象写入Json时,我想编写所有参数但是当从Json读取对象时,例如当在我的控制器中创建POST时:
def createBooking = Action(parse.json) {
implicit request => {
request.body.validate[Booking].map {
case (booking) => {
Logger.info("" + booking)
Ok("ONLY TEST")
}
}.recoverTotal {
e => BadRequest("Detected error:" + JsError.toFlatJson(e))
}
}
}
Run Code Online (Sandbox Code Playgroud)
我不想在Json POST中提供值creationTime和bookingId,我不想用我的Reads impl读取值:
package models.booking
import java.util.UUID
import org.joda.time.{DateTime}
import play.api.libs.functional.syntax._
import play.api.libs.json._
case class Booking (bookingId: UUID,
rId: Long,
creationTime: DateTime,
user: User,
dateTime: BookingTime,
numOfGuest: Int,
status: BookingState.BookingState) {
def …Run Code Online (Sandbox Code Playgroud) 我将IntelliJ(12.1.4)升级到新的Play 2.0支持(0.5.54)插件,发生了两件事:
IntelliJ不再重新编译我的.scala类,这意味着如果我将一个方法的签名从def某事(s1:String)= {}更改为def某事(s1:String,s2:String)= {}我得到一个在第一个参数之后预期的错误.我通过播放从终端运行应用程序,debug ~run应用程序重新编译没有问题.
scala.html未正确评估,我收到很多语法错误.颜色编码也是错误的.我试图按照评论中的建议将Scala插件更改为每晚构建(0.10.281), 但它仍然无法正常工作.
这是疯狂的坏事,因为它使IntelliJ的工作痛苦和适得其反.报告了一个错误:http://youtrack.jetbrains.com/issue/SCL-5749但在此期间我该怎么办?有人解决了这个问题吗?
当我用ReactiveMongo调用我的mongo实例时,我正在尝试进行理解.该方法应检查是否返回任何结果,如果不返回Future(NotFound).但我收到一个我不明白的错误.
[info] Compiling 8 Scala sources and 1 Java source to /Users/Projects/reco_play/parser/target/scala-2.10/classes...
[error] /Users/Projects/reco_play/parser/app/controllers/Application.scala:94: value map is not a member of Object
[error] }.getOrElse(Future(NotFound))
[error] ^
[error] one error found
[error] (compile:compile) Compilation failed
Run Code Online (Sandbox Code Playgroud)
进口:
import play.api.mvc._
import play.api.Play.current
import play.api.Logger
import play.modules.reactivemongo.{ReactiveMongoPlugin, MongoController}
import models.{Company}
import reactivemongo.api.collections.default.BSONCollection
import reactivemongo.bson.{BSONObjectID, BSONDocument}
import org.joda.time.DateTime
import scala.concurrent.{Future, ExecutionContext}
Run Code Online (Sandbox Code Playgroud)
方法:
def showEditForm(id: String) = Action {
implicit request =>
implicit val reader = Company.CompanyReader
Async {
val objectId = new BSONObjectID(id)
val cursor …Run Code Online (Sandbox Code Playgroud)