play框架02--细说目录结构

    play的目录结构制作的相当精简,以下是从play官网截下的图片:

      

  1. app Application sources
  2. assets Compiled asset sources
  3. stylesheets Typically LESS CSS sources
  4. javascripts Typically CoffeeScript sources
  5. controllers Application controllers
  6. models Application business layer
  7. views Templates
  8. build . sbt Application build script
  9. conf Configurations files and other non - compiled resources ( on classpath )
  10. application . conf Main configuration file
  11. routes Routes definition
  12. dist Arbitrary files to be included in your projects distribution
  13. public Public assets
  14. stylesheets CSS files
  15. javascripts Javascript files
  16. images Image files
  17. project sbt configuration files
  18. build . properties Marker for sbt project
  19. plugins . sbt sbt plugins including the declaration for Play itself
  20. lib Unmanaged libraries dependencies
  21. logs Logs folder
  22. application . log Default log file
  23. target Generated stuff
  24. resolution - cache Info about dependencies
  25. scala - 2.10
  26. api Generated API docs
  27. classes Compiled class files
  28. routes Sources generated from routes
  29. twirl Sources generated from templates
  30. universal Application packaging
  31. web Compiled web assets
  32. test source folder for unit or functional tests

  app目录:

   app目录是代码目录,包含了所有的Java或者Scala的源码,一般的“hello-world”sample程序都含有controllers、models、和views三个目录,分别对应MVC三层结构中的:C、M和V;我想这大家都和清楚,大家还可以根据自己的项目需要创建其他的目录,例如utils、dao等等。例如以下:


如果有需要,你还可以建一个名为“assets”的目录,里面可以放LESS或者CoffeeScript源文件。

注意:这些controllers、models和views等目录可以随着你项目的需要而改变,例如:你可以写成com.yourcompany.controllers、com.yourcompnay.model和com.yourcompany.views而不必非得写成controllers、models和views。

conf目录:

在这个目录里,放置的都是这个应用的一些配置文件信息,有两个主要的文件:

一个是application.conf:意思很明显,就是整个应用的配置信息,里面会有一些配置的参数。包括数据库链接中数据源的信息填写,日志打印的级别等信息等等,还可以自定义一些参数。


注意:在conf中,play默认定义的有:数据库信息、应用信息(名字、 Secret key、语言等)、日志;这三块儿的信息,在conf中直接改后,效果会在应用程序中直接出现。

假如你想一用conf中自定义的配置参数:例如上图中的阿里云相关的信息,你需要在application.conf中定义之后,在程序中使用

Play.configuration.getString("oss.access_id").getOrElse("diSnug5q4zb9y2mq")

来调用。实际上某人的那三块信息也是这么来调用的。

假如你在application.conf中不想定义过多的自定义信息,你也可以写一个自定义的conf文件,然后在application.conf中引用(include “fileName.conf”)如下:




routes:路由。非常重要的部分!使用方法非常简单,在这里定义你需要的rest接口,然后接口后面对应的处理函数。如下图:



public 的目录:

这里放置的都是前端页面相关的信息,例如js、css、json文件、图片等等。


这些目录文件的名字是可以改的,但是引用的时候需要注意目录名字。包括public的名字也是可以改的。前端页面中需要其中的静态文件的话,需要再routes中添加:


然后在前端需要静态文件的地方这么引用:


这里就是用的public目录下images目录中的静态文件。

lib目录:

如果之前你是做J2EE项目的,这个目录你一定清楚,这就是放置其他依赖包的地方。(当然如果Maven有依赖链接,尽量用Maven的依赖链接)

build.sbt file:

这个文件是整个项目添加依赖包的地方,所有的依赖都写在这里。如果你是J2EE开发者的话,你一定知道Maven的pom.xml文件,在这里,build.sbt文件就相当于pom.xml的文件。


project目录:

这个目录包含了sbt构建之后的东西:

1、pulgins.sbt:插件sbt


2、build.properties:包含了sbt的版本。


target目录:

target目录包含了应用编译之后的东西,就是编译后的可执行文件。


转载https://blog.csdn.net/i6448038/article/details/48264503

猜你喜欢

转载自blog.csdn.net/J_M_S_H_T/article/details/80826302