- 浏览: 136635 次
- 性别:
- 来自: 武汉
文章分类
最新评论
-
Dear疼你:
郑云飞 写道你好,请问,按照你的代码,为什么Android手机 ...
微信公众号发送模板消息 -
di1984HIT:
学习了。。。
微信公众号发送模板消息 -
zxs6587:
没有开启开发模式可以使用此接口发送模板消息吗????急求!!
微信公众号发送模板消息 -
郑云飞:
你好,请问,按照你的代码,为什么Android手机可以收到发送 ...
微信公众号发送模板消息 -
fsh430623:
有办法吗,我觉得扫描过后要是直接知道是哪个的二维码,多好
微信扫描公众号二维码实现登陆
基于jfinal的投票系统
1.数据库设计
投票主题表:
投票主题条目:
投票条目选项表:
投票管理端代码
浏览并投票的代码
1.数据库设计
投票主题表:
-- Create table create table VOTE_THEME ( ID VARCHAR2(32), NAME VARCHAR2(200), STARTDATE VARCHAR2(10), ENDDATE VARCHAR2(20), SFNM VARCHAR2(1) default '0', YXBJ VARCHAR2(1) default '1', SCRQ DATE default sysdate, HEADPIC VARCHAR2(200), FOOTPIC VARCHAR2(200) ) ; -- Add comments to the table comment on table VOTE_THEME is '投票主题'; -- Add comments to the columns comment on column VOTE_THEME.NAME is '主题'; comment on column VOTE_THEME.STARTDATE is '开始时间'; comment on column VOTE_THEME.ENDDATE is '截止时间'; comment on column VOTE_THEME.SFNM is '是否匿名'; comment on column VOTE_THEME.YXBJ is '有效标记'; comment on column VOTE_THEME.SCRQ is '生成日期'; comment on column VOTE_THEME.HEADPIC is '主题图片'; comment on column VOTE_THEME.FOOTPIC is '底部图片';
投票主题条目:
create table VOTE_THEME_ITEM ( ID VARCHAR2(32), NAME VARCHAR2(200), TYPE VARCHAR2(1), THEME_ID VARCHAR2(32), SCRQ DATE default sysdate, CNUM NUMBER default 1 ) ; -- Add comments to the table comment on table VOTE_THEME_ITEM is '投票项目'; -- Add comments to the columns comment on column VOTE_THEME_ITEM.TYPE is '1:单选,2:多选;3:手工输入'; comment on column VOTE_THEME_ITEM.CNUM is '可以选择的个数';
投票条目选项表:
-- Create table create table VOTE_THEME_ITEM_ANSWER ( ID VARCHAR2(32), ITEM_ID VARCHAR2(32), NAME VARCHAR2(200), COMMS CLOB, IMAGE_PATH VARCHAR2(200), FLV_PATH VARCHAR2(200), DEPTNAME VARCHAR2(50), THEME_ID VARCHAR2(32), ONUM NUMBER, CNUM NUMBER, ZGH VARCHAR2(20) ) ; -- Add comments to the table comment on table VOTE_THEME_ITEM_ANSWER is '投票题目选项';
投票管理端代码
package cn.edu.jxut.vote.controller; import java.io.File; import java.util.List; import net.loyin.jFinal.render.excel.ExcelRender; import org.apache.commons.lang.StringUtils; import cn.edu.jxut.common.config.GlobalConstants; import cn.edu.jxut.common.config.PermInterceptor; import cn.edu.jxut.common.controller.BaseController; import cn.edu.jxut.common.model.LoginUser; import cn.edu.jxut.vote.model.Theme; import cn.edu.jxut.vote.model.ThemeItem; import cn.edu.jxut.vote.model.ThemeItemAnswer; import com.jfinal.aop.Before; import com.jfinal.core.ActionKey; import com.jfinal.plugin.activerecord.Db; import com.jfinal.plugin.activerecord.Page; import com.jfinal.plugin.activerecord.Record; import com.jfinal.upload.UploadFile; @Before(PermInterceptor.class) public class VoteManagerController extends BaseController{ @ActionKey("/vote") public void index() { LoginUser u = (LoginUser)getSessionAttr("LoginUser"); setAttr("root", this.getRequest().getContextPath()); Theme theme = this.getModel(Theme.class); Page<Theme> p = Theme.dao.paginateByExample(theme, "yxbj = '1' and to_date(enddate,'yyyy-MM-dd') >= sysdate ", pageNumber, pageSize, ""); setAttr("page",p); render("/WEB-INF/vote/index.html"); } @ActionKey("/vote/add") public void toAddVote() { setAttr("root", this.getRequest().getContextPath()); render("/WEB-INF/vote/add.html"); } @ActionKey("/vote/detail") public void detail() { setAttr("root", this.getRequest().getContextPath()); String id = getPara("id"); Theme theme = Theme.dao.findById(id); List<ThemeItem> items = theme.getItems(); setAttr("item",items.get(0)); setAttr("theme",theme); render("/WEB-INF/vote/detail.html"); } @ActionKey("/vote/export") public void exportVote(){ String id = getPara("id"); String sql = "select t.id,t.name,i.name as itemname,a.name as answer,(select count(distinct user_id) from vote_user_answer a1" + " where a1.theme_id = t.id and a1.answer_id = a.id) as answercount" + " from vote_theme t, vote_theme_item i, vote_theme_item_answer a where t.id = i.theme_id" + " and i.id = a.item_id and i.theme_id = t.id and t.id = ?"; String[] col = {"投票名称","选项名称","得票数"}; String[] col1 = {"name","answer","answercount"}; List<Record> list = Db.find(sql,new Object[]{id}); this.render(new ExcelRender("投票结果.xls",col,col1,list)); } @ActionKey("/vote/save") public void voteSave() { UploadFile headpic = getFile("headpic"); UploadFile footpic = getFile("footpic"); Theme theme = this.getModel(Theme.class); ThemeItem themeItem = this.getModel(ThemeItem.class); themeItem.set("name", theme.getStr("name")); boolean update = true; if(StringUtils.isEmpty(theme.getStr("id"))){ update = false; theme.genId(); } File f = new File(GlobalConstants.filepath+File.separator+theme.getStr("id")+File.separator); System.out.println("111+++++++++++++++++++++++="+f.getAbsolutePath()); if(!f.exists()){ f.mkdirs(); } System.out.println("222+++++++++++++++++++++++="+f.getAbsolutePath()); if(headpic!=null){ File uploadFile = headpic.getFile(); uploadFile.renameTo(new File(f.getAbsolutePath()+File.separator+headpic.getFileName())); System.out.println("+++++++++++++++++++++++++++"+new File(f.getAbsolutePath()+File.separator+headpic.getFileName()).getAbsolutePath()); theme.set("headpic", ("upload"+File.separator+theme.getStr("id")+File.separator+headpic.getFileName()).replace("\\", "/")); } if(footpic!=null){ File uploadFile2 = footpic.getFile(); uploadFile2.renameTo(new File(f.getAbsolutePath()+File.separator+footpic.getFileName())); theme.set("footpic", ("upload"+File.separator+theme.getStr("id")+File.separator+footpic.getFileName()).replace("\\", "/")); } if(update){ theme.update(); themeItem.set("theme_id", theme.getStr("id")); themeItem.update(); setAttr("successMessage","修改成功!"); }else{ theme.genId(); theme.save(); themeItem.set("theme_id", theme.getStr("id")); themeItem.genId(); themeItem.save(); setAttr("successMessage","保存成功!"); } render("/WEB-INF/vote/add.html"); } @ActionKey("/vote/update") public void toUpdateVode() { LoginUser u = (LoginUser)getSessionAttr("LoginUser"); setAttr("root", this.getRequest().getContextPath()); String id = getPara("id"); Theme theme = Theme.dao.findById(id); List<ThemeItem> items = theme.getItems(); setAttr("item",items.get(0)); setAttr("theme",theme); render("/WEB-INF/vote/edit.html"); } @ActionKey("/vote/delete") public void deleteVote() { LoginUser u = (LoginUser)getSessionAttr("LoginUser"); setAttr("root", this.getRequest().getContextPath()); } @ActionKey("/vote/item/add") public void toItemAdd() { LoginUser u = (LoginUser)getSessionAttr("LoginUser"); setAttr("root", this.getRequest().getContextPath()); } @ActionKey("/vote/item/update") public void toItemUpdate() { LoginUser u = (LoginUser)getSessionAttr("LoginUser"); setAttr("root", this.getRequest().getContextPath()); } @ActionKey("/vote/item/delete") public void deleteItem() { } @ActionKey("/vote/addAnswer") public void toAddAnswer() { setAttr("themeId",getPara("id")); Theme theme = Theme.dao.findById(getPara("id")); ThemeItem item = ThemeItem.dao.findFirst("select * from vote_theme_item where theme_id = ?",new Object[]{theme.get("id")}); setAttr("item_id",item.get("id")); render("/WEB-INF/vote/answer/add.html"); } @ActionKey("/vote/answer/update") public void toUpdateAnswer() { LoginUser u = (LoginUser)getSessionAttr("LoginUser"); ThemeItemAnswer answer = ThemeItemAnswer.dao.findById(getPara("id")); setAttr("answer",answer); render("/WEB-INF/vote/answer/edit.html"); } @ActionKey("/vote/answer/save") public void saveAnswer() { UploadFile image = this.getFile("image"); UploadFile flv = this.getFile("flv"); ThemeItemAnswer answer = this.getModel(ThemeItemAnswer.class); boolean update = true; if(StringUtils.isEmpty(answer.getStr("id"))){ update = false; answer.genId(); } File f = new File(GlobalConstants.filepath+File.separator+answer.getStr("id")+File.separator); if(!f.exists()){ f.mkdirs(); } if(image!=null){ File uploadFile = image.getFile(); uploadFile.renameTo(new File(f.getAbsolutePath()+File.separator+image.getFileName())); answer.set("image_path", ("upload"+File.separator+answer.getStr("id")+File.separator+image.getFileName()).replace("\\", "/")); } if(flv!=null){ File uploadFile2 = flv.getFile(); uploadFile2.renameTo(new File(f.getAbsolutePath()+File.separator+flv.getFileName())); answer.set("flv_path", ("upload"+File.separator+answer.getStr("id")+File.separator+flv.getFileName()).replace("\\", "/")); } setAttr("root", this.getRequest().getContextPath()); if(update){ answer.update(); }else{ answer.save(); } setAttr("successMessage","保存成功!"); setAttr("themeId",answer.getStr("theme_id")); setAttr("item_id",answer.getStr("item_id")); render("/WEB-INF/vote/answer/add.html"); } @ActionKey("/vote/answer/delete") public void toDeleteAnswer() { LoginUser u = (LoginUser)getSessionAttr("LoginUser"); String id = getPara("id"); ThemeItemAnswer answer = ThemeItemAnswer.dao.findById(id); ThemeItem item = answer.getItem(); Theme theme = item.getTheme(); ThemeItemAnswer.dao.deleteById(id); setAttr("successMessage","选项删除成功!"); this.redirect("/vote/detail?id="+theme.getStr("id")); } }
浏览并投票的代码
package cn.edu.jxut.vote.controller; import java.io.File; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import org.apache.commons.lang.StringUtils; import cn.edu.jxut.common.controller.BaseController; import cn.edu.jxut.common.model.LoginUser; import cn.edu.jxut.vote.model.Theme; import cn.edu.jxut.vote.model.ThemeItem; import cn.edu.jxut.vote.model.ThemeItemAnswer; import cn.edu.jxut.vote.model.VoteUserAnswer; import com.jfinal.aop.ClearInterceptor; import com.jfinal.aop.ClearLayer; import com.jfinal.core.ActionKey; import com.jfinal.plugin.activerecord.Db; import com.jfinal.plugin.activerecord.Page; public class VoteViewController extends BaseController{ @ActionKey("/vote/view") @ClearInterceptor(ClearLayer.ALL) public void index() { setAttr("root", this.getRequest().getContextPath()); String id = getPara("id"); Theme theme = Theme.dao.findById(id); ThemeItem item = theme.getItems().get(0); ThemeItemAnswer answer = new ThemeItemAnswer(); answer.set("theme_id", id); answer.set("item_id", item.get("id")); String name = getPara("name"); if(StringUtils.isNotEmpty(name)){ if("请输入教师姓名".equals(name)){ name=""; } }else{ name = ""; } Page<ThemeItemAnswer> p = ThemeItemAnswer.dao.paginateByExample(answer, "name like '%"+name+"%'", this.getPageNumber(), this.getPageSize(), "cnum desc,onum"); setAttr("page",p); setAttr("theme",theme); setAttr("item",item); String sql = "select count(*) from vote_user_answer where user_id = ? and item_id = ?"; LoginUser u = (LoginUser)getSessionAttr("LoginUser"); if(u!=null){ int con = Db.queryInt(sql,new Object[]{u.get("user_id"),item.get("id")}); setAttr("cnum",con); } if("1".equals(getPara("success"))){ setAttr("successMessage","投票成功!"); }else if("0".equals(getPara("success"))){ setAttr("errorMessage","您已经投过一次了!"); }else if("-1".equals(getPara("success"))){ setAttr("errorMessage","您没有剩余的投票机会了!"); }else if("-2".equals(getPara("success"))){ setAttr("errorMessage","当前投票已经截止!"); }else if("-3".equals(getPara("success"))){ setAttr("errorMessage","当前投票还没有开始!"); } render("/WEB-INF/voteview/view.html"); } @ActionKey("/vote/viewAll") @ClearInterceptor(ClearLayer.ALL) public void viewAll() { setAttr("root", this.getRequest().getContextPath()); Theme theme = this.getModel(Theme.class); Page<Theme> p = Theme.dao.paginateByExample(theme, "yxbj = '1' and enddate >= to_char(sysdate,'yyyy-MM-dd') ", pageNumber, pageSize, ""); setAttr("page",p); render("/WEB-INF/voteview/viewAll.html"); } @ActionKey("/vote/view/detail") @ClearInterceptor(ClearLayer.ALL) public void detail() { setAttr("root", this.getRequest().getContextPath()); String id = getPara("id"); ThemeItemAnswer answer = ThemeItemAnswer.dao.findById(id); ThemeItem item = answer.getItem(); Theme theme = item.getTheme(); setAttr("answer",answer); setAttr("theme",theme); String sql = "select count(*) from vote_user_answer where user_id = ? and item_id = ?"; LoginUser u = (LoginUser)getSessionAttr("LoginUser"); if(u!=null){ int con = Db.queryInt(sql,new Object[]{u.get("user_id"),item.get("id")}); setAttr("cnum",con); } render("/WEB-INF/voteview/show.html"); } @ActionKey("/vote/vote") @ClearInterceptor(ClearLayer.ALL) public void vote(){ LoginUser u = (LoginUser)getSessionAttr("LoginUser"); String id = getPara("id"); ThemeItemAnswer answer = ThemeItemAnswer.dao.findById(id); ThemeItem item = answer.getItem(); Theme theme = item.getTheme(); if("1".equals(theme.getStr("sfnm"))){ u=new LoginUser(); u.set("user_id", this.getRequest().getRemoteAddr()); }else{ if(u==null){ this.redirect("/main?redirect=/vote/view?id="+theme.getStr("id")); return; } } String startDate = theme.getStr("startDate"); String endDate = theme.getStr("endDate"); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); try { Date start = df.parse(startDate); Date end = df.parse(endDate); if(df.parse(df.format(new Date())).compareTo(end)>0){ this.redirect("/vote/view?success=-2&id="+theme.getStr("id")); return; } if(new Date().compareTo(start)<0){ this.redirect("/vote/view?success=-3&id="+theme.getStr("id")); return; } } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } int cnum = item.getBigDecimal("cnum").intValue(); String sql = "select count(*) from vote_user_answer where user_id = ? and item_id = ?"; int con = Db.queryInt(sql,new Object[]{u.get("user_id"),item.get("id")}); if(con>=cnum){ this.redirect("/vote/view?success=-1&id="+theme.getStr("id")); return; } String sql2 = "select count(*) from vote_user_answer where user_id = ? and answer_id = ?"; int con2 = Db.queryInt(sql2,new Object[]{u.get("user_id"),answer.get("id")}); if(con2>0){ this.redirect("/vote/view?success=0&id="+theme.getStr("id")); return; } VoteUserAnswer userAnswer = new VoteUserAnswer(); userAnswer.genId(); userAnswer.set("answer_id", id); userAnswer.set("user_id", u.get("user_id")); userAnswer.set("item_id", item.get("id")); userAnswer.set("theme_id", theme.get("id")); userAnswer.save(); this.redirect("/vote/view?success=1&id="+theme.getStr("id")); } }
相关推荐
本篇文章将详细探讨如何在JFinal框架下实现登录后的在线信息集合功能。 首先,我们需要理解登录系统的基本构成。登录系统通常包括用户验证、会话管理以及权限控制等部分。在JFinal中,我们可以利用其内置的...
本示例“JFinal实现 Demo - 导出Excel.rar”旨在演示如何利用JFinal框架来实现Excel文件的导出功能。Excel作为一种广泛使用的数据处理和分析工具,其与Web应用的集成在数据报告、数据交换等方面具有重要意义。 首先...
Java图书管理系统基于JFinal框架实现,是一套完整的用于图书管理的软件系统,涵盖了图书分类、出版社管理、图书信息管理以及图书借阅与归还等核心功能。系统还具备图书逾期提醒功能,并能通过电子邮件发送通知,提高...
JFinal实现的数据同步中间件可能会通过监听数据库的变更事件,如触发器、日志分析或者binlog解析,来捕捉数据的变化,并将这些变化传播到其他系统或数据库。此外,数据同步中间件还需要处理并发控制、事务一致性、...
**基于JFinal框架的个人博客...总结,基于JFinal的个人博客系统充分利用了该框架的优势,实现了高效且功能完善的个人表达平台。通过不断迭代和优化,可以满足不同用户的需求,成为他们展示自我、学习交流的理想空间。
本程序是基于JFinal 1.5做的一个小站,代码没有使用什么特别的东西,用到了@JFinal作者提到的FakeStaticHandler来伪静态,其他的没什么。小站刚开 始使用Lucene来作为全文检索,后面又改成了SQL like匹配,估计要被...
Java基于JFinal的枸杞智能灌溉系统的开发设计与实现 Java基于JFinal的枸杞智能灌溉系统的开发设计与实现 Java基于JFinal的枸杞智能灌溉系统的开发设计与实现 Java基于JFinal的枸杞智能灌溉系统的开发设计与实现 Java...
JFinal + Redis 实现action的数据缓存 在Controller的public void 方法上写上 @Before(RedisCacheInterceptor.class) 即可实现redis缓存 需要在Appconfig中configPlugin代码进行插件加入 RedisPlugin appRedis = ...
JFinal_Blog是基于JFinal1.5开源系统搭建的博客系统,以91zcm.com 网站作为模板和演示事例,目前已经加入了开源行列。 JFinal_Blog 1.1版本发布新增功能点: 1、将数据库连接池由C3P0升级为Druid实现; 2、废弃WEB-...
【基于JFinal的报名系统详解】 JFinal 是一个基于Java的轻量级Web开发框架,它的设计理念是简单、高效,让开发者可以更专注于业务逻辑的实现,而不是被繁琐的配置和复杂的框架结构所困扰。本项目是一个基于JFinal的...
【标题】:“基于Jfinal的网络课程系统”是一款教育技术学专业课程设计的项目,它利用了JAVA极速WEB开发框架——JFinal,旨在构建一个功能完善的网络教学平台。该系统涵盖了课程信息展示、课程内容发布等多个核心...
【SSM+Maven+Jfinal+仓库管理系统】是一个典型的Java Web项目,它结合了Spring、Spring MVC和MyBatis(SSM)三大框架,并利用Maven进行项目管理和依赖管理,同时引入了Jfinal作为轻量级的开发框架,旨在构建一个高效...
JFinal_Blog是基于JFinal1.5开源系统搭建的博客系统,以91zcm.com 网站作为模板和演示demo,目前已经加入了OSC开源项目和Github。 一、V2.0 版本新增功能点及bug修复情况: 1、添加百度Ping服务; 2、添加百度...
【标题】"管理系统系列--JFinal实现的用户权限管理系统.zip" 涉及的主要知识点是基于Java的轻量级Web框架JFinal构建一个用户权限管理系统的实践。JFinal是一个高效、简洁的Java Web开发框架,它以MVC(Model-View-...
JFinal_Blog是基于JFinal1.5开源系统搭建的博客系统,以91zcm.com 网站作为模板和演示demo,目前已经加入了OSC开源项目和Github。 一、V2.0 版本新增功能点及bug修复情况: 1、添加百度Ping服务; 2、添加百度...
在实际应用中,Jfinal 常见于后台管理系统、企业内部应用、个人博客系统等场景。 总的来说,Jfinal 以其高效、轻量、易用的特性,为 Java Web 开发提供了一种高效的选择,尤其对于初学者和小团队来说,能够极大地...