请各位大神帮助,新手求教~基于struts2-spring-ibatis的任务管理系统 在日历上显示问题 在线等解答~
菜鸟刚刚开始学习struts2-spring-ibatis框架,要求做一个任务管理系统其中我已经可以通过在JSP页面上调用struts2的action来对数据库进行增删改查。
现在就是不知道如何把对应时间的任务显示在日历上...我在网上看到了好多的日历都是JS实现的,然后通过JSP又定义方法查询数据库做增删改查的操作...
有没有一种最简单的方法能让日历中对应日期显示出数据库中对应时间的任务,只需要显示出来那天的任务标题就行不需要在日历上进行增删改的操作,如果进行操作,我也希望能用我struts2里面已经有的action来做操作,通过JSP的<s:form></s:form>标签都能搞定。
由于对JSP和JS不是很熟悉,求大神给个JS代码例子作为参考。感激不已。
Task.java
package com.TaskManage.DAO;
public class Task {
private String startTime;
private String endTime;
private String title;
private String details;
private int pc;
private String state;
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getStartTime() {
return startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public String getEndTime() {
return endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDetails() {
return details;
}
public void setDetails(String details) {
this.details = details;
}
public int getPc() {
return pc;
}
public void setPc(int pc) {
this.pc = pc;
}
}
struts.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.objectFactory.spring.autoWire" value="type" />
<constant name="struts.objectFactory" value="spring" />
<include file="struts-default.xml"/>
<!-- <constant name="struts.action.extension" value="do" />
<constant name="struts.configuration.xml.reload" value="true" />
-->
<package name="struts2" namespace="/" extends="struts-default">
<action name="index">
<result name="success" type="redirectAction">findAllTask.action</result>
<result name="error">/error.jsp</result>
</action>
<action name="add" class="TaskAction" method="add">
<result name="success" type="redirectAction">findAllTask.action</result>
<result name="error">/error.jsp</result>
</action>
<action name="edit" class="TaskAction" method="edit">
<result name="success">/update.jsp</result>
</action>
<action name="newTask" class="TaskAction" method="newTask">
<result name="success">/addTask.jsp</result>
</action>
<action name="search" class="TaskAction" method="search">
<result name="success">/search.jsp</result>
</action>
<action name="update" class="TaskAction" method="update">
<result name="success" type="redirectAction">findAllTask.action</result>
<result name="error">/error.jsp</result>
</action>
<action name="delete" class="TaskAction" method="delete">
<result name="success" type="redirectAction">findAllTask.action</result>
<result name="error">/error.jsp</result>
</action>
<action name="findAllTask" class="TaskAction" method="findAllTask">
<result name="success">/list.jsp</result>
<result name="error">/error.jsp</result>
</action>
<action name="findTaskByTitle" class="TaskAction" method="findTaskByTitle">
<result name="success">/findTask.jsp</result>
<result name="error">/error.jsp</result>
</action>
<action name="findTaskByState" class="TaskAction" method="findTaskByState">
<result name="success">/findList.jsp</result>
<result name="error">/error.jsp</result>
</action>
<action name="findTaskByDetails" class="TaskAction" method="findTaskByDetails">
<result name="success">/findList.jsp</result>
<result name="error">/error.jsp</result>
</action>
<action name="findTaskByDate" class="TaskAction" method="findTaskByDate">
<result name="success">/findList.jsp</result>
<result name="error">/error.jsp</result>
</action>
<action name="findUnfinishedTask" class="TaskAction" method="findUnfinishedTask">
<result name="success">/unfinishedList.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
</struts>
task.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap
PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-2.dtd">
<sqlMap namespace="Task">
<typeAlias alias="task" type="com.TaskManage.DAO.Task"/>
<select id="selectAllTask" resultClass="task">
<![CDATA[
SELECT *
FROM TB_TASK
]]>
</select>
<select id="selectTaskByTitle" parameterClass="String" resultClass="task">
<![CDATA[
SELECT *
FROM TB_TASK
where title=#title#
]]>
</select>
<select id="selectTaskByDate" parameterClass="map" resultClass="task">
<![CDATA[
SELECT *
FROM TB_TASK
where startTime >= to_date(#startTime#,'yyyy-MM-dd') and endTime <= to_date(#endTime#,'yyyy-MM-dd')
]]>
</select>
<select id="selectTaskByState" parameterClass="String" resultClass="task">
<![CDATA[
SELECT *
FROM TB_TASK
where state=#state#
]]>
</select>
<insert id="insertTask" parameterClass="task">
<![CDATA[
insert into TB_TASK (startTime,endTime,details,state,pc,title)
values (to_date(#startTime#,'yyyy-MM-dd'),to_date(#endTime#,'yyyy-MM-dd'),#details#,#state#,#pc#,#title#)
]]>
</insert>
<delete id="deleteTaskByTitle" parameterClass="String">
<![CDATA[
delete TB_TASK
where title=#title#
]]>
</delete>
<update id="updateTask" parameterClass="task">
<![CDATA[
update TB_TASK
set
title=#title#,
startTime = to_date(#startTime#,'yyyy-MM-dd'),
endTime = to_date(#endTime#,'yyyy-MM-dd'),
details = #details#,
state = #state#,
pc = #pc#
where title=#title#
]]>
</update>
<select id="selectTaskByDetails" parameterClass="String" resultClass="task">
<![CDATA[
SELECT *
FROM TB_TASK
where details like '%$details$%'
]]>
</select>
<select id="selectUnfinishedTask" resultClass="task">
<![CDATA[
SELECT *
FROM TB_TASK
where state='unfinished'
union
SELECT *
FROM TB_TASK
where state='unstart'
]]>
</select>
</sqlMap>
各位大大看还需要提供什么,我在后面提供出来。 --------------------编程问答-------------------- TaskAction.java:
package com.TaskManage.Action;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.TaskManage.DAO.Task;
import com.TaskManage.Service.ITaskService;
import com.opensymphony.xwork2.ActionSupport;
public class TaskAction extends ActionSupport{
private ITaskService taskService=null;
private List<Task> list;
private Task task;
private String title;
private String state;
private String details;
private String startTime;
private String endTime;
private Map<String,Object> mapInfo = new HashMap<String,Object>();
public ITaskService getTaskService() {
return taskService;
}
public void setTaskService(ITaskService taskService) {
this.taskService = taskService;
}
public List<Task> getList() {
return list;
}
public void setList(List<Task> list) {
this.list = list;
}
public Task getTask() {
return task;
}
public void setTask(Task task) {
this.task = task;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getDetails() {
return details;
}
public void setDetails(String details) {
this.details = details;
}
public String getStartTime() {
return startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public String getEndTime() {
return endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
public String add() throws Exception{
if(getTaskService().addTask(task)){
return SUCCESS;
}
return ERROR;
}
public String edit(){
return SUCCESS;
}
public String newTask(){
return SUCCESS;
}
public String search(){
return SUCCESS;
}
public String update()throws Exception{
if(getTaskService().updateTask(task)){
return SUCCESS;
}
return ERROR;
}
public String delete()throws Exception{
if(getTaskService().deleteTaskByTitle(title)){
return SUCCESS;
}
return ERROR;
}
public String findAllTask()throws Exception{
try {
list=getTaskService().queryAllTask();
} catch (Exception e) {
}
return SUCCESS;
}
public String findUnfinishedTask()throws Exception{
try{
list=getTaskService().queryUnfinishedTask();
}catch (Exception e){
}
return SUCCESS;
}
public String findTaskByTitle()throws Exception{
try{
task=getTaskService().queryTaskByTitle(title);
} catch (Exception e){
}
return SUCCESS;
}
public String findTaskByState()throws Exception{
try{
list=getTaskService().queryTaskByState(state);
}catch(Exception e){
}
return SUCCESS;
}
public String findTaskByDetails()throws Exception{
try{
list=getTaskService().queryTaskByDetails(details);
}catch(Exception e){
}
return SUCCESS;
}
public String findTaskByDate()throws Exception{
mapInfo.put("startTime",startTime);
mapInfo.put("endTime",endTime);
try{
list=getTaskService().queryTaskByDate(mapInfo);
}catch(Exception e){
}
return SUCCESS;
}
}
一个网上找的JS的日历模版,可以做参考:
document.writeln("<div id='calenderdiv' style>日历加载中...</div>");--------------------编程问答-------------------- http://www.my97.net 这对你有用!!! --------------------编程问答-------------------- 2楼您好,您说的日历控件我有用过,但是一般只能使用到在输入日期的地方弹出,然后使用。这个能让我实现把任务显示在日历图对应的日期上吗?如果可以 求解~ --------------------编程问答-------------------- 顶一下,求提示,求解答
var press_tag;
function changecal(action,year,month)
{
var strcal;
switch(action)
{
case "nextmonth":
if(month==11)
{
month = 1;
year = year*1 + 1;
}else{
month = month*1 + 2;
}
strcal = "<span onmouseover=\"this.className='arrow_over'\" onmouseout=\"this.className='arrow_out'\" class='arrow_out' onclick='calender(" + year + "," + month +")' title='下一个月' style='cursor:hand;'>> </span>";
break;
case "premonth":
if(month==0)
{
month = 12;
year = year*1 - 1;
}
strcal = "<span onmouseover=\"this.className='arrow_over'\" onmouseout=\"this.className='arrow_out'\" class='arrow_out' onclick='calender(" + year + "," + month +")' title='上一个月' style='cursor:hand;'> <</span>";
break;
case "nextyear":
year = year*1 + 1;
month = month*1 + 1;
strcal = "<span onmouseover=\"this.className='arrow_over'\" onmouseout=\"this.className='arrow_out'\" class='arrow_out' onclick='calender(" + year + "," + month +")' title='下一年' style='cursor:hand;'>>></span>";
break;
case "preyear":
year = year*1 - 1;
month = month*1 + 1;
strcal = "<span onmouseover=\"this.className='arrow_over'\" onmouseout=\"this.className='arrow_out'\" class='arrow_out' onclick='calender(" + year + "," + month +")' title='上一年' style='cursor:hand;'><<</span>";
break;
default:;
}
strcal = " " + strcal + " ";
return(strcal);
}
function calender(cyear,cmonth)
{
var d,d_date,d_day,d_month;
//定义每月天数数组
var monthdates = ["31","28","31","30","31","30","31","31","30","31","30","31"];
d = new Date();
d_year = d.getYear(); //获取年份
//判断闰月,把monthdates的二月改成29
if (((d_year % 4 == 0) && (d_year % 100 != 0)) || (d_year % 400 == 0)) monthdates[1] = "29";
if ((cyear != "" ) || (cmonth != ""))
{
//如果用户选择了月份和年份,则当前的时间改为用户设定
d.setYear(cyear);
d.setMonth(cmonth-1);
d.setDate(1);
}
d_month = d.getMonth(); //获取当前是第几个月
d_year = d.getYear(); //获取年份
d_date = d.getDate(); //获取日期
//修正19XX年只显示两位的错误
if(d_year<2000){d_year = d_year + 1900};
//===========输出日历===========
var str;
str = "<table cellspacing='0' cellpadding='0' id='calender'>";
str += "<tr><td id='cal_title' colspan='7' >";
str += changecal("preyear",d_year,d_month);
str += changecal("premonth",d_year,d_month);
str += d_year + " - " + (d_month*1+1);
str += changecal("nextmonth",d_year,d_month);
str += changecal("nextyear",d_year,d_month);
str += "</td></tr>";
str += "<tr id='week'><td>星期天</td><td>星期一</td><td>星期二</td><td>星期三</td><td>星期四</td><td>星期五</td><td>星期六</td></tr>";
str += "<tr>";
var firstday,lastday,totalcounts,firstspace,lastspace,monthdays;
//需要显示的月份共有几天,可以用已定义的数组来获取
monthdays = monthdates[d.getMonth()];
//设定日期为月份中的第一天
d.setDate(1);
//需要显示的月份的第一天是星期几
firstday = d.getDay();
//1号前面需要补足的的空单元格的数
firstspace = firstday;
//设定日期为月份的最后一天
d.setDate(monthdays);
//需要显示的月份的最后一天是星期几
lastday = d.getDay();
//最后一天后面需要空单元格数
lastspace = 6 - lastday;
//前空单元格+总天数+后空单元格,用来控制循环
totalcounts = firstspace*1 + monthdays*1 + lastspace*1;
//count:大循环的变量;f_space:输出前空单元格的循环变量;l_space:用于输出后空单元格的循环变量
var count,flag,f_space,l_space;
//flag:前空单元格输完后令flag=1不再继续做这个小循环
flag = 0;
for(count=1;count<=totalcounts;count++)
{
//一开始flag=0,首先输出前空单元格,输完以后flag=1,以后将不再执行这个循环
if(flag==0)
{
if(firstspace!=0)
{
for(f_space=1;f_space<=firstspace;f_space++)
{
str += "<td> </td>";
if(f_space!= firstspace) count++;
}
flag = 1;
continue;
}
}
if((count-firstspace)<=monthdays)
{
//输出月份中的所有天数
curday = d_year+","+(d_month*1+1)+","+(count - firstspace)+"|";
linkday = d_year+","+(d_month*1+1)+","+(count - firstspace);
var today = new Date();
if( (d_year == today.getYear()) && (d_month == today.getMonth()) && ((count-firstspace) == today.getDate()) )
{
//将本地系统中的当前天数高亮
str += "<td><span class='current'>" + (count - firstspace) + "<br>填写</span></td>";
}
else{
//不用高亮的部分,没有日志
str += "<td>" + (count - firstspace) + "<br>填写</td>";
}
if(count%7==0)
{
if(count<totalcounts)
{
str += "</tr><tr>";
}else{
str += "</tr>";
}
}
}else{
//如果已经输出了月份中的最后一天,就开始输出后空单元格补足
for(l_space=1;l_space<=lastspace;l_space++)
{
str += "<td> </td>";
if(l_space!= lastspace) count++;
}
continue;
}
}
document.getElementById("calenderdiv").innerHTML = "<div id='calenderdiv'>" + str + "</div>";
}
//calender("","");
补充:Java , Web 开发