第一次使用博客 贴一个JSP+SQL实现按日期查询留言的代码吧~
2017-11-21 17:52
603 查看
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@page import="com.zjff.dao.MatesDao"%> <%@page import="com.zjff.dao.impl.MatesDaoimpl"%> <%@page import="com.zjff.entity.Mates"%> <%@page import="com.zjff.dao.MessageTypeDao"%> <%@page import="com.zjff.dao.impl.MessageTypeDaoimpl"%> <%@page import="com.zjff.dao.MateTypeDao"%> <%@page import="com.zjff.dao.impl.MateTypeDaoimpl"%> <!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> <style type="text/css"> #header { background-color: #CCC; height: 120px; width: 100%; text-align: center; font: 微软雅黑; line-height: 120px; letter-spacing: 5px; font-size: 24px; } #nav { height: 50px; width: 100%; text-align: center; line-height: 50px; margin-top: 5px; } </style> </head> <% MatesDao mate = new MatesDaoimpl(); List<Mates> list = new ArrayList<Mates>(); list = mate.getAllMate(); //输入所有留言的实例 用了SQL select * form mate Set<Date> set =new HashSet<Date>(); for(int i=0;i<list.size();i++){ set.add(list.get(i).getSubDate()); //用set集合特性 将重复的日期唯一化 } %> <body bgcolor="#7FFFD4"> <div id="header"> 班级留言板 </div> <div id="nav"> <form action="check.jsp" method="post"> <select name="subtime"> <% for(Date time:set ){ //遍历set集合 %> <option value="<%=time%>"><%=time%></option> //将value直接取值 提交至下个页面赋值容易 <% } %> </select> <button type="submit" value="Submit"> 查询 </button> <button> <a href="addit.jsp" style="text-decoration: none;color: black;">添加</a> </button> </form> </div> <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 " id="content"> <div class="content_table"> <table width="100%" cellpadding="0" cellspacing="1" bgcolor="#dedede"> <caption> table </caption> <tr bgcolor="#eae9ca"> <th> ID </th> <th> 用戶姓名 </th> <th> 留言內容 </th> <th> 留言时间 </th> <th> 留言类型 </th> <th> 用户类型 </th> </tr> <% Mates mates=null; MessageTypeDao mad=new MessageTypeDaoimpl(); MateTypeDao mtd=new MateTypeDaoimpl(); for(int i=0;i<list.size();i++){ mates=list.get(i); //遍历所有留言 %> <% if(i%2==0){%> <tr class="odd"> <td> <%=mates.getMateId() %> </td> <td> <%=mates.getMateName() %> </td> <td> <%=mates.getMateContent() %> </td> <td> <%=mates.getSubDate() %> </td> <td> <%=mad.getMessageTypeById(mates.getMessageTypeId()).getMessageTypeName() %> </td> <td> <%if(mates.getMateTypeId()!=0){ %> <%=mtd.getMateTypeById(mates.getMateTypeId()).getMateTypeName() %> <% }else{%> <%="一般同学" %> <%} %> </td> </tr> <%}else{ %> <tr class="even"> <td> <%=mates.getMateId() %> </td> <td> <%=mates.getMateName() %> </td> <td> <%=mates.getMateContent() %> </td> <td> <%=mates.getSubDate() %> </td> <td> <%=mad.getMessageTypeById(mates.getMessageTypeId()).getMessageTypeName() %> </td> <td> <%if(mates.getMateTypeId()!=0){ %> <%=mtd.getMateTypeById(mates.getMateTypeId()).getMateTypeName() %> <% }else{%> <%="一般同学" %> <%} %> </td> </tr> <%} }%> </table> </div> <div class="page"> <div class="right"> </div> </div> </div> </body> </html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@page import="com.zjff.dao.MatesDao"%> <%@page import="com.zjff.dao.impl.MatesDaoimpl"%> <%@page import="com.zjff.entity.Mates"%> <%@page import="com.zjff.dao.MessageTypeDao"%> <%@page import="com.zjff.dao.impl.MessageTypeDaoimpl"%> <%@page import="com.zjff.dao.MateTypeDao"%> <%@page import="com.zjff.dao.impl.MateTypeDaoimpl"%> <%@page import="java.util.logging.SimpleFormatter"%> <%@page import="java.text.SimpleDateFormat"%> <!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> <style type="text/css"> #header { background-color: #CCC; height: 120px; width: 100%; text-align: center; font: 微软雅黑; line-height: 120px; letter-spacing: 5px; font-size: 24px; } #nav { height: 50px; width: 100%; text-align: center; line-height: 50px; margin-top: 5px; } </style> </head> <% MatesDao mate = new MatesDaoimpl(); List<Mates> list = new ArrayList<Mates>(); Date d=new SimpleDateFormat("yyyy-MM-dd").parse(request.getParameter("subtime"));//将上个界面提交的值转成Date类型 list=mate.getMessageBySubDate(d); Set<Date> set =new HashSet<Date>(); for(int i=0;i<list.size();i++){ set.add(list.get(i).getSubDate()); } %> <body bgcolor="#7FFFD4"> <div id="header"> 班级留言板 </div> <div id="nav"> <button> <a href="find.jsp" style="text-decoration: none;color: black;">返回</a> </button> <button> <a href="addit.jsp" style="text-decoration: none;color: black;">添加</a> </button> </div> <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 " id="content"> <div class="content_table"> <table width="100%" cellpadding="0" cellspacing="1" bgcolor="#dedede"> <caption> table </caption> <tr bgcolor="#eae9ca"> <th> ID </th> <th> 用戶姓名 </th> <th> 留言內容 </th> <th> 留言时间 </th> <th> 留言类型 </th> <th> 用户类型 </th> </tr> <% Mates mates=null; MessageTypeDao mad=new MessageTypeDaoimpl(); MateTypeDao mtd=new MateTypeDaoimpl(); for(int i=0;i<list.size();i++){ mates=list.get(i); %> <% if(i%2==0){%> <tr class="odd"> <td> <%=mates.getMateId() %> </td> <td> <%=mates.getMateName() %> </td> <td> <%=mates.getMateContent() %> </td> <td> <%=mates.getSubDate() %> </td> <td> <%=mad.getMessageTypeById(mates.getMessageTypeId()).getMessageTypeName() %> </td> <td> <%if(mates.getMateTypeId()!=0){ %> <%=mtd.getMateTypeById(mates.getMateTypeId()).getMateTypeName() %> <% }else{%> <%="一般同学" %> <%} %> </td> </tr> <%}else{ %> <tr class="even"> <td> <%=mates.getMateId() %> </td> <td> <%=mates.getMateName() %> </td> <td> <%=mates.getMateContent() %> </td> <td> <%=mates.getSubDate() %> </td> <td> <%=mad.getMessageTypeById(mates.getMessageTypeId()).getMessageTypeName() %> </td> <td> <%if(mates.getMateTypeId()!=0){ %> <%=mtd.getMateTypeById(mates.getMateTypeId()).getMateTypeName() %> <% }else{%> <%="一般同学" %> <%} %> </td> </tr> <%} }%> </table> </div> <div class="page"> <div class="right"> </div> </div> </div> </body> </html>
相关文章推荐
- 使用jsp,tomcat实现用户登录注册留言的代码
- 一个使用J2ME技术实现的计算器的代码
- 一个使用J2ME技术实现的计算器的代码
- 有关打印、收藏等的JS代码(打印等主要使用了一个IE组件来实现)
- 一个使用J2ME技术实现的计算器的代码
- 一个使用J2ME技术实现的计算器的代码
- 在SQL中使用convert函数进行日期的查询的代码
- 使用ip数据库纯真版查询ip-代码实现
- Asp.net使用C#代码实现万年历查询
- 使用一个存储过程实现多条件查询
- 10_9_2从类MyClass中派生一个类MyDervedClass,重写GetString(),使用该方法的基类实现代码从基类中返回一个字符串,但在返回的字符串中添加文本"(output fro)"
- 有关打印、收藏等的JS代码(打印等主要使用了一个IE组件来实现)
- 在SQL中使用convert函数进行日期的查询的代码
- 使用gsoap实现一个简单的 QQ在线状态查询程序
- 在博客中查询不同日期博客的代码
- JSP中有关时间和日期类的使用与JSP中的字符替换函数 str_replace()实现
- 使用VC内嵌Python实现的一个代码检测工具
- 新写的一个使用ASP.NET AJAX中的UpdatePanel控件实现GridView的无刷新删除,更新,添加,查询!
- 在Action中查询出SQL SERVER表的数据,返回一个list。怎么在JSP页面中使用Struts标签,显示出表中的内容?(转)
- 一个使用J2ME技术实现的计算器的代码