一、创建项目:
注意:点击完成后需要等待一段时间,让idea根据webapp模板创建项目;
二、相关配置
1、pom.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>vrapp_jfianl</groupId>
<artifactId>vrapp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>vrapp Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<!--指定将要引入的jar的版本号-->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<!--集中声明依赖-->
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
<dependency>
<!--jfinal依赖-->
<groupId>com.jfinal</groupId>
<artifactId>jfinal</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>com.jfinal</groupId>
<artifactId>cos</artifactId>
<version>2017.5</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>vrapp</finalName>
</build>
</project>
2、创建项目结构目录
创建java目录,并将java目录设置为source root,这样IDEA才会把该目录下的.java文件当做java源文件来处理
3、创建VrAppConfig类(在config下创建)
按Alt+Insert快速创建config
该类要继承com.jfinal.config.JFinalConfi类,并重写五个方法。按Alt+Insert快捷键可快速生成代码
package com.config;
import com.controller.UserControllor;
import com.jfinal.config.*;
import com.jfinal.template.Engine;
public class VrAppConfig extends JFinalConfig {
@Override
public void configConstant(Constants constants) {
//设置jfinal的开发模式
constants.setDevMode(true);
}
@Override
public void configRoute(Routes routes) {
//配置url
//第一个参数是访问controller的key
//第二个参数是要映射的controller
// 第三个参数为该Controller的视图存放路径
// 第三个参数省略时默认与第一个参数值相同,在此即为 "/"路径
routes.add("/", UserControllor.class);
}
@Override
public void configEngine(Engine engine) {
}
@Override
public void configPlugin(Plugins plugins) {
}
@Override
public void configInterceptor(Interceptors interceptors) {
}
@Override
public void configHandler(Handlers handlers) {
}
}
4、创建UserController类(在controller下)
--------注:当定义完controller后一定要记得在config类中的configRoute里面配置url,由于我上面已经配置了这里就不在赘述
5、配置jetty启动:
①、在VrAppConfig添加一个main启动集成的jetty:
public static void main(String[] args) {
JFinal.start("src/main/webapp", 8080, "/", 5);
}
②、在pom.xml中声明依赖包:
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-dyvmsapi</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>com.jfinal</groupId>
<artifactId>jetty-server</artifactId>
<version>2018.11</version>
<scope>compile</scope>
</dependency>
注意:pom.xml配置全部代码如下
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>vrapp_jfianl</groupId>
<artifactId>vrapp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>vrapp Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<!--指定将要引入的jar的版本号-->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<!--集中声明依赖-->
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
<dependency>
<!--jfinal依赖-->
<groupId>com.jfinal</groupId>
<artifactId>jfinal</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>com.jfinal</groupId>
<artifactId>cos</artifactId>
<version>2017.5</version>
</dependency>
<!--配置jetty启动-->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-dyvmsapi</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>com.jfinal</groupId>
<artifactId>jetty-server</artifactId>
<version>2018.11</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>vrapp</finalName>
</build>
</project>
注意:config配置的代码:
package com.config;
import com.controller.UserControllor;
import com.jfinal.config.*;
import com.jfinal.core.JFinal;
import com.jfinal.template.Engine;
public class VrAppConfig extends JFinalConfig {
@Override
public void configConstant(Constants constants) {
//设置jfinal的开发模式
constants.setDevMode(true);
}
@Override
public void configRoute(Routes routes) {
//配置url
//第一个参数是访问controller的key
//第二个参数是要映射的controller
// 第三个参数为该Controller的视图存放路径
// 第三个参数省略时默认与第一个参数值相同,在此即为 "/"路径
routes.add("/", UserControllor.class);
}
@Override
public void configEngine(Engine engine) {
}
@Override
public void configPlugin(Plugins plugins) {
}
@Override
public void configInterceptor(Interceptors interceptors) {
}
@Override
public void configHandler(Handlers handlers) {
}
public static void main(String[] args) {
JFinal.start("src/main/webapp", 8080, "/", 5);
}
}
6、修改web.xml文件:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<filter>
<filter-name>jfnal</filter-name>
<filter-class>com.jfinal.core.JFinalFilter</filter-class>
<init-param>
<param-name>configClass</param-name>
<!--注意此处的路径配置,必须正确!-->
<param-value>com.config.VrAppConfig</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>jfnal</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
7、启动项目:
在config目录下配置的启动点击右键,运行代码;打开浏览器url中输入:http://localhost:8080
标签:Override,config,void,IDEA,maven,jfinal,JFinal,com,public From: https://www.cnblogs.com/yansans/p/17929342.html