基于JFinal完成一个简单的学生信息管理系统
作者:互联网
一、界面如下
二、操作步骤
点击进入:https://jfinal.com/project/1
滑到最下面,点击JFinal 4.9.01 demo for maven下载
然后把这个压缩包解压,导入到Ecplise中
然后在Navicat里新建一个数据库,命名为blog
输入查询语句
1 CREATE TABLE `blog` ( 2 `id` int(11) NOT NULL auto_increment, 3 `title` varchar(200) NOT NULL, 4 `content` mediumtext NOT NULL, 5 PRIMARY KEY (`id`) 6 ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 7 8 9 INSERT INTO `blog` VALUES ('1', 'JFinal Demo Title here', 'JFinal Demo Content here'); 10 INSERT INTO `blog` VALUES ('2', 'test 1', 'test 1'); 11 INSERT INTO `blog` VALUES ('3', 'test 2', 'test 2'); 12 INSERT INTO `blog` VALUES ('4', 'test 3', 'test 3'); 13 INSERT INTO `blog` VALUES ('5', 'test 4', 'test 4');
打开blog表
回到Eclipse,右击DemoConfig,选择Debug As->Java Application
运行成功!
在浏览器输入localhost,出现界面
然后就可以开始修改相关代码了
我所修改的部分为:
demo-config-dev.txt
1 # config 2 jdbcUrl = jdbc:mysql://localhost/blog?characterEncoding=utf8&useSSL=false&zeroDateTimeBehavior=convertToNull 3 user = root 4 password =ym123 5 devMode = true
BaseBlog.java
1 package com.demo.common.model.base; 2 3 import com.jfinal.plugin.activerecord.Model; 4 import com.jfinal.plugin.activerecord.IBean; 5 6 /** 7 * Generated by JFinal, do not modify this file. 8 */ 9 @SuppressWarnings({"serial", "unchecked"}) 10 public abstract class BaseBlog<M extends BaseBlog<M>> extends Model<M> implements IBean { 11 12 public M setId(java.lang.Integer id) { 13 set("id", id); 14 return (M)this; 15 } 16 17 public java.lang.Integer getId() { 18 return getInt("id"); 19 } 20 21 public M setS_number(java.lang.String s_number) { 22 set("s_number", s_number); 23 return (M)this; 24 } 25 26 public java.lang.String getS_number() { 27 return getStr("s_number"); 28 } 29 30 public M setS_name(java.lang.String s_name) { 31 set("s_name", s_name); 32 return (M)this; 33 } 34 35 public java.lang.String getS_name() { 36 return getStr("s_name"); 37 } 38 39 public M setS_grade(java.lang.String s_grade) { 40 set("s_grade", s_grade); 41 return (M)this; 42 } 43 44 public java.lang.String getS_grade() { 45 return getStr("s_grade"); 46 } 47 48 public M setS_phone(java.lang.String s_phone) { 49 set("s_phone", s_phone); 50 return (M)this; 51 } 52 53 public java.lang.String getS_phone() { 54 return getStr("s_phone"); 55 } 56 57 }
BlogValidator.java
1 package com.demo.blog; 2 3 import com.demo.common.model.Blog; 4 import com.jfinal.core.Controller; 5 import com.jfinal.validate.Validator; 6 7 /** 8 * 本 demo 仅表达最为粗浅的 jfinal 用法,更为有价值的实用的企业级用法 9 * 详见 JFinal 俱乐部: http://jfinal.com/club 10 * 11 * BlogValidator. 12 */ 13 public class BlogValidator extends Validator { 14 15 protected void validate(Controller controller) { 16 validateRequiredString("blog.s_number", "titleMsg1", "请输入学号!"); 17 validateRequiredString("blog.s_name", "titleMsg2", "请输入姓名!"); 18 validateRequiredString("blog.s_grade", "titleMsg3", "请输入班级!"); 19 validateRequiredString("blog.s_phone", "titleMsg4", "请输入电话!"); 20 } 21 22 protected void handleError(Controller controller) { 23 controller.keepModel(Blog.class); 24 25 String actionKey = getActionKey(); 26 if (actionKey.equals("/blog/save")) 27 controller.render("add.html"); 28 else if (actionKey.equals("/blog/update")) 29 controller.render("edit.html"); 30 } 31 }
index.html
1 #@layout() 2 #define main() 3 <h1>学生管理系统首页</h1> 4 <div class="table_box"> 5 <h1>欢迎来到学生管理系统!</h1> 6 本系统采用 JFinal Template 作为视图文件。 7 点击<a href="/blog"><b>此处</b></a>进入学生管理系统。 8 <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> 9 <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> 10 </div> 11 #end
_layout.html
1 #define layout() 2 <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 3 <html xml:lang="zh-CN" xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN"> 4 <head> 5 <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> 6 <link href="/assets/css/manage.css" media="screen" rel="stylesheet" type="text/css" /> 7 <script src="/assets/js/jquery-1.4.4.min.js" type="text/javascript" ></script> 8 </head> 9 <body> 10 <div class="manage_container"> 11 <div class="manage_head"> 12 <div class="manage_logo"> 13 <a href="http://www.jfinal.com" target="_blank">JFinal web framework</a> 14 </div> 15 <div id="nav"> 16 <ul> 17 <li><a href="/"><b>首页</b></a></li> 18 <li><a href="/blog"><b>学生信息管理</b></a></li> 19 </ul> 20 </div> 21 </div> 22 <div class="main"> 23 #@main() 24 </div> 25 </div> 26 </body> 27 </html> 28 #end
edit.html
1 #@layout() 2 #define main() 3 <h1>学生信息管理 ---> 修改学生信息 4 </h1> 5 <div class="form_box"> 6 <form action="/blog/update" method="post"> 7 #include("_form.html") 8 </form> 9 </div> 10 #end
blog.html
1 #@layout() 2 #define main() 3 <h1>学生信息管理 4 <a href="/blog/add">新增学生信息</a> 5 </h1> 6 <div class="table_box"> 7 <table class="list"> 8 <tbody> 9 <tr> 10 <th width="10%">id</th> 11 <th width="20%">学号</th> 12 <th width="20%">姓名</th> 13 <th width="20%">班级</th> 14 <th width="20%">电话</th> 15 <th width="10%">操作</th> 16 </tr> 17 18 #for(x : blogPage.getList()) 19 <tr> 20 <td style="text-align:left;">#(x.id)</td> 21 <td style="text-align:left;">#(x.s_number)</td> 22 <td style="text-align:left;">#(x.s_name)</td> 23 <td style="text-align:left;">#(x.s_grade)</td> 24 <td style="text-align:left;">#(x.s_phone)</td> 25 <td style="text-align:left;"> 26 <a href="/blog/delete/#(x.id)">删除</a> 27 <a href="/blog/edit/#(x.id)">修改</a> 28 </td> 29 </tr> 30 #end 31 </tbody> 32 </table> 33 #@paginate(blogPage.pageNumber, blogPage.totalPage, "/blog/") 34 </div> 35 #end
add.html
1 #@layout() 2 #define main() 3 <h1>学生信息管理 ---> 新增学生信息 4 </h1> 5 <div class="form_box"> 6 <form action="/blog/save" method="post"> 7 #include("_form.html") 8 </form> 9 </div> 10 #end
_form.html
1 <fieldset class="solid"> 2 <legend>新增学生信息</legend> 3 <input type="hidden" name="blog.id" value="#(blog.id??)" /> 4 <div> 5 <label>学号</label> <input type="text" name="blog.s_number" 6 value="#(blog.s_number??)" />#(titleMsg1) 7 </div> 8 <div> 9 <label>姓名</label> <input type="text" name="blog.s_name" 10 value="#(blog.s_name??)" />#(titleMsg2) 11 </div> 12 <div> 13 <label>班级</label> <input type="text" name="blog.s_grade" 14 value="#(blog.s_grade??)" />#(titleMsg3) 15 </div> 16 <div> 17 <label>电话</label> <input type="text" name="blog.s_phone" 18 value="#(blog.s_phone??)" />#(titleMsg4) 19 </div> 20 <div> 21 <label> </label> <input value="提交" type="submit"> 22 </div> 23 </fieldset>
重新设计一下数据库
以下为数据库语句:
1 SET FOREIGN_KEY_CHECKS=0; 2 3 -- ---------------------------- 4 -- Table structure for `blog` 5 -- ---------------------------- 6 DROP TABLE IF EXISTS `blog`; 7 CREATE TABLE `blog` ( 8 `id` int(11) NOT NULL AUTO_INCREMENT, 9 `s_number` varchar(200) NOT NULL, 10 `s_name` varchar(200) NOT NULL, 11 `s_grade` varchar(200) NOT NULL, 12 `s_phone` varchar(200) NOT NULL, 13 PRIMARY KEY (`id`) 14 ) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8; 15 16 -- ---------------------------- 17 -- Records of blog 18 -- ---------------------------- 19 INSERT INTO `blog` VALUES ('1', '20210000', '小猫', '1班', '10011'); 20 INSERT INTO `blog` VALUES ('2', '20210001', '小山羊', '2班', '10012'); 21 INSERT INTO `blog` VALUES ('3', '20210002', '移动', '3班', '10086'); 22 INSERT INTO `blog` VALUES ('4', '20210003', '联通', '4班', '10010');
然后重新运行一下右击DemoConfig,选择Debug As->Java Application即可。
标签:lang,11,基于,java,id,blog,JFinal,信息管理系统,public 来源: https://www.cnblogs.com/miao-com/p/15500168.html