java_Ninja实战过程

使用Ninja马上两年了,之前多多少少的都是跟着项目模仿着写,今年上半年准备从一个小项目开始从始至终走一遍;

首先官网:http://www.ninjaframework.org;

github:  https://github.com/ninjaframework/ninja

微信公众号:

 

---------------------------------------------------------------------------------------------------

1:准备:jdk1.8(环境变量配置)等;IDEA(开发工具);GIT(版本控制器);maven(项目构建工具);PostgreSQL(数据库);

安装过程略(如果感兴趣可以加Ninja的QQ新群:262296156或者2群:560927314)

访问ninja官网实在太慢了,于是我把整个网站抓下来了,已经分享到群里了,需要的可以直接下载

--------------------------------------------------------------------------------------------------

2:直接创建一个Ninja项目官网位置:www.ninjaframework.org/documentation/getting_started/create_your_first_application.html

------------------------------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------------------------------

直接进行maven构建;

1
mvn archetype:generate -DarchetypeGroupId=org.ninjaframework -DarchetypeArtifactId=ninja-servlet-archetype-simple

 解释一下这句话:我们使用maven构建项目,那就用它构建一个ninja原型--maven原型构建;

在你的某个目录下使用git窗口执行上面的代码,项目自动构建完毕(交互部分窝用中文解释一下);

进入项目,安装一下maven依赖包:

1
2
3
cd cmy
mvn clean install     // to generate the compiled classes the first time
mvn ninja:run         // to start Ninja's SuperDevMode 运行项目

构建完毕:

我接手新项目习惯性研究一下包目录结构,那Ninja也有介绍,官方地址http://www.ninjaframework.org/documentation/getting_started/the_anatomy_of_a_ninja_application.html

如果有必要等抽空解释一下目录结构,暂时先放在这里如下:

复制代码
 1 ├── pom.xml                                     // Instructions about dependencies and the build (Maven)
 2 └── src
 3     ├── main
 4     │   ├── java
 5     │   │   ├── META-INF
 6     │   │   │   └── persistence.xml             // Contains informations how to access databases via JPA
 7     │   │   ├── assets                          // Static assets of your application
 8     │   │   │   └── css
 9     │   │   │       └── custom.css
10     │   │   ├── conf 
11     │   │   │   ├── Module.java                 // Dependency injection definitions via Guice (Optional) 
12     │   │   │   ├── Routes.java                 // Contains all routes of your application in one location
13     │   │   │   ├── ServletModule.java          // Integration of arbitrary servlet filters and mappings (Optional)
14     │   │   │   ├── StartupActions.java         // Customization of application startup (Optional)
15     │   │   │   ├── application.conf            // Configuration for test dev and production mode
16     │   │   │   ├── messages.properties         // 18n messages
17     │   │   │   └── messages_de.properties
18     │   │   ├── controllers                     // Controllers will handle the actual request and do something
19     │   │   │   ├── ApiController.java
20     │   │   │   ├── ApplicationController.java
21     │   │   │   ├── ArticleController.java
22     │   │   │   └── LoginLogoutController.java
23     │   │   ├── dao                             // Database access via DAO objects and not in the controller
24     │   │   │   ├── ArticleDao.java
25     │   │   │   ├── SetupDao.java
26     │   │   │   └── UserDao.java
27     │   │   ├── db                              // Database migrations when dealing with RDBMS (Flyway)
28     │   │   │   └── migration
29     │   │   │       ├── V1__.sql
30     │   │   │       └── V2__.sql
31     │   │   ├── ehcache.xml                     // Configuration for ehcache
32     │   │   ├── etc
33     │   │   │   ├── LoggedInUser.java
34     │   │   │   └── LoggedInUserExtractor.java  // Argument extractors for controller methods
35     │   │   ├── filters
36     │   │   │   └── LoggerFilter.java           // Filter to filter the request in the controller
37     │   │   ├── logback.xml                     // Logging configuration via logback / slf4j
38     │   │   ├── models                          // Some models that map to your relational database
39     │   │   │   ├── Article.java
40     │   │   │   ├── ArticleDto.java
41     │   │   │   ├── ArticlesDto.java
42     │   │   │   └── User.java
43     │   │   └── views                           // html views - always map to a controller and a method
44     │   │       ├── ApplicationController
45     │   │       │   ├── index.ftl.html          // Maps to controller "ApplicationController" and method "index"
46     │   │       │   └── setup.ftl.html
47     │   │       ├── ArticleController
48     │   │       │   ├── articleNew.ftl.html
49     │   │       │   └── articleShow.ftl.html
50     │   │       ├── LoginLogoutController
51     │   │       │   ├── login.ftl.html
52     │   │       │   └── logout.ftl.html
53     │   │       ├── layout
54     │   │       │   ├── defaultLayout.ftl.html
55     │   │       │   ├── footer.ftl.html
56     │   │       │   └── header.ftl.html
57     │   │       └── system                      // Error html views. Can be customized to output custom error pages
58     │   │           ├── 403forbidden.ftl.html
59     │   │           └── 404notFound.ftl.html
60     │   ├── resources
61     │   └── webapp
62     │       └── WEB-INF
63     │           └── web.xml                    // Needed for servlet containers to start up Ninja
64     └── test
65         ├── java
66         │   └── controllers                    // Different tests for your application
67         │       ├── ApiControllerDocTest.java
68         │       ├── ApiControllerDocTesterTest.java
69         │       ├── ApiControllerMockTest.java
70         │       ├── ApiControllerTest.java
71         │       ├── ApplicationControllerFluentLeniumTest.java
72         │       ├── ApplicationControllerTest.java
73         │       ├── LoginLogoutControllerTest.java
74         │       └── RoutesTest.java
75         └── resources
76             └── test_for_upload.txt
View Code
复制代码

好了,接下来就开始配置项目了:

我要开发的是一个简单的博客系统,运行在互联网上的项目,因此一个配置或者布局构架等等和业务系统有所区别;

项目分析:

前台:需要文章列表就可以,我希望最好有个主页进入

后台:管理页面(我初步设置两三种权限,系统管理员,博主后台,运营后台)

--------------------------------------------------------------------------

开始配置application.conf 文件:

 

posted @   ldp.im  阅读(1112)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
点击右上角即可分享
微信分享提示