基于FullCalendar插件的简单个人日程安排系统(3)
来源:互联网 发布:ubuntu 16.04密码忘了 编辑:程序博客网 时间:2024/04/29 13:25
(这里的代码有点多不过都不是特别复杂,慢慢看,O(∩_∩)O哈哈~)
LoginServlet.java
package cn.javaee.controller;import java.io.IOException;import java.net.URLEncoder;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.Cookie;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import cn.javaee.model.Customer;import cn.javaee.model.CustomerList;/** * * @see 验证用户登录 * @author wangbin * @time 2017年11月18日 下午3:02:31 */@WebServlet("/LoginServlet")public class LoginServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public LoginServlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.setCharacterEncoding("GBK"); //获取表单提交的三个属性 //分别是 ”用户名“,”密码“,”记住账号" String username = request.getParameter("username"); String password = request.getParameter("password"); String rememberusername =request.getParameter("rememberusername"); //将获取的用户名和密码通过 new Customer(String username,String password)构造方法转换为一个Customer类 Customer customer = new Customer(username,password); if(username!= null && password!=null){ CustomerList customerList = new CustomerList(); //验证用户提交的用户是否存在 //通过判断是否能通过用户提交的用户名从用户列表中获取一个非空的Customer来判断该用户是否存在 Customer curCustomer = customerList.getCustomerByName(username); //若不存在,则返回“incorrect" if(curCustomer == null){ response.getWriter().print("incorrect"); }else{ //若存在该用户,则验证密码是否正确 if(curCustomer.equals(customer)){ //若密码正确,则成功登录 //添加一个cookie用于存放用户的用户名 Cookie nameCookie = new Cookie("username",URLEncoder.encode(customer.getUserName(),"UTF-8")); nameCookie.setMaxAge(60*60*24); response.addCookie(nameCookie); //若用户选择“记住账号",则添加一个cookie用于保留用户的选择 if(rememberusername.equals("true")){ Cookie myCookie=new Cookie("rememberName",URLEncoder.encode(customer.getUserName(),"UTF-8")); myCookie.setMaxAge(60*60*24); response.addCookie(myCookie); }else{ //若用户没有选择“记住账号",则删除用于保留用户选择的cookie Cookie[] cookies = request.getCookies(); if(cookies != null && cookies.length>0){ Cookie cookie = null; for(int i=0;i<cookies.length;i++){ cookie = cookies[i]; if(cookie.getName().equals("rememberName")){ cookie.setMaxAge(0); response.addCookie(cookie); break; } } } } if(curCustomer.getStatus() == 0){ //若该账号是普通用户,则跳转到普通用户页面 response.getWriter().print("customer_index.jsp"); }else{ //若该账号是管理员,则跳转到管理员页面 response.getWriter().print("admin_index.jsp"); } }else{ response.getWriter().print("incorrect"); } } } } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); }}
SignUpServlet.java
package cn.javaee.controller;import java.io.IOException;import java.sql.SQLException;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import cn.javaee.model.Customer;import cn.javaee.model.CustomerList;/** * * @see 用户注册 * @author wangbin * @time 2017年11月18日 下午3:10:54 */@WebServlet("/SignUpServlet")public class SignUpServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public SignUpServlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub //获取用户想要注册的用户名和密码 String userNameSignUp = request.getParameter("userNameSignUp"); String passwordSignUp = request.getParameter("passwordSignUp"); if ((userNameSignUp != null) && (passwordSignUp != null)) { //判断该用户名是否已经被注册 CustomerList customerList = new CustomerList(); Customer customer = customerList.getCustomerByName(userNameSignUp); if(customer == null){ //若该用户名尚未被注册,则添加该用户 customer =new Customer(userNameSignUp,passwordSignUp); customer.setStatus(0); customer.setUserId(String.valueOf(System.currentTimeMillis())); customer.setSchedule(null); //将用户输入的信息转为相应的Customer类 try { customerList.addCustomer(customer); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } response.getWriter().print("success"); }else{ //若已经被注册,则返回一个错误提示 response.getWriter().print("error"); } } else { response.getWriter().print("there is an error!"); } } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); }}
Customer.java
/** * */package cn.javaee.model;/** * @see Customer类,表示普通用户 * @author wangbin * @time 2017年11月15日 下午1:26:10 */public class Customer extends User{ /** * schedule Schedule类,用于存储该用户的所有日程 */ private Schedule schedule; /** * 默认的构造函数 */ public Customer(){ } /** * * @param cutomerId 用户ID */ public Customer(String cutomerId){ schedule = new Schedule(cutomerId); this.setUserId(cutomerId); } /** * * @param userName 用户名 * @param password 用户密码 */ public Customer(String userName,String password){ super(userName,password); } public Schedule getSchedule() { return schedule; } public void setSchedule(Schedule schedule) { this.schedule = schedule; } /* * @see 判断两个普通用户是否相同 * @author wangbin * @time 2017年11月15日 下午1:27:10 * @reutrn 若两者相同则返回true,否则返回false */ @Override public boolean equals(Object obj) { // TODO Auto-generated method stub if(obj != null){ if(obj instanceof Customer){ if((this.getUserName().equals(((Customer) obj).getUserName()) && this.getPassword().equals(((Customer) obj).getPassword()))){ return true; } } } return false; }}
User.java
/** * */package cn.javaee.model;/** * @see User类,表示用户 * @author wangbin * @time 2017年11月15日 下午12:41:06 */public class User { /** * userName 用户名 * userId 用户ID * password 用户密码 * status 用户类别,0为普通用户,1为管理员 */ private String userName; private String userId; private String password; private int status; public User(){ } public User(String userName,String password){ this.userName = userName; this.password = password; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getUserId() { return userId; } public void setUserId(String userId) { this.userId = userId; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public int getStatus() { return status; } public void setStatus(int status) { this.status = status; } /** * @see 判断两个用户是否相同 * @author wangbin * @time 2017年11月15日 下午12:45:25 * @return 若两个userId相同则返回true,否则返回false */ @Override public boolean equals(Object obj) { // TODO Auto-generated method stub if(obj != null){ if(obj instanceof User){ if(this.userId.equals(((User) obj).getUserId())){ return true; } } } return false; }}
CustomerList.java
/** * */package cn.javaee.model;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.ArrayList;/** * @see CustomerList类,用于管理所有的普通用户信息 * @author wangbin * @time 2017年11月15日 下午1:30:56 */public class CustomerList { /** * 用于存储所有的用户信息 */ private ArrayList<Customer> customerList; /** * 从user表中将所有的用户信息转为Customer类,添加到customerList中 * */ public CustomerList(){ Connection conn=null; customerList = new ArrayList<Customer>(); try { conn = AccessJDBCUtil.getAccessDBConnection(); Statement stmt = conn.createStatement(); String queryString = "select * from user "; ResultSet rs = stmt.executeQuery(queryString); while (rs.next()) { Customer customer = new Customer(rs.getString("userId")); customer.setUserId(rs.getString("userId")); customer.setUserName(rs.getString("userName")); customer.setStatus(rs.getInt("status")); customer.setPassword(rs.getString("password")); customerList.add(customer); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ if(conn != null){ try { conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } public ArrayList<Customer> getCustomerList() { return customerList; } public void setCustomerList(ArrayList<Customer> customerList) { this.customerList = customerList; } /** * * @see 通过普通用户名获取普通用户 * @author wangbin * @time 2017年11月15日 下午1:35:26 * @param name 待获取的用户的名字 * @return 若存在名字为name的用户,则返回该用户,否则返回空 */ public Customer getCustomerByName(String name){ for(Customer customer: customerList){ if(customer.getUserName().equals(name)){ return customer; } } return null; } /** * * @see 通过普通用户的用户id获取普通用户 * @author wangbin * @time 2017年11月15日 下午1:37:31 * @param id 待获取的用户的ID * @return 若存在ID为id的用户,则返回该用户,否则返回空 */ public Customer getCustomerById(String id){ for(Customer customer: customerList){ if(customer.getUserId().equals(id)){ return customer; } } return null; } /** * * @see 添加一个普通用户 * @author wangbin * @time 2017年11月15日 下午1:39:20 * @param customer 待添加的用户 */ public boolean addCustomer(Customer customer) throws ClassNotFoundException{ String userName = customer.getUserName(); String password = customer.getPassword(); String userId = String.valueOf(System.currentTimeMillis()); int status = 0; Connection conn=null; try { conn = AccessJDBCUtil.getAccessDBConnection(); Statement stmt = conn.createStatement(); String sql = "insert into user (userName,password,userId,status) values('" + userName + "','" + password + "','" + userId+"',"+status + ");"; int result = stmt.executeUpdate(sql); if (result != -1) { customerList.add(customer); return true; } else { return false; } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if(conn != null){ try { conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return false; } /** * * @see 删除一个用户 * @author wangbin * @time 2017年11月15日 下午1:40:58 * @param id 待删除用户的ID * @return 若存在该用户且成功删除,则返回true,否则返回false; */ public boolean deleteCustomer(String id){ Customer customer = getCustomerById(id); if(customer != null){ customerList.remove(customer); return true; } return false; } /** * * @see 修改一个普通用户的信息 * @author wangbin * @time 2017年11月15日 下午1:43:07 * @param id 待修改用户的ID * @return 若存在该用户且修改信息成功,则返回true,否则返回false */ public boolean modifyCustomer(String id){ for(Customer customer: customerList){ if(customer.getUserId().equals(id)){ //进行相关修改操作 return true; } } return false; } /* * @see 判断两个CustomerList是否相同 * @author wangbin * @time 2017年11月15日 下午1:31:56 * @return 若两者相同,则返回true,否则返回false */ @Override public boolean equals(Object obj) { // TODO Auto-generated method stub if(obj != null){ if(obj instanceof CustomerList){ if(this.getCustomerList().equals(((CustomerList) obj).getCustomerList())){ return true; } } } return false; }}
Schedule.java
/** * */package cn.javaee.model;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.text.DateFormat;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Date;/** * @see Schedule类,用于管理用户的所有事宜(ScheduleItem) * @author wangbin * @time 2017年11月15日 下午1:06:34 */public class Schedule { /** * customerId 该日程安排所属的用户ID * schedule 该日程安排所包含的所有事宜(ScheduleItem) */ private String customerId; private ArrayList<ScheduleItem> schedule; public Schedule(){ } /** * 将schedule_item表中的所有信息转为ScheduleItem,添加到schedule中 * @param customerId 用户ID */ public Schedule(String customerId){ Connection conn=null; schedule = new ArrayList<ScheduleItem>(); try { conn = AccessJDBCUtil.getAccessDBConnection(); Statement stmt = conn.createStatement(); String queryString = "select * from schedule_item where customerId = "+customerId; ResultSet rs = stmt.executeQuery(queryString); while (rs.next()) { ScheduleItem item = new ScheduleItem(); item.setId(rs.getString("id")); item.setCustomerId(rs.getString("customerId")); item.setTitle(rs.getString("content")); //数据表中的time选项对应一个事宜的开始时间 String start = rs.getString("time"); //数据表中的end选项对应一个事宜的结束时间 String end = rs.getString("end"); String remindTime = rs.getString("remindTime"); item.setEnd(end); item.setRemindTime(remindTime); //因为数据表中存放时间的格式是时间戳,但是客户端显示的时间是:2017-11-12 14:25:25 //所以需要将时间戳转为客户端想要的时间格式 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //数据表中存放的时间戳长度是10为,单位是秒 //format(timestamp)函数中的时间戳单位是毫秒 //所以要给从数据表中获取的时间加上3个0 String startTimeString = format.format(Long.parseLong(start+"000")); String endTimeString = format.format(Long.parseLong(end+"000")); item.setStart(startTimeString); item.setEnd(endTimeString); //数据表中是用state项来表示一个事宜的状态 //ScheduleItem是用color来表示一个事宜的状态 //所以要将state值转为对应的颜色 int state = rs.getInt("state"); String color=null; if(state == 1){ color = "yellow"; }else if(state == 2){ color = "red"; }else if(state == 3){ color = "green"; }else{ color = "gray"; } item.setColor(color); schedule.add(item); } //更新返回的数据 //就是判断哪些事宜已经进入了提醒时间,修改那些进入提醒时间的事宜状态 //但是并没有修改数据库中这些事宜的值 updateSchedule(schedule); //修改数据库中这些事宜的值 updateData(schedule); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ if(conn != null){ try { conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } public String getCustomerId() { return customerId; } public void setCustomerId(String customerId) { this.customerId = customerId; } public ArrayList<ScheduleItem> getSchedule() { return schedule; } public void setSchedule(ArrayList<ScheduleItem> schedule) { this.schedule = schedule; } /** * * @see 通过ScheduleItem的id来获取ScheduleItem * @author wangbin * @time 2017年11月15日 下午1:13:30 * @param itemId ScheduleItem的id * @return 若存在则返回该ScheduleItem,否则返回空 */ public ScheduleItem getScheduleItem(String itemId){ //遍历该Schedule中的所有ScheduleItem //若存在一项的id与itemId相同则返回该项 for(ScheduleItem item: schedule){ if(item.getId().equals(itemId)){ return item; } } return null; } /** * * @see 添加一条事宜 * @author wangbin * @time 2017年11月15日 下午1:15:28 * @param item 待添加的事宜 */ public boolean addScheduleItem(ScheduleItem item){ //若该项事宜不为空,则正常添加 String id = item.getId(); String cutomerId = item.getCustomerId(); String title = item.getTitle(); String start = item.getStart(); String end = item.getEnd(); String remindTime = item.getRemindTime(); Connection conn=null; try { conn = AccessJDBCUtil.getAccessDBConnection(); Statement stmt = conn.createStatement(); String sql = "insert into schedule_item (id,customerId,content,time,remindTime,state,end) values('" + id + "','" + cutomerId + "','" + title+"','"+start +"','"+remindTime+"',1,'"+end+"');"; int result = stmt.executeUpdate(sql); if (result != -1) { schedule.add(item); return true; } else { return false; } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if(conn != null){ try { conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return false; } /** * * @see 删除一条事宜 * @author wangbin * @time 2017年11月15日 下午1:20:12 * @param itemId 待删除事宜的ID * @return 若成功删除则返回true,否则返回false; */ public boolean deleteScheduleItem(String itemId){ Connection conn=null; try { conn = AccessJDBCUtil.getAccessDBConnection(); Statement stmt = conn.createStatement(); String sql = "delete from schedule_item where id = "+itemId; int result = stmt.executeUpdate(sql); if(result != -1){ return true; } }catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally{ if(conn != null){ try { conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return false; } /** * * @see 修改某项事宜 * @author wangbin * @time 2017年11月15日 下午1:25:03 * @param itemId 待修改事宜的id * @return 若修改成功则返回true,否则返回false; */ public boolean modifyScheduleItem(String itemId,String title,String start,String end,String remindTime){ Connection conn=null; try { conn = AccessJDBCUtil.getAccessDBConnection(); Statement stmt = conn.createStatement(); String sql = "update schedule_item set content = '"+title+"',time='"+start+"',end='"+end+"',remindTime='"+remindTime+"' where id = "+itemId; stmt.executeUpdate(sql); return true; }catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally{ if(conn != null){ try { conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return false; } /** * * @see 完成一条事宜 * @author wangbin * @time 2017年11月18日 下午3:27:20 * @param itemId 被完成的事宜的ID * @return */ public boolean changeItemState(String itemId){ Connection conn=null; try { conn = AccessJDBCUtil.getAccessDBConnection(); Statement stmt = conn.createStatement(); //将该事宜的state值改为3,即意味着完成了一条事宜 String sql = "update schedule_item set state = 3 where id = "+itemId; int result = stmt.executeUpdate(sql); if(result != -1){ return true; } }catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally{ if(conn != null){ try { conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return false; } /** * * @see 更新事宜的状态 * @author wangbin * @time 2017年11月18日 下午3:28:27 * @param schedule */ public void updateSchedule(ArrayList<ScheduleItem> schedule){ //遍历所有的事宜,看哪些事宜需要修改 for(ScheduleItem item: schedule){ long now = Long.parseLong(String.valueOf(System.currentTimeMillis())); String start = item.getStart(); String end = item.getEnd(); String remindTime =item.getRemindTime(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date startDate = null; Date endDate = null; try { startDate = simpleDateFormat.parse(start); endDate = simpleDateFormat.parse(end); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } long startTimeStamp = startDate.getTime(); long endTimeStamp = endDate.getTime(); long dueRemindTime = startTimeStamp-Long.parseLong(remindTime); if(now>dueRemindTime && now<endTimeStamp && !item.getColor().equals("green") && !item.getColor().equals("gray")){ //若当前时间大于用户设置的事宜开始时间减去提醒时间 //则意味着该事宜已经进入了提醒状态 item.setColor("red"); }else if(now >endTimeStamp && !item.getColor().equals("green")){ //若当前时间大于用户设置的事宜的结束时间,且用户没有完成该事宜 //则意味着该事宜进入了"未完成"状态 item.setColor("gray"); } } } /** * * @see 更新数据表中需要修改的事宜 * 该方法同上,只是这个方法是修改数据表中的数据 * @author wangbin * @time 2017年11月18日 下午3:31:01 * @param schedule */ public void updateData(ArrayList<ScheduleItem> schedule){ Connection conn=null; try { conn = AccessJDBCUtil.getAccessDBConnection(); Statement stmt = conn.createStatement(); for(ScheduleItem item: schedule){ long now = Long.parseLong(String.valueOf(System.currentTimeMillis())); String start = item.getStart(); String end = item.getEnd(); String remindTime =item.getRemindTime(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date startDate = null; Date endDate = null; try { startDate = simpleDateFormat.parse(start); endDate = simpleDateFormat.parse(end); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } long startTimeStamp = startDate.getTime(); long endTimeStamp = endDate.getTime(); long dueRemindTime = startTimeStamp-Long.parseLong(remindTime); String sql = null; if(now>dueRemindTime && now<endTimeStamp && !item.getColor().equals("green") && !item.getColor().equals("gray")){ sql = "update schedule_item set state = 2 where id = "+item.getId(); stmt.executeUpdate(sql); }else if(now >endTimeStamp && !item.getColor().equals("green")){ sql = "update schedule_item set state = 4 where id = "+item.getId(); stmt.executeUpdate(sql); } } }catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally{ if(conn != null){ try { conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } /* * @see 判断两个Schedule是否相同 * @author wangbin * @time 2017年11月15日 下午1:09:34 * @return 若两者相同则返回true,否则返回false; */ @Override public boolean equals(Object obj) { // TODO Auto-generated method stub if(obj != null){ if(obj instanceof Schedule){ if(this.getCustomerId().equals(((Schedule) obj).getCustomerId()) && this.getSchedule().equals(((Schedule) obj).getSchedule())){ return true; } } } return false; }}
ScheduleItem.java
/** * */package cn.javaee.model;/** * @see ScheduleItem类,表示日程安排中的事宜 * @author wangbin * @time 2017年11月15日 下午12:48:04 */public class ScheduleItem { /** * id 事宜ID * customerId 该事宜所属的用户ID * content 该事宜的内容 * time 该事宜设置的时间 * remindTime 该事宜的提醒时间(如在事宜设置的时间前30分钟或者一小时,该事宜进入提醒时间状态) * color 该事宜的状态 * 未进入提醒时间的待完成事宜用 黄色表示 * 进入提醒时间的待完成事宜用 红色表示 * 已完成的事宜用 绿色表示 * 未完成的事宜用 灰色表示 */ private String id; private String customerId; private String title; private String start; private String end; private String color; private String remindTime; public ScheduleItem(){ } public ScheduleItem(String id,String title,String start,String end,String color,String remindTime){ this.id = id; this.title = title; this.start = start; this.end = end; this.color = color; this.remindTime = remindTime; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getCustomerId() { return customerId; } public void setCustomerId(String customerId) { this.customerId = customerId; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getStart() { return start; } public void setStart(String start) { this.start = start; } public String getEnd() { return end; } public void setEnd(String end) { this.end = end; } public String getColor() { return color; } public void setColor(String color) { this.color = color; } public String getRemindTime() { return remindTime; } public void setRemindTime(String remindTime) { this.remindTime = remindTime; }/* (non-Javadoc) * @see java.lang.Object#toString() */@Overridepublic String toString() { // TODO Auto-generated method stub return "{id:'"+this.id+"',title:'"+this.title+"',start:'"+this.start+"',end:'"+this.end+"',color:'"+this.color+"',remindTime'"+this.remindTime+"'}";} /** * @see 判断两个事宜是否相同 * @author wangbin * @time 2017年11月15日 下午13:02:14 * @return 若两者相同则返回true,否则返回false */ @Override public boolean equals(Object obj) { // TODO Auto-generated method stub if(obj != null){ if(obj instanceof ScheduleItem){ if(this.getId().equals(((ScheduleItem) obj).getId())){ return true; } } } return false; }}
AccessJDBCUtil.java
package cn.javaee.model;/** * @see AccessJDBCUtil工具类,用于处理数据库连接 * @author wangbin * @time 2017年11月15日 下午3:16:19 */import java.sql.*;public class AccessJDBCUtil { //注册jdbc驱动 static { try { Class.forName("com.mysql.jdbc.Driver"); } catch(ClassNotFoundException e) { System.err.println("JdbcOdbc Bridge Driver not found!"); } } /** * * @see 建立数据库连接,连接的数据库名为marhong,用户名、密码均为root * @author wangbin * @time 2017年11月15日 下午3:17:11 * @return * @throws SQLException */ public static java.sql.Connection getAccessDBConnection() throws SQLException { String databaseURL = "jdbc:mysql://localhost/marhong?useUnicode=true&characterEncoding=utf-8"; return DriverManager.getConnection(databaseURL, "root", "root"); } }
这里我用的数据库是mysql,上面用到的数据库名为marhong,库中有两个表user、schedule_item,两个表的结构如下图所示:
user表
schedule_item表
具体的代码功能就不再解释了,因为在java doc中已经说的很详细了。如果有疑惑可以一起讨论哈。
阅读全文
0 0
- 基于FullCalendar插件的简单个人日程安排系统(3)
- 基于FullCalendar插件的简单个人日程安排系统(1)
- 基于FullCalendar插件的简单个人日程安排系统(2)
- 基于FullCalendar插件的个人日程安排系统(4)
- 日程安排插件fullcalendar
- 基于J2ME技术的高校学生日程安排系统
- fullCalendar插件的使用
- fullcalendar的简单运用
- jQuery插件实战之Fullcalendar - 开发一个完整功能的富客户端会议室预定系统前台
- 带记事功能的日历插件fullCalendar
- 基于SSH2的个人博客系统
- 基于PHP+MySQL的个人博客系统
- 基于数据结构的个人图书管理系统
- 基于jsp+servlet的个人博客系统
- 基于SSH的个人信息管理系统
- fullCalendar插件使用心得
- FullCalendar日历插件使用说明
- fullcalendar日历插件使用手册
- 【python】透彻解析csv文件
- java构造函数
- C语言常用运算符与函数汇总
- python学习笔记 第四章
- JVM 发生OOM的四种情况
- 基于FullCalendar插件的简单个人日程安排系统(3)
- 常用的MIME类型
- K-Means聚类算法的原理及实现
- 红黑树
- 【Java学习】----如何映射JavaEE到MVC
- 老徐教你识破小程序各种骗局!
- 2017/11/27_周报
- 练习1-13 编写一个程序,打印输入中单词长度的垂直方向的直方图(垂直图)
- 编码解码原理