1、Myeclipse中 新建 Dynamic Web Project  

导入jar包

2、配置web.xml

<?xml version="1.0" encoding="UTF-8"?>
<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_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>JFinalDemo</display-name>
<filter>
<filter-name>jfinal</filter-name>
<filter-class>com.jfinal.core.JFinalFilter</filter-class>
<init-param>
<param-name>configClass</param-name>
<param-value>com.demo.common.CommonConfig</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>jfinal</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

3、配置文件config.properties

jdbcUrl = jdbc:mysql://localhost:3306/jfinal?useUnicode=true&characterEncoding=utf-8
user = root
password =
devMode =true

4、配置jfinal启动文件

package com.demo.common;

import com.demo.common.controller.BlogController;

public class CommonConfig extends JFinalConfig {

	@Override
public void configConstant(Constants me) {
loadPropertyFile("config.properties");
me.setDevMode(getPropertyToBoolean("devMode",false));
me.setViewType(ViewType.JSP);
me.setBaseViewPath("/WEB-INF/view");
} @Override
public void configRoute(Routes me) {
me.add("/blog", BlogController.class);
me.add("/hello", HelloController.class);
} @Override
public void configPlugin(Plugins me) {
C3p0Plugin c3p0Plugin = new C3p0Plugin(getProperty("jdbcUrl"), getProperty("user"), getProperty("password"));
me.add(c3p0Plugin);
ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
me.add(arp);
arp.addMapping("blog",Blog.class);
} @Override
public void configInterceptor(Interceptors me) {
// TODO Auto-generated method stub } @Override
public void configHandler(Handlers me) {
// TODO Auto-generated method stub } /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
JFinal.start("WebRoot", 81, "/", 5);
} }

5、控制器

package com.demo.common.controller;

import java.util.Date;

public class BlogController extends Controller {
public void index(){
setAttr("blogs", Blog.me.find("select * from blog"));
render("index.jsp");
}
public void add(){
String dosubmit = getPara("dosbumit");
if(dosubmit==null || dosubmit.length()<=0){
render("add.jsp");
}else{
Blog blog = getModel(Blog.class,"blog");
blog.set("time", new Date());
blog.save();
index();
}
}
public void del(){
Integer id = getParaToInt(0);
if(id==null || id<=0){
renderText("数据异常");
return;
}
Boolean flag = Blog.me.deleteById(id);
if(!flag){
renderText("数据已删除");
return;
}
index();
}
public void update(){
String dosubmit = getPara("dosbumit");
if(dosubmit==null || dosubmit.length()<=0){
Integer id = getParaToInt(0);
if(id==null || id<=0){
renderText("数据异常");
return;
}
setAttr("blog", Blog.me.findById(id));
render("update.jsp");
}else{
Blog blog = getModel(Blog.class,"blog");
blog.update();
index();
}
}
}

6、模型

package com.demo.common.model;

import com.jfinal.plugin.activerecord.Model;

public class Blog extends Model<Blog> {
public final static Blog me = new Blog();
}

7、视图

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>博客列表</title>
<link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page"> </head> <body>
<table class="table table-striped table-bordered">
<caption><a href="/blog/add" class="btn btn-primary">添加博客</a></caption>
<thead>
<tr>
<th>ID</th>
<th>标题</th>
<th>内容</th>
<th>时间</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<c:forEach items="${blogs }" var="b">
<tr>
<td>${b.id }</td>
<td>${b.title }</td>
<td>${b.content }</td>
<td>${b.time }</td>
<td>
<a class="btn btn-primary" href="/blog/del/${b.id }">删除</a>
|
<a class="btn btn-danger" href="/blog/update/${b.id }">编辑</a>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</body>
</html>

代码:

下载

JFinal项目搭建的更多相关文章

  1. 使用Vue+JFinal框架搭建前后端分离系统

    前后端分离作为Web开发的一种方式,现在应用越来越广泛.前端一般比较流行Vue.js框架,后端框架比较多,网上有很多Vue+SpringMVC前后端分离的demo,但是Vue+JFinal框架貌似没有 ...

  2. JFinal 项目 在tomcat下部署

