diff --git a/build.gradle b/build.gradle index eccc0f2..afd194e 100644 --- a/build.gradle +++ b/build.gradle @@ -13,8 +13,10 @@ subprojects { dependencies { testCompile group: 'junit', name: 'junit', version: '4.11' compile 'mysql:mysql-connector-java:5.1.34' - compile 'javax.servlet:jstl:1.1.2' compile 'org.flywaydb:flyway-core:3.0' + compile 'jstl:jstl:1.2' + compile 'org.json:json:20141113' + } } diff --git a/core/build.gradle b/core/build.gradle index 0abe490..5c0719b 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -1,22 +1,23 @@ apply plugin: 'java' apply plugin: 'org.flywaydb.flyway' -/*指定从mvnRepository中安装依赖*/ buildscript { repositories { mavenCentral() } dependencies { -// classpath 'com.h2database:h2:1.3.170' classpath 'org.flywaydb:flyway-gradle-plugin:3.2.1' - + classpath 'org.codehaus.jackson:jackson-mapper-asl:1.9.10' } } dependencies { testCompile 'junit:junit:4.10' compile 'org.hibernate:hibernate-entitymanager:4.3.8.Final' + compile 'org.springframework:spring-webmvc:4.1.7.RELEASE' + compile 'javax.servlet:javax.servlet-api:3.1.0' + } diff --git a/core/src/main/java/com/tw/core/Dao/CoachDao.java b/core/src/main/java/com/tw/core/Dao/CoachDao.java new file mode 100644 index 0000000..3690fcb --- /dev/null +++ b/core/src/main/java/com/tw/core/Dao/CoachDao.java @@ -0,0 +1,35 @@ +package com.tw.core.Dao; + +import com.tw.core.entity.Coach; +import org.hibernate.Query; +import org.hibernate.Session; +import org.springframework.stereotype.Repository; + +import java.sql.SQLException; +import java.util.List; + +import static com.tw.core.Util.HibernateUtil.getSessionFactory; + +/** + * Created by twer on 7/22/15. + */ + +@Repository +public class CoachDao { + + public List getCoaches() throws SQLException { + + Session session = getSessionFactory().openSession(); + session.beginTransaction(); + Query query = session.createQuery("from Employee employee where employee.role = 'COACH' "); //此处User是类名,而不是数据库的表名,select * 不写 + List coachList = query.list(); + session.close(); + return coachList; + } + + + public static void main(String arg[]) throws SQLException{ + CoachDao coachDao = new CoachDao(); + System.out.println(coachDao.getCoaches()); + } +} diff --git a/core/src/main/java/com/tw/core/Dao/CourseDao.java b/core/src/main/java/com/tw/core/Dao/CourseDao.java new file mode 100644 index 0000000..ed7c42d --- /dev/null +++ b/core/src/main/java/com/tw/core/Dao/CourseDao.java @@ -0,0 +1,78 @@ +package com.tw.core.Dao; + +import com.tw.core.entity.Course; +import org.hibernate.Query; +import org.hibernate.Session; +import org.springframework.stereotype.Repository; + +import java.sql.SQLException; +import java.util.List; + +import static com.tw.core.Util.HibernateUtil.getSessionFactory; + +@Repository +public class CourseDao { + + public List getCourses() throws SQLException { + + Session session = getSessionFactory().openSession(); + session.beginTransaction(); + Query query = session.createQuery("from Course"); //此处User是类名,而不是数据库的表名,select * 不写 + List courseList = query.list(); + session.getTransaction().commit(); + session.close(); + return courseList; + } + + + public void insertCourse(Course course) throws SQLException { + + Session session = getSessionFactory().openSession(); + session.beginTransaction(); + session.save(course); + session.getTransaction().commit(); + session.close(); + } + + + + public void deleteCourse(int id) throws SQLException { + + Session session = getSessionFactory().openSession(); + session.beginTransaction(); + + Course course = new Course(); + course.setId(id); + session.delete(course); + session.getTransaction().commit(); + + session.close(); + } + + + public Course getOneCourse(int id) throws SQLException{ + + Session session = getSessionFactory().openSession(); + session.beginTransaction(); + Course course = (Course)session.get(Course.class,id); + + session.close(); + return course; + } + + public void UpdateOneCourse(Course course) throws SQLException{ + + Session session = getSessionFactory().openSession(); + session.beginTransaction(); + + session.update(course); + session.getTransaction().commit(); + session.close(); + } + + + public static void main()throws SQLException{ + CourseDao courseDao = new CourseDao(); + System.out.println(courseDao.getCourses()); + } +} diff --git a/core/src/main/java/com/tw/core/Dao/CustomerDao.java b/core/src/main/java/com/tw/core/Dao/CustomerDao.java new file mode 100644 index 0000000..4576831 --- /dev/null +++ b/core/src/main/java/com/tw/core/Dao/CustomerDao.java @@ -0,0 +1,78 @@ +package com.tw.core.Dao; + +import com.tw.core.entity.Customer; +import org.hibernate.Query; +import org.hibernate.Session; +import org.springframework.stereotype.Repository; + +import java.sql.SQLException; +import java.util.List; + +import static com.tw.core.Util.HibernateUtil.getSessionFactory; +@Repository +public class CustomerDao { + + public List getCustomers() throws SQLException { + + Session session = getSessionFactory().openSession(); + session.beginTransaction(); + Query query = session.createQuery("from Customer"); //此处User是类名,而不是数据库的表名,select * 不写 + List customerList = query.list(); + session.getTransaction().commit(); + session.close(); + return customerList; + } + + + public void insertCustomer(Customer customer) throws SQLException { + + Session session = getSessionFactory().openSession(); + session.beginTransaction(); + session.save(customer); + session.getTransaction().commit(); + session.close(); + } + + + + public void deleteCustomer(int id) throws SQLException { + + Session session = getSessionFactory().openSession(); + session.beginTransaction(); + + Customer customer = new Customer(); + customer.setId(id); + session.delete(customer); + session.getTransaction().commit(); + + session.close(); + } + + + public Customer getOneCustomer(int id) throws SQLException{ + + Session session = getSessionFactory().openSession(); + session.beginTransaction(); + Customer customer = (Customer)session.get(Customer.class,id); + + session.close(); + return customer; + } + + public void UpdateOneCustomer(Customer customer) throws SQLException{ + + Session session = getSessionFactory().openSession(); + session.beginTransaction(); + + session.update(customer); + session.getTransaction().commit(); + session.close(); + } + + + + public static void main(String arg[]) throws SQLException{ + CustomerDao customerDao = new CustomerDao(); + System.out.println(customerDao.getCustomers()+"!!!!!!!!!!!!!!!!!!!!!!!"); + } +} diff --git a/core/src/main/java/com/tw/core/Dao/DBConnection.java b/core/src/main/java/com/tw/core/Dao/DBConnection.java deleted file mode 100644 index 2af4f64..0000000 --- a/core/src/main/java/com/tw/core/Dao/DBConnection.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.tw.core.Dao; - -import com.tw.core.entity.User; - -import java.sql.*; -import java.util.ArrayList; -import java.util.List; - -/** - * Created by twer on 7/7/15. - */ -public class DBConnection { - - public Connection getConnection() { - - Connection connection = null; - String driver = "com.mysql.jdbc.Driver"; //驱动名称 - String url = "jdbc:mysql://localhost:3306/userInfo?useUnicode=true&characterEncoding=UTF-8";//url指向要访问的数据库 - - try { - Class.forName(driver);//加载驱动程序 - connection = DriverManager.getConnection(url, "root", "");//链接数据库 - - } catch (Exception e) { - e.printStackTrace(); - } - return connection; - } - - public static void main(String[] args){ - System.out.print(new DBConnection().getConnection());} - -} diff --git a/core/src/main/java/com/tw/core/Dao/EmployeeDao.java b/core/src/main/java/com/tw/core/Dao/EmployeeDao.java new file mode 100644 index 0000000..8026e2c --- /dev/null +++ b/core/src/main/java/com/tw/core/Dao/EmployeeDao.java @@ -0,0 +1,68 @@ +package com.tw.core.Dao; + +import com.tw.core.entity.Employee; +import com.tw.core.entity.User; +import org.hibernate.Query; +import org.hibernate.Session; +import org.springframework.stereotype.Repository; + +import java.sql.SQLException; +import java.util.List; + +import static com.tw.core.Util.HibernateUtil.getSessionFactory; + + +@Repository +public class EmployeeDao { + + public List getEmployees() throws SQLException { + + Session session = getSessionFactory().openSession(); + session.beginTransaction(); + Query query = session.createQuery("from Employee"); //此处User是类名,而不是数据库的表名,select * 不写 + List employeeList = query.list(); + session.close(); + return employeeList; + } + + + public void insertEmployee(Employee employee) throws SQLException { + + Session session = getSessionFactory().openSession(); + session.beginTransaction(); + session.save(employee); + session.getTransaction().commit(); + session.close(); + } + + + + + public Employee getOneEmployee(int id) throws SQLException{ + + Session session = getSessionFactory().openSession(); + session.beginTransaction(); + Employee employee = (Employee)session.get(Employee.class,id); + + session.close(); + return employee; + } + + + public void UpdateOneEmployee(Employee employee) throws SQLException{ + + Session session = getSessionFactory().openSession(); + session.beginTransaction(); + + session.update(employee); + session.getTransaction().commit(); + session.close(); + } + +// public static void main(String arg[]) throws SQLException{ +// EmployeeDao employeeDao = new EmployeeDao(); +// Employee employee = new Employee("jame","male",11,"3","coach","YES"); +// employeeDao.insertEmployee(employee); +// } + +} diff --git a/core/src/main/java/com/tw/core/Dao/PasswordEncryption.java b/core/src/main/java/com/tw/core/Dao/PasswordEncryption.java new file mode 100644 index 0000000..a04c130 --- /dev/null +++ b/core/src/main/java/com/tw/core/Dao/PasswordEncryption.java @@ -0,0 +1,42 @@ +package com.tw.core.Dao; + +import org.springframework.stereotype.Repository; + +import java.security.MessageDigest; + + +@Repository +public class PasswordEncryption { + + public String encodeByMD5(String originStr) { + try { + //生成实现指定摘要算法的 MessageDigest 对象。 + MessageDigest md = MessageDigest.getInstance("MD5"); + //使用指定的字节数组更新摘要。 + md.update(originStr.getBytes()); + //通过执行诸如填充之类的最终操作完成哈希计算。 + byte b[] = md.digest(); + //生成具体的md5密码到buf数组 + int i; + StringBuffer buf = new StringBuffer(""); + for (int offset = 0; offset < b.length; offset++) { + i = b[offset]; + if (i < 0) + i += 256; + if (i < 16) + buf.append("0"); + buf.append(Integer.toHexString(i)); + } + return buf.toString(); +// System.out.println("32位: " + buf.toString());// 32位的加密 +// System.out.println("16位: " + buf.toString().substring(8, 24));// 16位的加密,其实就是32位加密后的截取 + } + catch (Exception e) { + e.printStackTrace(); + return originStr; + } + } + + + +} diff --git a/core/src/main/java/com/tw/core/Dao/ScheduleDao.java b/core/src/main/java/com/tw/core/Dao/ScheduleDao.java new file mode 100644 index 0000000..949ae1b --- /dev/null +++ b/core/src/main/java/com/tw/core/Dao/ScheduleDao.java @@ -0,0 +1,69 @@ +package com.tw.core.Dao; + +import com.tw.core.entity.Schedule; +import org.hibernate.Query; +import org.hibernate.Session; +import org.springframework.stereotype.Repository; + +import java.sql.SQLException; +import java.util.List; + +import static com.tw.core.Util.HibernateUtil.getSessionFactory; + + +@Repository +public class ScheduleDao { + + public List getSchedules() throws SQLException { + Session session = getSessionFactory().openSession(); + session.beginTransaction(); + Query query = session.createQuery("from Schedule"); + List scheduleList = query.list(); + session.close(); + return scheduleList; + } + + public void deleteSchedule(int id) throws SQLException { + + Session session = getSessionFactory().openSession(); + session.beginTransaction(); + + Schedule schedule = new Schedule(); + schedule.setId(id); + session.delete(schedule); + session.getTransaction().commit(); + + session.close(); + } + + public void insertSchedule(Schedule schedule) throws SQLException { + + Session session = getSessionFactory().openSession(); + session.beginTransaction(); + session.save(schedule); + session.getTransaction().commit(); + session.close(); + } + + public Schedule getOneSchedule(int id) throws SQLException{ + + Session session = getSessionFactory().openSession(); + session.beginTransaction(); + Schedule schedule = (Schedule)session.get(Schedule.class,id); + + session.close(); + return schedule; + } + + + public void updateOneSchedule(Schedule schedule) throws SQLException{ + + Session session = getSessionFactory().openSession(); + session.beginTransaction(); + + session.update(schedule); + session.getTransaction().commit(); + session.close(); + } + +} diff --git a/core/src/main/java/com/tw/core/Dao/UserDao.java b/core/src/main/java/com/tw/core/Dao/UserDao.java index a3fead0..52365bc 100644 --- a/core/src/main/java/com/tw/core/Dao/UserDao.java +++ b/core/src/main/java/com/tw/core/Dao/UserDao.java @@ -1,59 +1,77 @@ package com.tw.core.Dao; -import com.tw.core.Util.HibernateUtil; +import com.tw.core.entity.Employee; import com.tw.core.entity.User; import org.hibernate.Query; import org.hibernate.Session; -import org.hibernate.Transaction; +import org.springframework.stereotype.Repository; import java.sql.*; -import java.util.ArrayList; import java.util.List; +import static com.tw.core.Util.HibernateUtil.getSessionFactory; -/** - * Created by twer on 7/7/15. - */ - - - +@Repository public class UserDao { + PasswordEncryption passwordEncryption = new PasswordEncryption(); public List getUsers() throws SQLException { - Session session = HibernateUtil.getSessionFactory().openSession(); + Session session = getSessionFactory().openSession(); session.beginTransaction(); Query query = session.createQuery("from User"); //此处User是类名,而不是数据库的表名,select * 不写 List usersList = query.list(); + session.close(); + return usersList; + } - return usersList; + public boolean verifyRegister(User user) throws SQLException{ - } + Session session = getSessionFactory().openSession(); + session.beginTransaction(); - public void insertUsers(String name, String sex, String email, int age) throws SQLException { + Employee employee = user.getEmployee(); - Session session = HibernateUtil.getSessionFactory().openSession(); + if (employee == null){ + System.out.println("++++++++++++++++++++++++++该工号不存在++++++++++++++++++++"); + return false; + }else{ - User user = new User(); - user.setName(name); - user.setSex(sex); - user.setEmail(email); - user.setAge(age); + int coachId = employee.getId(); + Query query = session.createQuery("SELECT count(*) FROM User user where user.employee.id = :coachId"); + query.setParameter("coachId", coachId); + Long count = (Long)query.uniqueResult(); - session.beginTransaction(); - session.save(user); - session.getTransaction().commit(); + if (count != 0){ + System.out.println("+++++++++++++++++++++++++++该工号已占用+++++++++++++++++++++"); + return false; + }else{ + return true; + } + } + } + public void insertUsers(User user) throws SQLException { + Session session = getSessionFactory().openSession(); + session.beginTransaction(); + User user_insert = new User(); + user_insert.setId(user.getId()); + user_insert.setName(user.getName()); + user_insert.setPassword(passwordEncryption.encodeByMD5(user.getPassword())); + user_insert.setEmployee(user.getEmployee()); + session.save(user_insert); + session.getTransaction().commit(); + session.close(); } public void deleteUsers(int id) throws SQLException { - Session session = HibernateUtil.getSessionFactory().openSession(); + Session session = getSessionFactory().openSession(); session.beginTransaction(); User user = new User(); @@ -61,72 +79,66 @@ public void deleteUsers(int id) throws SQLException { session.delete(user); session.getTransaction().commit(); + session.close(); } - - - public User getOneUser(int id) throws SQLException{ - Session session = HibernateUtil.getSessionFactory().openSession(); + Session session = getSessionFactory().openSession(); session.beginTransaction(); - User user = (User)session.get(User.class,id); //此处User是类名,而不是数据库的表名,select * 不写 - + User user = (User)session.get(User.class,id); + session.close(); + return user; + } + public void UpdateOneUser(User user) throws SQLException{ + Session session = getSessionFactory().openSession(); + session.beginTransaction(); -// DBConnection dbConnection = new DBConnection(); -// Connection connection = dbConnection.getConnection(); -// -// String sql = "FROM User WHERE id=?"; -// PreparedStatement statement = connection.prepareStatement(sql); -// statement.setInt(1, id); -// -// ResultSet rs = statement.executeQuery(); -// -// User user = new User(); -// if (rs.next()){ -// user.setId(rs.getInt("id")); -// user.setName(rs.getString("name")); -// user.setSex(rs.getString("sex")); -// user.setEmail(rs.getString("email")); -// user.setAge(rs.getInt("age")); -// } + User user_update = new User(); + user_update.setId(user.getId()); + user_update.setName(user.getName()); + user_update.setPassword(passwordEncryption.encodeByMD5(user.getPassword())); + user_update.setEmployee(user.getEmployee()); - return user; + session.update(user_update); + session.getTransaction().commit(); + session.close(); } - public void UpdateOneUser(User user) throws SQLException{ + public boolean login (String name, String password) throws SQLException{ - Session session = HibernateUtil.getSessionFactory().openSession(); + Session session = getSessionFactory().openSession(); + session.beginTransaction(); - User user_update = new User(); - if (null != user) { - user_update.setId(user.getId()); - user_update.setName(user.getName()); - user_update.setSex(user.getSex()); - user_update.setEmail(user.getEmail()); - user_update.setAge(user.getAge()); - - session.beginTransaction(); - session.update(user_update); - session.getTransaction().commit(); - } + password = passwordEncryption.encodeByMD5(password); - } + Query query = session.createQuery("SELECT count(*) FROM User user where user.name = :name and user.password = :password"); + query.setParameter("name", name); + query.setParameter("password",password); + Long count = (Long)query.uniqueResult(); + System.out.println(count); + if (count == 0){ + return false; + } + session.getTransaction().commit(); + session.close(); + return true; + } -// public static void main(String[] args) throws SQLException { -// UserDao daos = new UserDao(); -// daos.getUsers(); -// } + public static void main(String agrs[]) throws SQLException{ + UserDao userdao = new UserDao(); + System.out.println(userdao.login("admin1", "123")); + } } diff --git a/core/src/main/java/com/tw/core/Util/CookieUtil.java b/core/src/main/java/com/tw/core/Util/CookieUtil.java new file mode 100644 index 0000000..af61977 --- /dev/null +++ b/core/src/main/java/com/tw/core/Util/CookieUtil.java @@ -0,0 +1,45 @@ +package com.tw.core.Util; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class CookieUtil { + + public static void saveCookie(String cookieName, String value, HttpServletResponse response) { + Cookie cookie = new Cookie(cookieName, value); + cookie.setPath("/"); + response.addCookie(cookie); + } + + public static String getCookie(String cookieName, HttpServletRequest request) { + String cookieValue = null; + Cookie[] cookies = request.getCookies(); + Cookie c = null; + + if (cookies != null) { + for (int i = 0; i < cookies.length; i++) { + c = cookies[i]; + if (c.getName().equals(cookieName)) { + cookieValue = c.getValue(); + } + } + } + return cookieValue; + } + + public static void deleteCookie( HttpServletRequest request,HttpServletResponse response) { + Cookie[] cookies = request.getCookies(); + Cookie c = null; + if (cookies != null) { + for (int i = 0; i < cookies.length; i++) { + c = cookies[i]; + if (c != null) { + c.setMaxAge(0); + c.setPath("/"); + response.addCookie(c); + } + } + } + } +} diff --git a/core/src/main/java/com/tw/core/Util/HibernateUtil.java b/core/src/main/java/com/tw/core/Util/HibernateUtil.java index e2fbd8a..7bd6652 100644 --- a/core/src/main/java/com/tw/core/Util/HibernateUtil.java +++ b/core/src/main/java/com/tw/core/Util/HibernateUtil.java @@ -5,9 +5,6 @@ import org.hibernate.cfg.Configuration; -/** - * Created by twer on 7/10/15. - */ public class HibernateUtil { private static SessionFactory sessionFactory ; diff --git a/core/src/main/java/com/tw/core/controller/CourseController.java b/core/src/main/java/com/tw/core/controller/CourseController.java new file mode 100644 index 0000000..2cf7522 --- /dev/null +++ b/core/src/main/java/com/tw/core/controller/CourseController.java @@ -0,0 +1,122 @@ +package com.tw.core.controller; + +import com.tw.core.entity.Course; +import com.tw.core.service.CourseService; +import org.json.JSONException; +import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.sql.SQLException; +import java.util.List; + +@Controller +@RequestMapping("/course") +public class CourseController { + @Autowired + private CourseService courseService; + + + @RequestMapping(method = RequestMethod.GET) + public ModelAndView getCourses() { + + ModelAndView modelAndView = new ModelAndView(); + modelAndView.setViewName("course"); + modelAndView.addObject("courseList", courseService.getCourses()); + return modelAndView; + + } + +// +// @RequestMapping(method = RequestMethod.GET) +// public @ResponseBody List getCourses() { +// +// List courseList = courseService.getCourses(); +// return courseList; +// +// } + + @RequestMapping(method = RequestMethod.POST) + public @ResponseBody Course insertCourse(@RequestParam(value = "courseName") String courseName, + @RequestParam(value = "description") String description) throws SQLException { + + System.out.println("#################"); + + Course course = new Course(courseName, description); + courseService.insertCourse(course); + return course; + } + +// @RequestMapping(value = "/insert", method = RequestMethod.POST) +// public ModelAndView insertCourse(@RequestParam(value = "courseName") String courseName, +// @RequestParam(value = "description") String description, +// HttpSession session) throws SQLException { +// +// if (session.getAttribute("user") != null) { +// +// Course course = new Course(courseName,description); +// courseService.insertCourse(course); +// +// return new ModelAndView("redirect:" + "/course"); +// } else { +// return new ModelAndView("redirect:" + "/login"); +// } +// } + + + @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) + public + @ResponseBody + void deleteCourse(@PathVariable int id) { + + courseService.deleteCourse(id); + } + + +// @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET) +// public ModelAndView deleteCourse(@PathVariable("id") String id,HttpSession session) throws SQLException { +// if (session.getAttribute("user") != null) { +// courseService.deleteCourse(Integer.parseInt(id)); +// return new ModelAndView("redirect:" + "/course"); +// } else { +// return new ModelAndView("redirect:" + "/login"); +// } +// } + +// @RequestMapping(value = "/modify/{id}", method = RequestMethod.GET) +// public ModelAndView getOneCourse(@PathVariable("id") String id, HttpSession session) throws SQLException { +// +// if (session.getAttribute("user") != null) { +// return new ModelAndView("modifyCourse", "course", courseService.getOneCourse(Integer.parseInt(id))); +// } else { +// return new ModelAndView("redirect:" + "/login"); +// } +// } + + + @RequestMapping(value = "/update", method = RequestMethod.PUT) + public @ResponseBody Course updateOneCourse(@RequestParam(value = "id") int id, + @RequestParam(value = "courseName") String courseName, + @RequestParam(value = "description") String description) { + + System.out.println("###########"); + Course course = new Course(id, courseName, description); + courseService.updateOneCourse(course); + System.out.println(course.getId()); + System.out.println(course.getCourseName()); + System.out.println(course.getDescription()); +// course = courseService.getOneCourse(id); + +// JSONObject courseJson = new JSONObject("{'id':'"+course.getId()+ +// "','courseName':'" + course.getCourseName() + +// "','description':'" + course.getDescription()+"'}"); +// response.setContentType("text/html;charset=utf-8"); +// response.getWriter().write(courseJson.toString()); + return course; + } +} diff --git a/core/src/main/java/com/tw/core/controller/CustomerController.java b/core/src/main/java/com/tw/core/controller/CustomerController.java new file mode 100644 index 0000000..13d325d --- /dev/null +++ b/core/src/main/java/com/tw/core/controller/CustomerController.java @@ -0,0 +1,105 @@ +package com.tw.core.controller; + +import com.tw.core.Util.CookieUtil; +import com.tw.core.entity.Customer; +import com.tw.core.entity.Employee; +import com.tw.core.entity.User; +import com.tw.core.service.CoachService; +import com.tw.core.service.CustomerService; +import com.tw.core.service.EmployeeService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.sql.SQLException; + +@Controller +@RequestMapping("/customer") +public class CustomerController { + + @Autowired + private CustomerService customerService; + + @Autowired + private EmployeeService employeeService; + + @Autowired + private CoachService coachService; + + @RequestMapping(method =RequestMethod.GET) + public ModelAndView getCustomers(HttpSession session,HttpServletResponse response){ + + if (session.getAttribute("user") != null) { + ModelAndView modelAndView = new ModelAndView(); + modelAndView.setViewName("customer"); + modelAndView.addObject("customerList", customerService.getCustomers()); + modelAndView.addObject("coachList",coachService.getCoaches()); + return modelAndView; + } else { + CookieUtil.saveCookie("previousURL", "/customer", response); + return new ModelAndView("redirect:"+"/login"); + } + } + + + @RequestMapping(value = "/insert", method = RequestMethod.POST) + public ModelAndView insertUser(@RequestParam(value = "customerName") String customerName, + HttpSession session) throws SQLException { + + if (session.getAttribute("user") != null) { + + Customer customer = new Customer(customerName); + customerService.insertCustomer(customer); + + return new ModelAndView("redirect:" + "/customer"); + } else { + return new ModelAndView("redirect:" + "/login"); + } + } + + @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET) + public ModelAndView deleteCustomer(@PathVariable("id") String id,HttpSession session) throws SQLException { + if (session.getAttribute("user") != null) { + customerService.deleteCustomer(Integer.parseInt(id)); + return new ModelAndView("redirect:" + "/customer"); + } else { + return new ModelAndView("redirect:" + "/login"); + } + } + + @RequestMapping(value = "/modify/{id}", method = RequestMethod.GET) + public ModelAndView getOneCustomer(@PathVariable("id") String id, HttpSession session) throws SQLException { + + if (session.getAttribute("user") != null) { + return new ModelAndView("modifyCustomer", "customer",customerService.getOneCustomer(Integer.parseInt(id))); + } else { + return new ModelAndView("redirect:" + "/login"); + } + } + + @RequestMapping(value = "/modify/{id}", method = RequestMethod.POST) + public ModelAndView updateOneCustomer(@PathVariable("id") String id, + @RequestParam(value = "customerName") String customerName, + HttpSession session) { + + + if (session.getAttribute("user") != null) { + + Customer customer = new Customer(); + customer.setId(Integer.parseInt(id)); + customer.setCustomerName(customerName); + customerService.UpdateOneCustomer(customer); + + return new ModelAndView("redirect:" + "/customer"); + } else { + return new ModelAndView("redirect:" + "/login"); + } + } + +} diff --git a/core/src/main/java/com/tw/core/controller/EmployeeController.java b/core/src/main/java/com/tw/core/controller/EmployeeController.java new file mode 100644 index 0000000..9fa4c5c --- /dev/null +++ b/core/src/main/java/com/tw/core/controller/EmployeeController.java @@ -0,0 +1,92 @@ +package com.tw.core.controller; + +import com.tw.core.Util.CookieUtil; +import com.tw.core.entity.Employee; +import com.tw.core.service.EmployeeService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.sql.SQLException; + +/** + * Created by twer on 7/19/15. + */ + +@Controller +@RequestMapping("/employee") +public class EmployeeController { + + @Autowired + private EmployeeService employeeService; + + @RequestMapping(method =RequestMethod.GET) + public ModelAndView getEmployees(HttpSession session,HttpServletResponse response){ + + if (session.getAttribute("user") != null) { + return new ModelAndView("employee","employeeList",employeeService.getEmployees()); + } else { + CookieUtil.saveCookie("previousURL", "/employee", response); + return new ModelAndView("redirect:"+"/login"); + } + } + + + @RequestMapping(value = "/insert", method = RequestMethod.POST) + public ModelAndView insertUser(@RequestParam(value = "name") String name, + @RequestParam(value = "sex") String sex, + @RequestParam(value = "age") int age, + @RequestParam(value = "email") String email, + @RequestParam(value = "role") String role, + @RequestParam(value = "state") String state, + HttpSession session) throws SQLException { + + if (session.getAttribute("user") != null) { + Employee employee = new Employee(name,sex,age,email,role,state); + employeeService.insertEmployee(employee); + return new ModelAndView("redirect:" + "/employee"); + } else { + return new ModelAndView("redirect:" + "/login"); + } + } + + @RequestMapping(value = "/modify/{id}", method = RequestMethod.GET) + public ModelAndView getOneEmployee(@PathVariable("id") String id, HttpSession session) throws SQLException { + + if (session.getAttribute("user") != null) { + int idd = Integer.parseInt(id); + System.out.println(idd); + return new ModelAndView("modifyEmployee", "employee",employeeService.getOneEmployee(idd)); + } else { + return new ModelAndView("redirect:" + "/login"); + } + } + + @RequestMapping(value = "/modify/{id}", method = RequestMethod.POST) + public ModelAndView updateOneUser(@PathVariable("id") String id, + @RequestParam(value = "name") String name, + @RequestParam(value = "sex") String sex, + @RequestParam(value = "age") int age, + @RequestParam(value = "email") String email, + @RequestParam(value = "role") String role, + @RequestParam(value = "state") String state, + HttpSession session) { + + + if (session.getAttribute("user") != null) { + Employee employee = new Employee(Integer.parseInt(id),name,sex,age,email,role,state); + + employeeService.UpdateOneEmployee(employee); + return new ModelAndView("redirect:" + "/employee"); + } else { + return new ModelAndView("redirect:" + "/login"); + } + } + +} diff --git a/core/src/main/java/com/tw/core/controller/IndexController.java b/core/src/main/java/com/tw/core/controller/IndexController.java new file mode 100644 index 0000000..5f4bbcf --- /dev/null +++ b/core/src/main/java/com/tw/core/controller/IndexController.java @@ -0,0 +1,17 @@ +package com.tw.core.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + + +@Controller +@RequestMapping("/") +public class IndexController { + + @RequestMapping(method = RequestMethod.GET) + public ModelAndView getIndex(){ + return new ModelAndView("index"); + } +} diff --git a/core/src/main/java/com/tw/core/controller/LoginController.java b/core/src/main/java/com/tw/core/controller/LoginController.java new file mode 100644 index 0000000..400fa2e --- /dev/null +++ b/core/src/main/java/com/tw/core/controller/LoginController.java @@ -0,0 +1,61 @@ +package com.tw.core.controller; + +import com.tw.core.Util.CookieUtil; +import com.tw.core.service.UserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.sql.SQLException; + + +@Controller +@RequestMapping("/login") +public class LoginController { + @Autowired + private UserService userService; + + + @RequestMapping( method = RequestMethod.GET) + public ModelAndView getLoginPage() { + + ModelAndView modelAndView = new ModelAndView(); + modelAndView.setViewName("login"); + return modelAndView; + } + + + @RequestMapping( method = RequestMethod.POST) + public ModelAndView logIn(@RequestParam(value = "name") String name, + @RequestParam(value = "password") String password, + HttpSession session, + HttpServletRequest request, + HttpServletResponse response) throws SQLException { + + if (userService.login(name, password)) { + session.setAttribute("user", name ); + String previousURL = CookieUtil.getCookie("previousURL", request); + if (previousURL != null){ + CookieUtil.deleteCookie(request,response); + return new ModelAndView("redirect:" + previousURL); + }else{ + return new ModelAndView("redirect:"+"/"); + } + } else { + return new ModelAndView("loginError"); + } + } + + + @RequestMapping(value = "/logout", method = RequestMethod.GET) + public ModelAndView destroySession(HttpServletRequest request){ + request.getSession().invalidate(); + return new ModelAndView("redirect:"+"/"); + } +} diff --git a/core/src/main/java/com/tw/core/controller/RegisterController.java b/core/src/main/java/com/tw/core/controller/RegisterController.java new file mode 100644 index 0000000..b862d06 --- /dev/null +++ b/core/src/main/java/com/tw/core/controller/RegisterController.java @@ -0,0 +1,52 @@ +package com.tw.core.controller; + +import com.tw.core.entity.Employee; +import com.tw.core.entity.User; +import com.tw.core.service.EmployeeService; +import com.tw.core.service.UserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.servlet.ModelAndView; + +import java.sql.SQLException; + + +@Controller +@RequestMapping("/users/insert") +public class RegisterController { + + @Autowired + private UserService userService; + + @Autowired + private EmployeeService employeeService; + + @RequestMapping(method = RequestMethod.GET) + public ModelAndView insertUser() throws SQLException { + + return new ModelAndView("insert"); + } + + @RequestMapping(method = RequestMethod.POST) + public ModelAndView insertUser(@RequestParam(value = "name") String userName, + @RequestParam(value = "password") String userPassword, + @RequestParam(value = "employeeId") int employeeId) throws SQLException { + + User user = new User(); + user.setName(userName); + user.setPassword(userPassword); + Employee employee = employeeService.getOneEmployee(employeeId); + user.setEmployee(employee); + + if (userService.verifyRegister(user)){ + userService.insertUsers(user); + return new ModelAndView("redirect:" + "/users"); + }else { + return new ModelAndView("redirect:" + "/users/insert"); + } + + } +} diff --git a/core/src/main/java/com/tw/core/controller/ScheduleController.java b/core/src/main/java/com/tw/core/controller/ScheduleController.java new file mode 100644 index 0000000..42bf31e --- /dev/null +++ b/core/src/main/java/com/tw/core/controller/ScheduleController.java @@ -0,0 +1,114 @@ +package com.tw.core.controller; + +import com.tw.core.Util.CookieUtil; +import com.tw.core.entity.Schedule; +import com.tw.core.service.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.sql.SQLException; + +@Controller +@RequestMapping("/schedule") +public class ScheduleController { + @Autowired + private ScheduleService scheduleService; + + @Autowired + private CourseService courseService; + + @Autowired + private CoachService coachService; + + @Autowired + private CustomerService customerService; + + @Autowired + private EmployeeService employeeService; + + @RequestMapping(method = RequestMethod.GET) + public ModelAndView getSchedules(HttpSession session,HttpServletResponse response) { + + if (session.getAttribute("user") != null) { + ModelAndView modelAndView = new ModelAndView(); + modelAndView.setViewName("schedule"); + modelAndView.addObject("scheduleList", scheduleService.getSchedules()); + modelAndView.addObject("courseList", courseService.getCourses()); + modelAndView.addObject("coachList",coachService.getCoaches()); + modelAndView.addObject("customerList", customerService.getCustomers()); + return modelAndView; + } else { + CookieUtil.saveCookie("previousURL", "/schedule", response); + return new ModelAndView("redirect:"+"/login"); + } + + } + + @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET) + public ModelAndView deleteSchedule(@PathVariable("id") String id, + HttpSession session) throws SQLException { + if (session.getAttribute("user") != null) { + scheduleService.deleteSchedule(Integer.parseInt(id)); + return new ModelAndView("redirect:" + "/schedule"); + } else { + return new ModelAndView("redirect:" + "/login"); + } + } + + @RequestMapping(value = "/insert", method = RequestMethod.POST) + public ModelAndView insertSchedule(@RequestParam(value = "courseId") int courseId, + @RequestParam(value = "coachId") int coachId, + @RequestParam(value = "time") String time, + @RequestParam(value = "customer") String customer, + HttpSession session) throws SQLException { + + if (session.getAttribute("user") != null) { + Schedule schedule = new Schedule(courseService.getOneCourse(courseId),employeeService.getOneEmployee(coachId),time,customer); + scheduleService.insertSchedule(schedule); + return new ModelAndView("redirect:" + "/schedule"); + } else { + return new ModelAndView("redirect:" + "/login"); + } + } + + @RequestMapping(value = "/modify/{id}", method = RequestMethod.GET) + public ModelAndView modifySchedule(@PathVariable("id") String id, + HttpSession session) throws SQLException { + if (session.getAttribute("user") != null) { + ModelAndView modelAndView = new ModelAndView(); + modelAndView.setViewName("modifySchedule"); + modelAndView.addObject("schedule", scheduleService.getOneSchedule(Integer.parseInt(id))); + modelAndView.addObject("courseList",courseService.getCourses()); + modelAndView.addObject("coachList",coachService.getCoaches()); + modelAndView.addObject("customerList",customerService.getCustomers()); + return modelAndView; + } else { + return new ModelAndView("redirect:" + "/login"); + } + } + + + @RequestMapping(value = "/modify/{id}", method = RequestMethod.POST) + public ModelAndView modifySchedule(@PathVariable("id") String id, + @RequestParam(value = "courseId") int courseId, + @RequestParam(value = "coachId") int coachId, + @RequestParam(value = "time") String time, + @RequestParam(value = "customer") String customer, + HttpSession session) throws SQLException { + + if (session.getAttribute("user") != null) { + Schedule schedule = new Schedule(Integer.parseInt(id),courseService.getOneCourse(courseId),employeeService.getOneEmployee(coachId),time,customer); + scheduleService.updateOneSchedule(schedule); + return new ModelAndView("redirect:" + "/schedule"); + } else { + return new ModelAndView("redirect:" + "/login"); + } + } +} diff --git a/core/src/main/java/com/tw/core/controller/UserController.java b/core/src/main/java/com/tw/core/controller/UserController.java new file mode 100644 index 0000000..fc1f2e6 --- /dev/null +++ b/core/src/main/java/com/tw/core/controller/UserController.java @@ -0,0 +1,91 @@ + +package com.tw.core.controller; + +import com.tw.core.Util.CookieUtil; +import com.tw.core.entity.Employee; +import com.tw.core.entity.User; +import com.tw.core.service.EmployeeService; +import com.tw.core.service.UserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + + +@Controller +@RequestMapping("/users") +public class UserController { + + @Autowired + private UserService userService; + + @Autowired + private EmployeeService employeeService; + Map data = new HashMap(); + + + @RequestMapping(method = RequestMethod.GET) + public ModelAndView getUsers(HttpSession session,HttpServletResponse response) { + + if (session.getAttribute("user") != null) { + return new ModelAndView("userInformation","userList",userService.getUsers()); + } else { + CookieUtil.saveCookie("previousURL", "/users", response); + return new ModelAndView("redirect:"+"/login"); + } + + } + + + @RequestMapping(value = "/delete", method = RequestMethod.GET) + public ModelAndView deleteUser(@RequestParam(value = "id") int id, HttpSession session) throws SQLException { + if (session.getAttribute("user") != null) { + userService.deleteUsers(id); + return new ModelAndView("redirect:" + "/users"); + } else { + return new ModelAndView("redirect:" + "/login"); + } + } + + + @RequestMapping(value = "/modify", method = RequestMethod.GET) + public ModelAndView getOneUser(@RequestParam(value = "id") int id, HttpSession session,HttpServletResponse response) throws SQLException { + if (session.getAttribute("user") != null) { + return new ModelAndView("modify", "user",userService.getOneUser(id)); + } else { + return new ModelAndView("redirect:" + "/login"); + } + } + + @RequestMapping(value = "/modify", method = RequestMethod.POST) + public ModelAndView updateOneUser(@RequestParam(value = "id") int userId, + @RequestParam(value = "name") String userName, + @RequestParam(value = "password") String userPassword, + @RequestParam(value = "employeeId") int employeeId, + HttpSession session) { + if (session.getAttribute("user") != null) { + User user = new User(); + user.setId(userId); + user.setName(userName); + user.setPassword(userPassword); + Employee employee = employeeService.getOneEmployee(employeeId); + user.setEmployee(employee); + + userService.UpdateOneUser(user); + return new ModelAndView("redirect:" + "/users"); + } else { + return new ModelAndView("redirect:" + "/login"); + } + } + + + +} \ No newline at end of file diff --git a/core/src/main/java/com/tw/core/entity/Coach.java b/core/src/main/java/com/tw/core/entity/Coach.java new file mode 100644 index 0000000..c583481 --- /dev/null +++ b/core/src/main/java/com/tw/core/entity/Coach.java @@ -0,0 +1,11 @@ +package com.tw.core.entity; + +public class Coach extends Employee { + private int id; + private String name; + private String sex; + private int age; + private String email; + private String role; + private String state; +} diff --git a/core/src/main/java/com/tw/core/entity/Course.java b/core/src/main/java/com/tw/core/entity/Course.java new file mode 100644 index 0000000..646c795 --- /dev/null +++ b/core/src/main/java/com/tw/core/entity/Course.java @@ -0,0 +1,55 @@ +package com.tw.core.entity; + +import javax.persistence.*; + +@Entity +@Table(name = "Course") +public class Course { + + private int id; + private String courseName; + private String description; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Column(name = "courseName") + public String getCourseName() { + return courseName; + } + + public void setCourseName(String courseName) { + this.courseName = courseName; + } + + @Column(name = "description") + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + + public Course() { + } + + public Course(int id, String courseName, String description) { + this.id = id; + this.courseName = courseName; + this.description = description; + } + + public Course(String courseName, String description) { + this.courseName = courseName; + this.description = description; + } +} diff --git a/core/src/main/java/com/tw/core/entity/Customer.java b/core/src/main/java/com/tw/core/entity/Customer.java new file mode 100644 index 0000000..12e64ed --- /dev/null +++ b/core/src/main/java/com/tw/core/entity/Customer.java @@ -0,0 +1,40 @@ +package com.tw.core.entity; + +import javax.persistence.*; + +@Entity +@Table(name = "Customer") +public class Customer { + + private int id; + private String customerName; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + public int getId() { + return id; + } + public void setId(int id) { + this.id = id; + } + + @Column(name = "customerName") + public String getCustomerName() { + return customerName; + } + public void setCustomerName(String customerName) { + this.customerName = customerName; + } + + public Customer() { + } + + public Customer(int id, String customerName) { + this.id = id; + this.customerName = customerName; + } + + public Customer(String customerName) { + this.customerName = customerName; + } +} diff --git a/core/src/main/java/com/tw/core/entity/Employee.java b/core/src/main/java/com/tw/core/entity/Employee.java new file mode 100644 index 0000000..ccc9fce --- /dev/null +++ b/core/src/main/java/com/tw/core/entity/Employee.java @@ -0,0 +1,102 @@ +package com.tw.core.entity; + +import javax.persistence.*; + + +@Entity +@Table(name = "Employee") +public class Employee { + private int id; + private String name; + private String sex; + private int age; + private String email; + private String role; + private String state; + + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Column(name = "name") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Column(name = "sex") + public String getSex() { + return sex; + } + + public void setSex(String sex) { + this.sex = sex; + } + + @Column(name = "age") + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + @Column(name = "email") + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + @Column(name = "role") + public String getRole() { + return role; + } + public void setRole(String role) { + this.role = role; + } + + @Column(name = "state") + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } + + public Employee() { + } + + public Employee(String name, String sex, int age, String email, String role, String state) { + this.name = name; + this.sex = sex; + this.age = age; + this.email = email; + this.role = role; + this.state = state; + } + + public Employee(int id, String name, String sex, int age, String email, String role, String state) { + this.id = id; + this.name = name; + this.sex = sex; + this.age = age; + this.email = email; + this.role = role; + this.state = state; + } +} diff --git a/core/src/main/java/com/tw/core/entity/Schedule.java b/core/src/main/java/com/tw/core/entity/Schedule.java new file mode 100644 index 0000000..7b68496 --- /dev/null +++ b/core/src/main/java/com/tw/core/entity/Schedule.java @@ -0,0 +1,82 @@ +package com.tw.core.entity; + +import javax.persistence.*; + +@Entity +@Table(name = "Schedule") +public class Schedule { + private int id; + private Course course; + private Employee employee; + private String time; + private String customer; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "courseId") + public Course getCourse() { + return course; + } + + public void setCourse(Course course) { + this.course = course; + } + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "coachId") + public Employee getEmployee() { + return employee; + } + + public void setEmployee(Employee employee) { + this.employee = employee; + } + + @Column(name = "time") + public String getTime() { + return time; + } + + public void setTime(String time) { + this.time = time; + } + + @Column(name = "customer") + public String getCustomer() { + return customer; + } + + public void setCustomer(String customer) { + this.customer = customer; + } + + + public Schedule() { + } + + public Schedule(Course course, Employee employee, String time, String customer) { + this.course = course; + this.employee = employee; + this.time = time; + this.customer = customer; + } + + + public Schedule(int id, Course course, Employee employee, String time, String customer) { + this.id = id; + this.course = course; + this.employee = employee; + this.time = time; + this.customer = customer; + } +} diff --git a/core/src/main/java/com/tw/core/entity/User.java b/core/src/main/java/com/tw/core/entity/User.java index da43d04..5bf5c5b 100644 --- a/core/src/main/java/com/tw/core/entity/User.java +++ b/core/src/main/java/com/tw/core/entity/User.java @@ -5,140 +5,56 @@ * Created by twer on 7/7/15. */ +@Entity //@Entity 注解将一个类声明为实体 Bean +@Table(name = "User") - - @Entity - @Table(name = "userInfo") - - - public class User { - - @Id @GeneratedValue(strategy = GenerationType.AUTO) - @Column(name = "id") // 非必要,在欄位名稱與屬性名稱不同時使用 +public class User { private int id; - - @Column(name = "name") // 非必要,在欄位名稱與屬性名稱不同時使用 private String name; + private String password; + private Employee employee; - @Column(name = "sex") // 非必要,在欄位名稱與屬性名稱不同時使用 - private String sex; - - @Column(name = "email") // 非必要,在欄位名稱與屬性名稱不同時使用 - private String email; - @Column(name = "age") // 非必要,在欄位名稱與屬性名稱不同時使用 - private int age; - - // 必須要有一個預設的建構方法 - // 以使得Hibernate可以使用Constructor.newInstance()建立物件 - public User() { + @Id //@Id 注解声明了该实体Bean的标识属性 + @GeneratedValue(strategy = GenerationType.AUTO) //@Id 注解可将实体Bean中某个属性定义为主键,使用@GenerateValue注解可以定义该标识符的生成策略。 + public int getId() { + return id; } - public User(int id, String name, String sex, String email, int age) { + public void setId(int id) { this.id = id; - this.name = name; - this.sex = sex; - this.email = email; - this.age = age; } - public void setId(int id) { - this.id = id; + @Column(name = "name") + public String getName() { + return name; } public void setName(String name) { this.name = name; } - public void setSex(String sex) { - this.sex = sex; + @Column(name = "password") + public String getPassword() { + return password; } - public void setEmail(String email) { - this.email = email; + public void setPassword(String password) { + this.password = password; } - public void setAge(int age) { - this.age = age; - } - - - - public int getId() { - return id; + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name="employeeId") + public Employee getEmployee() { + return employee; } - - public String getName() { - return name; + public void setEmployee(Employee employee) { + this.employee = employee; } +} - public String getSex() { - return sex; - } - public String getEmail() { - return email; - } - - public int getAge() { - return age; - } -} -// public class User { -// private int id; -// private String name; -// private String sex; -// private String email; -// private int age; -// -// public User(int id, String name, String sex, String email, int age) { -// this.id = id; -// this.name = name; -// this.sex = sex; -// this.email = email; -// this.age = age; -// } -// -// public User(){ -// -// } -// -// public int getId(){return id;} -// public void setId(int id){this.id = id;} -// -// public String getName() { -// return name; -// } -// -// public void setName(String name) { -// this.name = name; -// } -// -// public String getSex() { -// return sex; -// } -// -// public void setSex(String sex) { -// this.sex = sex; -// } -// -// public String getEmail() { -// return email; -// } -// -// public void setEmail(String email) { -// this.email = email; -// } -// -// public int getAge() { -// return age; -// } -// -// public void setAge(int age) { -// this.age = age; -// } -//} diff --git a/core/src/main/java/com/tw/core/service/CoachService.java b/core/src/main/java/com/tw/core/service/CoachService.java new file mode 100644 index 0000000..3260f12 --- /dev/null +++ b/core/src/main/java/com/tw/core/service/CoachService.java @@ -0,0 +1,27 @@ +package com.tw.core.service; + +import com.tw.core.Dao.CoachDao; +import com.tw.core.entity.Coach; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.sql.SQLException; +import java.util.List; + + +@Service +public class CoachService { + + @Autowired + private CoachDao coachDao; + + public List getCoaches(){ + try { + return coachDao.getCoaches(); + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + +} diff --git a/core/src/main/java/com/tw/core/service/CourseService.java b/core/src/main/java/com/tw/core/service/CourseService.java new file mode 100644 index 0000000..4279ea8 --- /dev/null +++ b/core/src/main/java/com/tw/core/service/CourseService.java @@ -0,0 +1,59 @@ +package com.tw.core.service; + +import com.tw.core.Dao.CourseDao; +import com.tw.core.entity.Course; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.sql.SQLException; +import java.util.List; + +@Service +public class CourseService { + + @Autowired + private CourseDao courseDao; + + public List getCourses(){ + try { + return courseDao.getCourses(); + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + + public void deleteCourse(int id){ + try { + courseDao.deleteCourse(id); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public Course getOneCourse(int id){ + try{ + return courseDao.getOneCourse(id); + }catch (SQLException e){ + e.printStackTrace(); + } + return null; + } + + public void updateOneCourse(Course course){ + try{ + courseDao.UpdateOneCourse(course); + }catch (SQLException e){ + e.printStackTrace(); + } + } + + + public void insertCourse(Course course){ + try { + courseDao.insertCourse(course); + } catch (SQLException e) { + e.printStackTrace(); + } + } +} diff --git a/core/src/main/java/com/tw/core/service/CustomerService.java b/core/src/main/java/com/tw/core/service/CustomerService.java new file mode 100644 index 0000000..099a0f5 --- /dev/null +++ b/core/src/main/java/com/tw/core/service/CustomerService.java @@ -0,0 +1,60 @@ +package com.tw.core.service; + +import com.tw.core.Dao.CustomerDao; +import com.tw.core.entity.Customer; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.sql.SQLException; +import java.util.List; + +@Service +public class CustomerService { + + @Autowired + private CustomerDao customerDao; + + public List getCustomers(){ + try { + return customerDao.getCustomers(); + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + + + public void insertCustomer(Customer customer){ + try { + customerDao.insertCustomer(customer); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public void deleteCustomer(int id){ + try { + customerDao.deleteCustomer(id); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public Customer getOneCustomer(int id){ + try{ + return customerDao.getOneCustomer(id); + }catch (SQLException e){ + e.printStackTrace(); + } + return null; + } + + public void UpdateOneCustomer(Customer customer){ + try{ + customerDao.UpdateOneCustomer(customer); + }catch (SQLException e){ + e.printStackTrace(); + } + } + +} diff --git a/core/src/main/java/com/tw/core/service/EmployeeService.java b/core/src/main/java/com/tw/core/service/EmployeeService.java new file mode 100644 index 0000000..a2101c9 --- /dev/null +++ b/core/src/main/java/com/tw/core/service/EmployeeService.java @@ -0,0 +1,56 @@ +package com.tw.core.service; + +import com.tw.core.Dao.EmployeeDao; +import com.tw.core.entity.Employee; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.sql.SQLException; +import java.util.List; + + +@Service +public class EmployeeService { + @Autowired + private EmployeeDao employeeDao; + + public List getEmployees(){ + try { + return employeeDao.getEmployees(); + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + + public void insertEmployee(Employee employee){ + try { + employeeDao.insertEmployee(employee); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public Employee getOneEmployee(int id){ + try{ + return employeeDao.getOneEmployee(id); + }catch (SQLException e){ + e.printStackTrace(); + } + return null; + } + + public void UpdateOneEmployee(Employee employee){ + try{ + employeeDao.UpdateOneEmployee(employee); + }catch (SQLException e){ + e.printStackTrace(); + } + } +// +// public static void main(String arg[]) throws SQLException{ +// EmployeeService employeeService = new EmployeeService(); +// System.out.println(employeeService.getEmployees()); +// +// } +} diff --git a/core/src/main/java/com/tw/core/service/ScheduleService.java b/core/src/main/java/com/tw/core/service/ScheduleService.java new file mode 100644 index 0000000..ca09226 --- /dev/null +++ b/core/src/main/java/com/tw/core/service/ScheduleService.java @@ -0,0 +1,61 @@ +package com.tw.core.service; + +import com.tw.core.Dao.ScheduleDao; +import com.tw.core.entity.Employee; +import com.tw.core.entity.Schedule; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.sql.SQLException; +import java.util.List; + +@Service +public class ScheduleService { + + @Autowired + private ScheduleDao scheduleDao; + + public List getSchedules(){ + try { + return scheduleDao.getSchedules(); + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + + public void deleteSchedule(int id){ + try { + scheduleDao.deleteSchedule(id); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + + public void insertSchedule(Schedule schedule){ + try { + scheduleDao.insertSchedule(schedule); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + + public Schedule getOneSchedule(int id){ + try{ + return scheduleDao.getOneSchedule(id); + }catch (SQLException e){ + e.printStackTrace(); + } + return null; + } + + public void updateOneSchedule(Schedule schedule){ + try{ + scheduleDao.updateOneSchedule(schedule); + }catch (SQLException e){ + e.printStackTrace(); + } + } +} diff --git a/core/src/main/java/com/tw/core/service/UserService.java b/core/src/main/java/com/tw/core/service/UserService.java index 034f5e0..93a9367 100644 --- a/core/src/main/java/com/tw/core/service/UserService.java +++ b/core/src/main/java/com/tw/core/service/UserService.java @@ -2,19 +2,41 @@ import com.tw.core.Dao.UserDao; import com.tw.core.entity.User; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; import java.sql.SQLException; +import java.util.List; -/** - * Created by twer on 7/8/15. - */ + +@Service public class UserService { - UserDao userDao = new UserDao(); + @Autowired + private UserDao userDao; + + public List getUsers(){ + try { + return userDao.getUsers(); + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + + + public boolean verifyRegister(User user){ + try{ + return userDao.verifyRegister(user); + }catch (SQLException e){ + e.printStackTrace(); + } + return false; + } - public void insertUsers(String name, String sex, String email, int age){ + public void insertUsers(User user){ try { - userDao.insertUsers(name, sex, email, age); + userDao.insertUsers(user); } catch (SQLException e) { e.printStackTrace(); } @@ -28,11 +50,6 @@ public void deleteUsers(int id){ } } - - - - - public User getOneUser(int id){ try{ return userDao.getOneUser(id); @@ -50,4 +67,14 @@ public void UpdateOneUser(User user){ } } + public boolean login (String name, String password){ + try{ + return userDao.login(name,password); + }catch (Exception e){ + e.printStackTrace(); + } + return false; + } + + } diff --git a/core/src/main/resources/db/migration/V1__Create_Employee_table.sql b/core/src/main/resources/db/migration/V1__Create_Employee_table.sql new file mode 100644 index 0000000..b8a6993 --- /dev/null +++ b/core/src/main/resources/db/migration/V1__Create_Employee_table.sql @@ -0,0 +1,16 @@ +create table Employee ( + id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, + name VARCHAR(40) NOT NULL, + sex VARCHAR(40) NOT NULL, + age int NOT NULL, + email VARCHAR(50) NOT NULL, + role VARCHAR(40) NOT NULL, + state VARCHAR(20) NOT NULL +); + + +INSERT INTO Employee (name,sex,age,email,role,state) VALUES ("李一","male",34,"121@qq.com","OPs","YES"); +INSERT INTO Employee (name,sex,age,email,role,state) VALUES ("李二","male",34,"121@qq.com","OPs","YES"); +INSERT INTO Employee (name,sex,age,email,role,state) VALUES ("李三","male",34,"121@qq.com","COACH","YES"); +INSERT INTO Employee (name,sex,age,email,role,state) VALUES ("李四","male",34,"121@qq.com","COACH","YES"); +INSERT INTO Employee (name,sex,age,email,role,state) VALUES ("李舞","male",34,"121@qq.com","COACH","YES"); diff --git a/core/src/main/resources/db/migration/V1__Create_person_table.sql b/core/src/main/resources/db/migration/V1__Create_person_table.sql deleted file mode 100644 index 6d78aed..0000000 --- a/core/src/main/resources/db/migration/V1__Create_person_table.sql +++ /dev/null @@ -1,5 +0,0 @@ - -create table PERSON ( - ID int not null, - NAME varchar(100) not null -); \ No newline at end of file diff --git a/core/src/main/resources/db/migration/V2__Add_people.sql b/core/src/main/resources/db/migration/V2__Add_people.sql deleted file mode 100644 index 0d8ed6f..0000000 --- a/core/src/main/resources/db/migration/V2__Add_people.sql +++ /dev/null @@ -1,3 +0,0 @@ -insert into PERSON (ID, NAME) values (1, 'Axel'); -insert into PERSON (ID, NAME) values (2, 'Mr. Foo'); -insert into PERSON (ID, NAME) values (3, 'Ms. Bar'); \ No newline at end of file diff --git a/core/src/main/resources/db/migration/V2__Create_User_table.sql b/core/src/main/resources/db/migration/V2__Create_User_table.sql new file mode 100644 index 0000000..6898a59 --- /dev/null +++ b/core/src/main/resources/db/migration/V2__Create_User_table.sql @@ -0,0 +1,13 @@ +create table User( + id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, + name VARCHAR(40) NOT NULL, + password VARCHAR(50) NOT NULL, + employeeId INT NOT NULL UNIQUE, + foreign key(employeeId) references Employee(id) on delete cascade on update cascade +); + +INSERT INTO User(name,password,employeeId) VALUES ("admin1","202cb962ac59075b964b07152d234b70",1); +INSERT INTO User(name,password,employeeId) VALUES ("admin2","202cb962ac59075b964b07152d234b70",2); +INSERT INTO User(name,password,employeeId) VALUES ("admin3","202cb962ac59075b964b07152d234b70",3); +INSERT INTO User(name,password,employeeId) VALUES ("admin4","202cb962ac59075b964b07152d234b70",4); +INSERT INTO User(name,password,employeeId) VALUES ("admin5","202cb962ac59075b964b07152d234b70",5); \ No newline at end of file diff --git a/core/src/main/resources/db/migration/V3__Create_Customer_table.sql b/core/src/main/resources/db/migration/V3__Create_Customer_table.sql new file mode 100644 index 0000000..03339ca --- /dev/null +++ b/core/src/main/resources/db/migration/V3__Create_Customer_table.sql @@ -0,0 +1,9 @@ +create table Customer ( + id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, + customerName VARCHAR(40) NOT NULL +); + +INSERT INTO Customer(customerName) VALUES ("李煜"); +INSERT INTO Customer(customerName) VALUES ("朱江"); +INSERT INTO Customer(customerName) VALUES ("李静"); +INSERT INTO Customer(customerName) VALUES ("杨洋"); \ No newline at end of file diff --git a/core/src/main/resources/db/migration/V4__Create_Course_table.sql b/core/src/main/resources/db/migration/V4__Create_Course_table.sql new file mode 100644 index 0000000..5f6f3b8 --- /dev/null +++ b/core/src/main/resources/db/migration/V4__Create_Course_table.sql @@ -0,0 +1,10 @@ +create table Course ( + id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, + courseName VARCHAR(40) NOT NULL, + description VARCHAR(200)); + +INSERT INTO Course (courseName,description) VALUES ("private","You need to specify a coach!"); +INSERT INTO Course (courseName,description) VALUES ("swimming","This is an interesting sport!"); +INSERT INTO Course (courseName,description) VALUES ("football","This is an interesting sport!"); +INSERT INTO Course (courseName,description) VALUES ("running","This is an interesting sport!"); +INSERT INTO Course (courseName,description) VALUES ("basketball","This is an interesting sport!"); \ No newline at end of file diff --git a/core/src/main/resources/db/migration/V5__Create_Schedule_table.sql b/core/src/main/resources/db/migration/V5__Create_Schedule_table.sql new file mode 100644 index 0000000..9fdc3ca --- /dev/null +++ b/core/src/main/resources/db/migration/V5__Create_Schedule_table.sql @@ -0,0 +1,14 @@ +create table Schedule ( + id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, + courseId INT, + coachId INT, + time VARCHAR(20) NOT NULL, + customer VARCHAR(40), + CONSTRAINT foreign key(courseId) references Course(id) on delete set null , + CONSTRAINT foreign key(coachId) references Employee(id) on delete set null +); + +INSERT INTO Schedule (courseId,coachId,time,customer) VALUES (2,4,"2015-07-23","All"); +INSERT INTO Schedule (courseId,coachId,time,customer) VALUES (3,4,"2015-07-29","All"); +INSERT INTO Schedule (courseId,coachId,time,customer) VALUES (4,4,"2015-07-31","All"); +INSERT INTO Schedule (courseId,coachId,time,customer) VALUES (4,5,"2015-08-01","All"); diff --git a/core/src/main/resources/hibernate.cfg.xml b/core/src/main/resources/hibernate.cfg.xml index 951822a..af92269 100644 --- a/core/src/main/resources/hibernate.cfg.xml +++ b/core/src/main/resources/hibernate.cfg.xml @@ -20,14 +20,21 @@ root - + 10 + thread + + true - - + + + + + + \ No newline at end of file diff --git a/web/build.gradle b/web/build.gradle index a0926d1..88e02ab 100644 --- a/web/build.gradle +++ b/web/build.gradle @@ -5,6 +5,7 @@ dependencies { providedCompile 'javax.servlet:javax.servlet-api:3.1.0' testCompile 'junit:junit:4.10' + } buildscript { diff --git a/web/src/main/java/com/tw/web/DeleteServlet.java b/web/src/main/java/com/tw/web/DeleteServlet.java deleted file mode 100644 index d3fd025..0000000 --- a/web/src/main/java/com/tw/web/DeleteServlet.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.tw.web; - -import com.tw.core.entity.User; -import com.tw.core.service.UserService; - -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 java.io.IOException; - -/** - * Created by twer on 7/8/15. - */ -@WebServlet(name = "DeleteServlet") -public class DeleteServlet extends HttpServlet { - protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { - - - - } - - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - - - int id = Integer.parseInt(request.getParameter("id")); - UserService userService = new UserService(); - - userService.deleteUsers(id); - response.sendRedirect("/web/hello"); - - } - -} diff --git a/web/src/main/java/com/tw/web/HelloServlet.java b/web/src/main/java/com/tw/web/HelloServlet.java deleted file mode 100644 index f65bd45..0000000 --- a/web/src/main/java/com/tw/web/HelloServlet.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.tw.web; - -import java.io.*; -import java.sql.SQLException; -import java.util.List; -import javax.servlet.http.*; -import javax.servlet.*; - -import com.tw.core.Dao.UserDao; -import com.tw.core.entity.User; - -public class HelloServlet extends HttpServlet { - public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { - - // PrintWriter out = res.getWriter(); - - - res.setCharacterEncoding("UTF-8"); - res.setContentType("text/html;character=utf-8"); - - - try { - req.getRequestDispatcher("user Information.jsp").forward(req,res); - } catch (Exception e) { - e.printStackTrace(); - } - - - // out.println(new Service().service()); - // out.close(); - } -} \ No newline at end of file diff --git a/web/src/main/java/com/tw/web/InsertServlet.java b/web/src/main/java/com/tw/web/InsertServlet.java deleted file mode 100644 index 5fd19da..0000000 --- a/web/src/main/java/com/tw/web/InsertServlet.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.tw.web; - -import com.tw.core.Dao.UserDao; -import com.tw.core.entity.User; -import com.tw.core.service.UserService; - -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 java.io.IOException; -import java.sql.SQLException; - -/** - * Created by twer on 7/8/15. - */ -@WebServlet(name = "InsertServlet") -public class InsertServlet extends HttpServlet { - protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - -// int id = Integer.parseInt(request.getParameter("id")); - String name = request.getParameter("name"); - String sex = request.getParameter("sex"); - String email = request.getParameter("email"); - int age = Integer.parseInt(request.getParameter("age")); - -// User user = new User(id,name,sex,email,age); - - UserService userService = new UserService(); - userService.insertUsers(name,sex,email,age); - response.sendRedirect("/web/hello"); - - } - - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - - } -} diff --git a/web/src/main/java/com/tw/web/ModifyServlet.java b/web/src/main/java/com/tw/web/ModifyServlet.java deleted file mode 100644 index a002ef6..0000000 --- a/web/src/main/java/com/tw/web/ModifyServlet.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.tw.web; - -import com.tw.core.entity.User; -import com.tw.core.service.UserService; - -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 java.io.IOException; -import java.io.PrintWriter; - -/** - * Created by twer on 7/8/15. - */ -@WebServlet(name = "ModifyServlet") -public class ModifyServlet extends HttpServlet { - protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - - int id = Integer.parseInt(request.getParameter("id")); - String name = request.getParameter("name"); - String sex = request.getParameter("sex"); - String email = request.getParameter("email"); - int age = Integer.parseInt(request.getParameter("age")); - - User user = new User(id,name,sex,email,age); - - UserService userService = new UserService(); - userService.UpdateOneUser(user); - response.sendRedirect("/web/hello"); /*远程定向,重定向*/ - - - } - - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - - int id = Integer.parseInt(request.getParameter("id")); - UserService userService = new UserService(); - User user = userService.getOneUser(id); - - request.setAttribute("userList", user); - - request.getRequestDispatcher("modify.jsp").forward(request, response); /*直接跳转,请求转发*/ - - // response.sendRedirect("/modify"); - } -} diff --git a/web/src/main/webapp/WEB-INF/applicationContext.xml b/web/src/main/webapp/WEB-INF/applicationContext.xml new file mode 100644 index 0000000..142def2 --- /dev/null +++ b/web/src/main/webapp/WEB-INF/applicationContext.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/web/src/main/webapp/WEB-INF/spring-servlet.xml b/web/src/main/webapp/WEB-INF/spring-servlet.xml new file mode 100644 index 0000000..40a139b --- /dev/null +++ b/web/src/main/webapp/WEB-INF/spring-servlet.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/web/src/main/webapp/WEB-INF/views/course.jsp b/web/src/main/webapp/WEB-INF/views/course.jsp new file mode 100644 index 0000000..8af1a9e --- /dev/null +++ b/web/src/main/webapp/WEB-INF/views/course.jsp @@ -0,0 +1,81 @@ +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + + 课程管理 + + + + + + + +

课程管理页面

+ +
+ +
+ +
+ + + + + + + + + + + + + + + + + +
${course.id}${course.courseName}${course.description} + + + +
+ +
  • 添加课程
  • + + +
    + + + + + + diff --git a/web/src/main/webapp/WEB-INF/views/customer.jsp b/web/src/main/webapp/WEB-INF/views/customer.jsp new file mode 100644 index 0000000..942cb1a --- /dev/null +++ b/web/src/main/webapp/WEB-INF/views/customer.jsp @@ -0,0 +1,71 @@ +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + + 顾客管理 + + + + + + + +
      +

      顾客管理页面

      +
    + +
    + + + + + + + + + + + + + + + + +
    编号姓名删除更新
    ${customer.id}${customer.customerName}删除信息修改信息
    + +

    +
      +
    • 添加顾客
    • +
    +

    + +
    + + + + + + + + +
    姓名
    + + + +
    + + +
    + + diff --git a/web/src/main/webapp/WEB-INF/views/employee.jsp b/web/src/main/webapp/WEB-INF/views/employee.jsp new file mode 100644 index 0000000..136944c --- /dev/null +++ b/web/src/main/webapp/WEB-INF/views/employee.jsp @@ -0,0 +1,94 @@ +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + 员工管理 + + + + + + + +
      +

      员工管理页面

      +
    + +
    + + + + + + + + + + + + + + + + + + + + + + + +
    工号姓名性别年龄邮箱岗位是否在职修改信息
    ${employee.id}${employee.name}${employee.sex}${employee.age}${employee.email}${employee.role}${employee.state}修改信息
    + + +

    +
      +
    • 添加员工
    • +
    +

    + +
    + + + + + + + + + + + + + + + + + +
    姓名性别年龄邮箱岗位在职
    + + + +
    + + +
    +
    + + + diff --git a/web/src/main/webapp/WEB-INF/views/index.jsp b/web/src/main/webapp/WEB-INF/views/index.jsp new file mode 100644 index 0000000..3c66ae1 --- /dev/null +++ b/web/src/main/webapp/WEB-INF/views/index.jsp @@ -0,0 +1,22 @@ +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + 健身房管理系统 + + + + + + + diff --git a/web/src/main/webapp/WEB-INF/views/insert.jsp b/web/src/main/webapp/WEB-INF/views/insert.jsp new file mode 100644 index 0000000..62d80af --- /dev/null +++ b/web/src/main/webapp/WEB-INF/views/insert.jsp @@ -0,0 +1,23 @@ +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + 用户注册 + + +

    新用户注册

    + +
    + 用户名 : +
      + 密    码 : +
        + 工    号 : +
        +
          + + +
          + + + diff --git a/web/src/main/webapp/WEB-INF/views/login.jsp b/web/src/main/webapp/WEB-INF/views/login.jsp new file mode 100644 index 0000000..addf5d2 --- /dev/null +++ b/web/src/main/webapp/WEB-INF/views/login.jsp @@ -0,0 +1,19 @@ +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + 用户登陆页面 + + + +

          请先登陆

          + +
          + 用户名: + 密  码: + + +
          + + + + diff --git a/web/src/main/webapp/WEB-INF/views/loginError.jsp b/web/src/main/webapp/WEB-INF/views/loginError.jsp new file mode 100644 index 0000000..d914b6a --- /dev/null +++ b/web/src/main/webapp/WEB-INF/views/loginError.jsp @@ -0,0 +1,12 @@ +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + + + +
          +

          用户名或密码错误

          + 返回重新登录 +
          + + diff --git a/web/src/main/webapp/WEB-INF/views/modify.jsp b/web/src/main/webapp/WEB-INF/views/modify.jsp new file mode 100644 index 0000000..cc09ddc --- /dev/null +++ b/web/src/main/webapp/WEB-INF/views/modify.jsp @@ -0,0 +1,23 @@ +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + + + + + +
          + + 序号 : + 用户名 : + 密码 : + 工号 : + +
          + +
          + + + + diff --git a/web/src/main/webapp/WEB-INF/views/modifyCourse.jsp b/web/src/main/webapp/WEB-INF/views/modifyCourse.jsp new file mode 100644 index 0000000..8861f9c --- /dev/null +++ b/web/src/main/webapp/WEB-INF/views/modifyCourse.jsp @@ -0,0 +1,18 @@ +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + + + + +
          + + 编号 : + 课程 : + 描述 : + +
          + +
          + + diff --git a/web/src/main/webapp/WEB-INF/views/modifyCustomer.jsp b/web/src/main/webapp/WEB-INF/views/modifyCustomer.jsp new file mode 100644 index 0000000..971a6b7 --- /dev/null +++ b/web/src/main/webapp/WEB-INF/views/modifyCustomer.jsp @@ -0,0 +1,20 @@ +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + + + + + +
          + + 编号 : + 姓名 : + +
          + +
          + + + + diff --git a/web/src/main/webapp/WEB-INF/views/modifyEmployee.jsp b/web/src/main/webapp/WEB-INF/views/modifyEmployee.jsp new file mode 100644 index 0000000..b32ae13 --- /dev/null +++ b/web/src/main/webapp/WEB-INF/views/modifyEmployee.jsp @@ -0,0 +1,24 @@ +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + + + + +
          + + 工号 : + 姓名 : + 性别 : + 年龄 : + 邮箱 : + 岗位 : + 是否在职 : + +
          + +
          + + + + diff --git a/web/src/main/webapp/WEB-INF/views/modifySchedule.jsp b/web/src/main/webapp/WEB-INF/views/modifySchedule.jsp new file mode 100644 index 0000000..30d291d --- /dev/null +++ b/web/src/main/webapp/WEB-INF/views/modifySchedule.jsp @@ -0,0 +1,44 @@ +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + + + + +
          + + + + 编号 : + + + 课程 : + + 教练 : + + 时间 : + + 顾客 : + + + +
          + + + +
          + + diff --git a/web/src/main/webapp/WEB-INF/views/schedule.jsp b/web/src/main/webapp/WEB-INF/views/schedule.jsp new file mode 100644 index 0000000..fff5be0 --- /dev/null +++ b/web/src/main/webapp/WEB-INF/views/schedule.jsp @@ -0,0 +1,153 @@ +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + + 课程表管理 + + + + + + + + + + + + + +
            +

            课程表管理页面

            +
          + + +
          + + + + + + + + + + + + + + + + + + + + + + + + +
          编号课程教练时间顾客删除用户修改信息
          ${schedule.id}${schedule.course.courseName}${schedule.employee.name}${schedule.time}${schedule.customer}删除用户修改信息
          + + +
            +
          • 添加公共课
          • +
          + +
          + + + + + + + + + + + + + + +
          课程教练时间顾客
          + + + +
          + + + +
          + + + +
            +
          • 预约私教课
          • +
          + +
          + + + + + + + + + + + + + + +
          课程教练时间顾客
          + + + + + +
          + + + +
          + + +
          + + diff --git a/web/src/main/webapp/WEB-INF/views/userInformation.jsp b/web/src/main/webapp/WEB-INF/views/userInformation.jsp new file mode 100644 index 0000000..e469e33 --- /dev/null +++ b/web/src/main/webapp/WEB-INF/views/userInformation.jsp @@ -0,0 +1,54 @@ +<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> + + + + 用户管理 + + + + + + +

          用户管理页面

          + +
          + + + + + + + + + + + + + + + + + + + + + + +
          编号用户名工号删除用户修改信息
          ${user.id}${user.name}${user.employee.id}删除用户修改信息
          +
          + + + + diff --git a/web/src/main/webapp/WEB-INF/web.xml b/web/src/main/webapp/WEB-INF/web.xml index 591d630..eed3ce1 100644 --- a/web/src/main/webapp/WEB-INF/web.xml +++ b/web/src/main/webapp/WEB-INF/web.xml @@ -1,51 +1,41 @@ - + + - - HelloServlet - com.tw.web.HelloServlet - - - HelloServlet - /hello - - - InsertServlet - com.tw.web.InsertServlet - + + + contextConfigLocation + /WEB-INF/applicationContext.xml + - - InsertServlet - /insert - + + + + org.springframework.web.context.ContextLoaderListener + + - DeleteServlet - com.tw.web.DeleteServlet + spring + org.springframework.web.servlet.DispatcherServlet + + 1 - DeleteServlet - /delete + spring + / - - ModifyServlet - com.tw.web.ModifyServlet - - - ModifyServlet - /modify - + + + + - - - user Information.jsp - \ No newline at end of file diff --git a/web/src/main/webapp/css/customerStyle.css b/web/src/main/webapp/css/customerStyle.css new file mode 100644 index 0000000..fb64a37 --- /dev/null +++ b/web/src/main/webapp/css/customerStyle.css @@ -0,0 +1,60 @@ +html { + font-family: cursive; /*更改页面上的所有字体*/ +} + +h2 { + color: #CA42C8; + text-align: center; +} + +a { + color: #CA42C8; +} + +a:hover { + background-color: #ff3300; +} + +.container { + padding-right: 15px; + padding-left: 15px; + margin-right: auto; + margin-left: auto; + width: 1170px; +} + +.table { + border-collapse: collapse; + width: inherit; + margin-top: 20px; /*table间的间距*/ + font-size: 18px; + text-align: center; /*表格字体居中*/ + border: 1px solid gold; + background-color: antiquewhite; + height: 35px; + color: peru; +} + +.table-bordered th, +.table-bordered td { + border: 1px solid #ddd; +} + +input { + line-height: inherit; + margin: 0; + font: inherit; + font-size: medium; + color: inherit; +} + +.button { + box-sizing: border-box; + font-size: small; + cursor: pointer; +} + +#insertButton { + margin-top: 20px; + font-size: large; +} \ No newline at end of file diff --git a/web/src/main/webapp/css/employeeStyle.css b/web/src/main/webapp/css/employeeStyle.css new file mode 100644 index 0000000..9380a5e --- /dev/null +++ b/web/src/main/webapp/css/employeeStyle.css @@ -0,0 +1,58 @@ +html { + font-family: cursive; /*更改页面上的所有字体*/ +} + +body { + margin: auto; /*body在页面上的位置*/ +} + +ul { + display: block; +} + +h2 { + color: #CA42C8; + position:relative; + text-align: center; /*文字居中*/ +} + +table { + display: block; + margin-top: 20px; /*table间的间距*/ + text-align: center; /*表格字体居中*/ + +} +a{ + color: #269abc; +} + +a:hover { + background-color:#ff3300 +} + +.container { + padding-right: 15px; + padding-left: 15px; + margin-right: auto; + margin-left: auto; + width: 1170px; +} + +.table { + border-collapse: collapse; + width: inherit; +} + +.table-bordered th, +.table-bordered td { + border: 1px solid #ddd !important; +} + +input { + font: inherit; + font-size: medium; + line-height: inherit; + margin: 0; + color: inherit; +} + diff --git a/web/src/main/webapp/css/main.css b/web/src/main/webapp/css/main.css new file mode 100644 index 0000000..05a2355 --- /dev/null +++ b/web/src/main/webapp/css/main.css @@ -0,0 +1,12 @@ +.navigation { + margin: 1em; +} + +.nav-item { + display: inline-block; + margin: auto 10px; +} + +.register { + margin: 10px 0; +} \ No newline at end of file diff --git a/web/src/main/webapp/css/navigator.css b/web/src/main/webapp/css/navigator.css new file mode 100644 index 0000000..6fca5a3 --- /dev/null +++ b/web/src/main/webapp/css/navigator.css @@ -0,0 +1,28 @@ +ul { + display: inline-block; + float: left; + width: 100%; + padding: 0; + margin: auto 200px; + list-style-type: none; + text-align: center; +} + +a { + float: left; + position: relative; + width: 7em; + text-decoration: none; + color: white; + background-color: purple; + padding: 0.2em 0.6em; + border-right: 1px solid white; +} + +a:hover { + background-color: #ff3300 +} + +li { + display: inline +} diff --git a/web/src/main/webapp/html/course.html b/web/src/main/webapp/html/course.html new file mode 100644 index 0000000..a6b1b0e --- /dev/null +++ b/web/src/main/webapp/html/course.html @@ -0,0 +1,120 @@ + + + + + 课程管理 + + + + + +
            +

            课程管理页面

            +
          + +
          + +
          + + +
          + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
          + + +
        • 添加课程
        • +
          + +
          + + + + + + + \ No newline at end of file diff --git a/web/src/main/webapp/index.html b/web/src/main/webapp/index.html new file mode 100644 index 0000000..71ce692 --- /dev/null +++ b/web/src/main/webapp/index.html @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/web/src/main/webapp/insert.jsp b/web/src/main/webapp/insert.jsp deleted file mode 100644 index cb24b0a..0000000 --- a/web/src/main/webapp/insert.jsp +++ /dev/null @@ -1,26 +0,0 @@ -<%@ page import="com.tw.core.Dao.UserDao" %> -<%-- - Created by IntelliJ IDEA. - User: twer - Date: 7/8/15 - Time: 3:58 PM - To change this template use File | Settings | File Templates. ---%> -<%@ page contentType="text/html;charset=UTF-8" language="java" %> - - - - - - - -
          - 姓名 : - 性别 : - 邮箱 : - 年龄 : -
          - -
          - - diff --git a/web/src/main/webapp/js/course.js b/web/src/main/webapp/js/course.js new file mode 100644 index 0000000..fcfb445 --- /dev/null +++ b/web/src/main/webapp/js/course.js @@ -0,0 +1,85 @@ +$(function () { + + $('#insertButton').on('click', function () { + $('#insertCourseForm').toggle(); + }); + + + $('.updateButton').on('click', function () { + var id = $(this).closest('tr').children('.course-id').text(); + var name = $(this).closest('tr').children('.course-name').text(); + var description = $(this).closest('tr').children('.course-description').text(); + $('#idInput').val(id); + $('#nameInput').val(name); + $('#descriptionInput').val(description); + $('#updateCourseForm').toggle(); + }); + + var course; + $('.deleteButton').on('click',function(){ + if (confirm("确定要删除吗?")) { + course = this; + var id = course.closest('td').id; + $.ajax({ + url: '/web/course/' + id, + type: 'DELETE', + dataType: 'text', + success: function () { + course.closest('tr').remove(); + } + }) + } + }); + + $('#updateCourseForm').submit(function (e) { + e.preventDefault(); + var name = $('#nameInput').val(); + if (name == "") { + alert("Name can not be set null!"); + return false; + } + var id = $('#idInput').val(); + var description = $('#descriptionInput').val(); + $.ajax({ + url: '/web/course/update', + type: 'PUT', + dataType: 'json', + data: {"id": id, "courseName": name, "description": description}, + success: function (result) { + $('#updateCourseForm').hide(); + var td = 'tr #' + result.id; + $(td).siblings('.course-name').text(result.courseName); + $(td).siblings('.course-description').text(result.description); + } + }); + }); + + + $('.insertButton').on('click', function () { + course = this; + var name = $('#nameInsert').val(); + if (name == "") { + alert("Name can not be set null!"); + return; + } + var form = $('#insertCourseForm'); + $.ajax({ + url: '/web/course', + type: 'POST', + dataType: 'json', + data: form.serialize(), + success: function (data) { + window.location.reload(); + } + }) + }) + +}); + + + + + + + + diff --git a/web/src/main/webapp/js/schedule.js b/web/src/main/webapp/js/schedule.js new file mode 100644 index 0000000..e69de29 diff --git a/web/src/main/webapp/lib/css/bootstrap.css b/web/src/main/webapp/lib/css/bootstrap.css index 037dd05..7933a23 100644 --- a/web/src/main/webapp/lib/css/bootstrap.css +++ b/web/src/main/webapp/lib/css/bootstrap.css @@ -10,6 +10,13 @@ html { -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; } + +h2 { + color: #428bca; + position:relative; + text-align: center; +} + body { margin: 0; } diff --git a/web/src/main/webapp/lib/js/angular/.DS_Store b/web/src/main/webapp/lib/js/angular/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/web/src/main/webapp/lib/js/angular/.DS_Store differ diff --git a/web/src/main/webapp/modify.jsp b/web/src/main/webapp/modify.jsp deleted file mode 100644 index 4db41ca..0000000 --- a/web/src/main/webapp/modify.jsp +++ /dev/null @@ -1,33 +0,0 @@ -<%@ page import="com.tw.core.entity.User" %> -<%@ page import="com.tw.core.Dao.UserDao" %> -<%@ page import="java.util.List" %> -<%-- - Created by IntelliJ IDEA. - User: twer - Date: 7/8/15 - Time: 10:28 PM - To change this template use File | Settings | File Templates. ---%> -<%@ page contentType="text/html;charset=UTF-8" language="java" %> - - - - <% - User user = (User) request.getAttribute("userList"); - %> - - - -
          - 序号 : - 姓名 : - 性别 : - 邮箱 : - 年龄 : -
          - -
          - - - - diff --git a/web/src/main/webapp/user Information.jsp b/web/src/main/webapp/user Information.jsp deleted file mode 100644 index 3c8e291..0000000 --- a/web/src/main/webapp/user Information.jsp +++ /dev/null @@ -1,78 +0,0 @@ -<%-- - Created by IntelliJ IDEA. - User: twer - Date: 7/7/15 - Time: 1:47 PM - To change this template use File | Settings | File Templates. ---%> -<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="utf-8"%> -<%@ page import="java.sql.*,java.text.*,java.util.*"%> -<%@ page import="com.tw.core.Dao.UserDao" %> -<%@ page import="java.io.PrintWriter" %> -<%@ page import="com.tw.core.entity.User" %> - - - - 第一个JSP程序 - - - <%----%> - <%----%> - <%----%> - <%----%> - <%----%> - <%----%> - <%----%> - <%----%> - <%----%> - <%----%> - <%----%> - <%----%> - <%----%> - <%----%> - <%----%> - <%----%> - <%----%> - <%----%> - <%----%> - <%----%> - <%----%> - <%----%> - <%----%> - <%----%> - <%----%> - <%--
          姓名性别邮箱年龄
          韩玲163@163.com12
          吴天163@163.com12
          张贵163@163.com77
          --%> - - - <% UserDao userDao = new UserDao(); - List userList = userDao.getUsers(); - %> - - - - - - - - - <%if(userList.size()!=0){ - for(int i=0;i - - <%----%> - - - - - - - - <%}}%> - -
          姓名性别邮箱年龄
          <%=userList.get(i).getId()%><%=userList.get(i).getName()%><%=userList.get(i).getSex()%><%=userList.get(i).getEmail()%><%=userList.get(i).getAge()%>删除修改
          - - - -