http://kjunichi.cocolog-nifty.com/misc/2012/02/jsdoitgoogle-ap.html
このページを見ると、実はできる?
ringoJSは、javaのクラスに割と自由にアクセスできるのか。
これも参考になる
http://stackoverflow.com/questions/8464618/reading-and-writing-data-using-ringojs-on-app-engine
JAVAで普通にdatastoreを使う方法
https://developers.google.com/appengine/docs/java/datastore/entities?hl=ja
知らなかったが、ringoJSではjavaのクラスを割と自由に使えるんだな。
そこで、gae javaでdatastoreを使う方法をそのまま移植して、以下のようなコードでいけた。
action.js
var response = require('ringo/jsgi/response'); var mustache = require('ringo/mustache'); exports.index = function (req) { var template = getResource("./templates/index.html").content; //javaのdatastoreいじるためのクラス importPackage(com.google.appengine.api.datastore); var datastore = DatastoreServiceFactory.getDatastoreService(); //var datastore = com.google.appengine.api.datastore.DatastoreServiceFactory.getDatastoreService(); //保存 var testPost = new com.google.appengine.api.datastore.Entity("TestPost","post2"); testPost.setProperty("content", "testdayo!!!!!"); datastore.put(testPost); var key = KeyFactory.createKey("TestPost", "post2"); // Getting the entity var blogPost = datastore.get(key); // Reading the properties var content = blogPost.getProperty("content"); return response.html( mustache.to_html(template, { title: "RingoJS test page", content: content }) ); };
また、html側では、このcontentを表示している。
<!DOCTYPE html> <html]]> <head]]> <title]]>Welcome to Ringo</title]]> <link rel="stylesheet" href="stylesheets/page.css" /> <link rel="stylesheet" href="stylesheets/index.css" /> </head]]> <body]]> <div id="header"><h1]]>{{title}}</h1></div]]> <div id="body"]]> {{content}} </div]]> <script type="text/javascript" src="javascripts/index.js"></script]]> </body]]> </html]]>
- 作者: 井上誠一郎
- 出版社/メーカー: 技術評論社
- 発売日: 2011/04/20
- メディア: 大型本
- 購入: 8人 クリック: 1,158回
- この商品を含むブログ (22件) を見る
作ればわかる!Google App Engine for Javaプログラミング
- 作者: 中垣健志
- 出版社/メーカー: 翔泳社
- 発売日: 2011/04/23
- メディア: 大型本
- 購入: 3人 クリック: 104回
- この商品を含むブログ (24件) を見る