    原文:http://my.oschina.net/jfinal/blog/353062 首先明确一下 JFinal 项目是标准的 java web 项目,其部署方式与普通 java web 项目没有任 ...

  3. Intellij IDEA Java web 项目搭建

    Java web 项目搭建 简介 在上一节java web环境搭建中,我们配置了开发java web项目最基本的环境,现在我们将采用Spring MVC+Spring+Hibernate的架构搭建一个 ...

  4. 项目搭建系列之一:使用Maven搭建SpringMVC项目

    约定电脑都安装了eclipse,且已配置好Maven以及eclipse插件. 1.Eclipse 2.maven 3.Eclipse 需要安装maven插件.url:maven - http://do ...

  5. 初尝 JFinal 项目(一)

    temp1: JFinal项目与JAVA项目类似,有属性方法.操作方法.Sql语句操作.jdbc.配置文件 对比:|| JAVA: Bean / Srv(Server) / SqlMap / jdbc ...

  6. maven项目搭建

    一.Maven简介 Maven是基于Java平台的项目构建(mvn clean install).依赖管理(中央仓库,Nexus)和项目信息管理的项目管理工具. Maven是基于项目对象模型(POM) ...

  7. maven3常用命令、java项目搭建、web项目搭建详细图解

    http://blog.csdn.net/edward0830ly/article/details/8748986 ------------------------------maven3常用命令-- ...

  8. Java web 项目搭建

    Java web 项目搭建 简介 在上一节java web环境搭建中,我们配置了开发java web项目最基本的环境,现在我们将采用Spring MVC+Spring+Hibernate的架构搭建一个 ...

  9. requirejs + vue 项目搭建2

    上篇是年后的项目搭建的,时间比较仓促,感觉有点low 1.gulp-vue 文件对公用js的有依赖,以后别的同事拿去搭其他项目,估计会被喷 2.不支持vue-loader一样写模版语言和es6语法 最 ...

随机推荐

  1. NPAPI命休矣

    NPAPI命休矣,Firebreath命休矣,NPPluginProxy命休矣.以后该更多专注LLVM.Emscripten.Websocket和NativeClient之类的技术啦.

  2. Bootstrap Multiselect 设置 option

    $.ajax({ type: 'post', url: "helper/ajax_search.php", data: {models: decodeURIComponent(br ...

  3. Swift-7-闭包

    // Playground - noun: a place where people can play import UIKit // swift 中闭包与C和OC中的blocks比较相似 // 1. ...

  4. 一个共通的viewModel搞定所有的分页查询一览及数据导出(easyui + knockoutjs + mvc4.0)

    前言 大家看标题就明白了我想写什么了,在做企业信息化系统中可能大家写的最多的一种页面就是查询页面了.其实每个查询页面,除了条件不太一样,数据不太一样,其它的其实都差不多.所以我就想提取一些共通的东西出 ...

  5. Photoshop脚本之eps转换成jpg

    function saveEPS( doc, saveFile ) { var saveOptions = new JPEGSaveOptions( ); saveOptions.encoding = ...

  6. Sql server 打不开了,无法识别的配置节 system.serviceModel 解决方案

    异常描述: System.Configuration.ConfigurationErrorsException: 配置系统未能初始化 ---> System.Configuration.Conf ...

  7. 【BZOJ】3203: [Sdoi2013]保护出题人(几何+三分+特殊的技巧)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3203 wa无数次QAQ,犯sb错....一是数组没有引用...二是输出转成了int(越界了sad). ...

  8. 终于找到了最新的Chemdarw注册码

    随着中国人对知识产权的保护意识提升,正版软件越来越流行,只有一小部分人还在寻找Chemdarw破解版.最新的ChemDraw 15正式版本已经强势来袭,在获取软件安装包之后需要有效的注册码才能激活软件 ...

  9. C# 各版本的新特性

    http://www.cnblogs.com/JeffreySun/archive/2012/11/14/2770211.html

  10. 自定义字体TextView

    /** * 备注: * 作者:王莹 * 时间:2017/5/4. * ~_~想睡觉了!! * (-o-)~zZ我想睡啦- * π_π?打瞌睡 */ public class FontsTextView ...