1.导jar包
1 <dependency> 2 <groupId>com.jfinal</groupId> 3 <artifactId>jfinal-undertow</artifactId> 4 <version>2.0</version> 5 </dependency> 6 7 <dependency> 8 <groupId>com.jfinal</groupId> 9 <artifactId>jfinal</artifactId> 10 <version>4.8</version> 11 </dependency>
2.DemoConfig
1 public class DemoConfig extends JFinalConfig { 2 @Override 3 public void onStart() { 4 System.out.println("我是开始"); 5 } 6 7 @Override 8 public void configConstant(Constants constants) { 9 constants.setDevMode(true); 10 } 11 12 @Override 13 public void configRoute(Routes routes) { 14 routes.add("/hello",HelloController.class); 15 } 16 17 @Override 18 public void onStop() { 19 System.out.println("我是结束"); 20 } 21 22 @Override 23 public void configEngine(Engine engine) { 24 } 25 26 @Override 27 public void configPlugin(Plugins plugins) { 28 } 29 30 @Override 31 public void configInterceptor(Interceptors interceptors) { 32 } 33 34 @Override 35 public void configHandler(Handlers handlers) { 36 } 37 }
3.HelloController
1 public class HelloController extends Controller { 2 public void index() 3 { 4 renderText("Hello JFinal World."); 5 sayHelo(); 6 } 7 }
4.start
1 public class Start { 2 public static void main(String[] args) { 3 UndertowServer.start(DemoConfig.class,8009,true); 4 } 5 }
来源:https://www.cnblogs.com/Tsugar/p/12460126.html