nummy / play-framework-reference Goto Github PK
View Code? Open in Web Editor NEWplay参考手册
Home Page: http://play.readthedocs.io/
play参考手册
Home Page: http://play.readthedocs.io/
如果JSON能够直接映射到对应的类,那么可以省去写Reads[T]、Writes[T]或Format[T]的麻烦。
假设存在样式类Resident:
case class Resident(name: String, age: Int, role: Option[String])
下面的代码创建一个Reads[Resident]:
import play.api.libs.json._
implicit val residentReads = Json.reads[Resident]
当程序编译的时候,Play会自动检查我们的类,然后插入以下代码:
import play.api.libs.json._
import play.api.libs.functional.syntax._
implicit val residentReads = (
(__ \ "name").read[String] and
(__ \ "age").read[Int] and
(__ \ "role").readNullable[String]
)(Resident)
同样的,我们还可以创建:
import play.api.libs.json._
implicit val residentWrites = Json.writes[Resident]
import play.api.libs.json._
implicit val residentFormat = Json.format[Resident]
但是这样做的话,我们定义的类必须满足以下条件:
样式类刚好满足上述要求,所以原生支持。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.