为什么我得到[Some] Object而不是[String]对象?
Some对象在方法调用中不能用作String参数.
的config def回报String,所以我期望类型为String.
但是当我输入"你好"时,Scala得到它是正确的.
码
def config(s: String) = Play.current.configuration.getString(s).toString()
Logger.info(config("recaptcha.publicKey"))
Logger.info("Hello")
Run Code Online (Sandbox Code Playgroud)
产量
[info] application - Some(6LeDMdASAAAAAC4CFIDY-5M7NEZ_WnO0NO9CSdtj)
[info] application - Hello
Run Code Online (Sandbox Code Playgroud) 我很难解读Scala API文档.
例如,我已经定义了一个在数据库中使用的时间戳.
def postedDate = column[Timestamp]("posted_date", O NotNull, O Default new Timestamp(Calendar.getInstance.getTimeInMillis), O DBType("timestamp"))
Run Code Online (Sandbox Code Playgroud)
如果我没有阅读几个例子,其中没有一个在API文档中,我怎么能构建这个语句?
从Column文档中我怎么知道参数?
我猜测它与TimestampTypeMapperDelegate有关,但它仍然不清楚如何使用它.
你能定义一组变量供以后使用吗?
这里有一些伪代码突出了我的意图:
def coordinates = x1, y1, x2, y2
log("Drawing from (%4.1f, %4.1f) to (%4.1f, %4.1f)".format(coordinates))
canvas.drawLine(coordinates, linePaint)
Run Code Online (Sandbox Code Playgroud)
这是一个包含重复代码的工作示例.
log("Drawing from (%4.1f, %4.1f) to (%4.1f, %4.1f)".format(x1, y1, x2, y2))
canvas.drawLine(x1, y1, x2, y2, linePaint)
Run Code Online (Sandbox Code Playgroud) 我有一个播放模板,其中参数的最典型场景是"null".
我已经明白,惯用的Scala更喜欢Option.
我来自java的第一个直觉是使用null.
带null的情况:
在控制器中
views.html.addPost(errors.errorsAsJson)
Run Code Online (Sandbox Code Playgroud)
在视图中
@(errors: play.api.libs.json.JsValue = null)
...
@if(errors != null){@errors}
Run Code Online (Sandbox Code Playgroud)
选项案例:
在控制器中
views.html.addPost(Option(errors.errorsAsJson))
Run Code Online (Sandbox Code Playgroud)
在视图中
@(errors: Option[play.api.libs.json.JsValue] = None)
...
@{errors match {
case None => {}
case _ => {errors.get}
}
}
Run Code Online (Sandbox Code Playgroud)
更新:我现在明白了.
代替:
@{errors match {
case None => {}
case _ => {errors.get}
}
}
Run Code Online (Sandbox Code Playgroud)
我可以这样做
@errors
Run Code Online (Sandbox Code Playgroud)
更新2:
显然我没有用null进行空检查?也许有些Play framework神奇?调用null变量毫无例外地工作.
我决定学习Scala/Play(服务器端),并决定同时学习Android(客户端)游戏开发以增加开发.
我有一个关于如何在Android中为HTTP请求设计好的问题.
根据我的理解,最好的方法是将HTTP请求委托给扩展抽象AsyncTask类的类.
您是否必须为您覆盖AsyncTask的doInBackground方法中的每个不同逻辑执行新的扩展?
对我来说,为每个请求逻辑创建一个类并不是很自然,而是在一个类中封装了几个连贯的方法.
我刚刚开始玩一点,但我对设计不满意,因为我不喜欢我设计的varargs对象doInBackground(Object... params).
通过这种设计,我放松了类型安全性,并且params对象远非直观和直观,这是我在代码中努力的方法.
这是我想要改进的代码.
public class GameActivity extends Activity {
private class MyCellListener implements ICellListener {
public void onCellSelected() {
ServerProxy.postSelectedCell(row, col, player.getUser());
...
// ServerProxy.other();
public class ServerProxy extends AsyncTask<Object, Void, Void>{
private static final String TAG = ServerProxy.class.getSimpleName();
private static final String SERVER_ADDRESS = "http://127.0.0.1";
// Prevent external instantiation
private ServerProxy(){};
public static void postSelectedCell(int row, int cell, User user){
List<NameValuePair> postParameters = …Run Code Online (Sandbox Code Playgroud) 我为什么要这么做
trait Compiler {
var printInstruction: String
}
class JavaCompiler extends Compiler {
var printInstruction = "System.out.print(arg0);"
}
Run Code Online (Sandbox Code Playgroud)
代替
trait Compiler {
var printInstruction: String
}
class JavaCompiler extends Compiler {
printInstruction = "System.out.print(arg0);"
}
Run Code Online (Sandbox Code Playgroud)
什么时候
trait Compiler {
var printInstruction: String
def printInstruction: String
}
Run Code Online (Sandbox Code Playgroud)
给出编译错误.
我正在尝试建立一个链接到我的网站和Facebook,并在其上放置一些元数据!我的目标是管理这些数据:
<meta property="og:title" content="MY_PAGE_TITLE" />
<meta property="og:description" content="MY_DESCRIPTION_TEXT" />
Run Code Online (Sandbox Code Playgroud)
不幸的是,我的Web应用程序(在PHP上)结构不合理,我还没有定义正确的MVC!这是非常程序化的,因此在渲染主html标题部分之后,我应该从数据库中提取我应该放在这些元标记上的信息.
所以,我试过的是:
<script type="text/javascript">
$('head').append("<meta property=\"og:title\" content=\"MY_PAGE_TITLE\" />");
$('head').append("<meta property=\"og:description\" content=\"MY_DESCRIPTION_TEXT\" />");
</script>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/it_IT/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<fb:like href="<?=$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]?>" send="false" layout="button_count" width="130" show_faces="false"></fb:like>
Run Code Online (Sandbox Code Playgroud)
但事实上,它不起作用!我的意思是,在头上添加元标记,然后尝试渲染它.
你知道一些策略吗?我会避免将它们直接插入头部的选项,因为正如我所说,我想要插入的文本是在头部之后(由于网站的组织错误).
我相信另一个解决方案,希望你知道一个!
scala ×5
android ×1
asynchronous ×1
facebook ×1
html ×1
http ×1
java ×1
javascript ×1
oop ×1
php ×1
scalaquery ×1