JFinal快速上手及注意事项

官方手册虽然写的很详细但是忽略的很多小的细节方面,不看源码,网络资料又少,很多新手找不到解决办法。所以养成出了问题,多看源码的习惯

部署helloJFinal

  • 项目结构

JFinal快速上手及注意事项_第1张图片

    -

  • 相关代码
  • `package demo;

import com.jfinal.core.Controller;

public class myControll extends Controller{

public void index() {
      this.renderText("hello jfinal");
}

}
`


package demo;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.template.Engine;

public class projectConfig extends JFinalConfig{

    @Override
    public void configConstant(Constants me) {
        // TODO Auto-generated method stub
        me.setDevMode(true);
    }

    @Override
    public void configRoute(Routes me) {
        // TODO Auto-generated method stub
        me.add("/hello", myControll.class);
    }


    @Override
    public void configEngine(Engine me) {
        // TODO Auto-generated method stub

    }

    @Override
    public void configHandler(Handlers me) {
        // TODO Auto-generated method stub

    }

    @Override
    public void configInterceptor(Interceptors me) {
        // TODO Auto-generated method stub

    }

    @Override
    public void configPlugin(Plugins me) {
        // TODO Auto-generated method stub

    }


}

-webxml


<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <display-name>JFinalDemodisplay-name>
    <welcome-file-list>
        <welcome-file>index.htmlwelcome-file>
        <welcome-file>index.htmwelcome-file>
        <welcome-file>index.jspwelcome-file>
        <welcome-file>default.htmlwelcome-file>
        <welcome-file>default.htmwelcome-file>
        <welcome-file>default.jspwelcome-file>
    welcome-file-list>
    <filter>
        <filter-name>jfinalfilter-name>
        <filter-class>com.jfinal.core.JFinalFilterfilter-class>
        <init-param>
                  
            <param-name>configClassparam-name>
            <param-value>demo.projectConfigparam-value>
        init-param>
    filter>
    <filter-mapping>
        <filter-name>jfinalfilter-name>
        <url-pattern>/*url-pattern>
    filter-mapping>
web-app>

关于

JFinal.start("WebContent", 80, "/",5);

官方文件写的是 Jfinal.start(“src/main/webapp”,80,”/”,5);
其实这个路径写了 “/”就代表采用相对路径 而 默认执行index()方法 ,如果 全部写出来,即为 http://localhost/hello/index 其他方法修改 index为你想要的方法即可

你可能感兴趣的:(Jfinal)