From 791bd6368f24ba5670147fcb15d18843ee63beb6 Mon Sep 17 00:00:00 2001 From: VuVanHoc Date: Sun, 19 May 2019 15:32:04 +0700 Subject: [PATCH 1/4] Add file customer.sql.md --- 17020780_vu_van_hoc/mywallet/customers.sql.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 17020780_vu_van_hoc/mywallet/customers.sql.md diff --git a/17020780_vu_van_hoc/mywallet/customers.sql.md b/17020780_vu_van_hoc/mywallet/customers.sql.md new file mode 100644 index 0000000..904418d --- /dev/null +++ b/17020780_vu_van_hoc/mywallet/customers.sql.md @@ -0,0 +1,18 @@ +create database if not exists `my_wallet_systems`; +use `my_wallet_systems`; + +drop table if exists `customers`; +create table `customers` ( + `id` int(11) auto_increment, + `name` varchar(100) not null, + `email` varchar(100) not null, + `phone` varchar(50) not null, + `balance` double not null, + `created_date` datetime not null, + `updated_date` datetime, + primary key (`id`) +)ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- insert into `customers`(`name`, `email`, `phone`, `balance`, `created_date`) values +-- ("Vũ Văn Học", "hocvanvu1999@gmail.com", "0343847478", 1000000, "2019-05-19"), +-- ("Nguyen Van An", "hocvanvu1999@gmail.com", "0963245801", 500000, "2019-05-19"); \ No newline at end of file From 39b6ffc5241ce928676d4f4a2e1e30398b4a6c0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=E1=BB=8Dc=20V=C5=A9=20V=C4=83n?= Date: Mon, 10 Jun 2019 22:36:58 +0700 Subject: [PATCH 2/4] Add file customer.sql.md --- 17020780_vu_van_hoc/mywallet/customer.sql.md | 64 ++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 17020780_vu_van_hoc/mywallet/customer.sql.md diff --git a/17020780_vu_van_hoc/mywallet/customer.sql.md b/17020780_vu_van_hoc/mywallet/customer.sql.md new file mode 100644 index 0000000..c891354 --- /dev/null +++ b/17020780_vu_van_hoc/mywallet/customer.sql.md @@ -0,0 +1,64 @@ +-- phpMyAdmin SQL Dump +-- version 4.8.5 +-- https://www.phpmyadmin.net/ +-- +-- Host: 127.0.0.1 +-- Generation Time: Jun 10, 2019 at 05:33 PM +-- Server version: 10.1.38-MariaDB +-- PHP Version: 7.3.2 + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +SET AUTOCOMMIT = 0; +START TRANSACTION; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; + +-- +-- Database: `my_walllet_systems` +-- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `customer` +-- + +CREATE TABLE `customer` ( + `cus_id` int(11) NOT NULL, + `cus_name` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, + `cus_email` varchar(100) NOT NULL, + `cus_phone` varchar(50) NOT NULL, + `cus_balance` double UNSIGNED NOT NULL, + `cus_created_date` datetime NOT NULL, + `cus_updated_date` datetime DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- +-- Indexes for dumped tables +-- + +-- +-- Indexes for table `customer` +-- +ALTER TABLE `customer` + ADD PRIMARY KEY (`cus_id`); + +-- +-- AUTO_INCREMENT for dumped tables +-- + +-- +-- AUTO_INCREMENT for table `customer` +-- +ALTER TABLE `customer` + MODIFY `cus_id` int(11) NOT NULL AUTO_INCREMENT; +COMMIT; + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; From 3c774580d356adf4e965f67e240147ac98d5ada1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=E1=BB=8Dc=20V=C5=A9=20V=C4=83n?= Date: Mon, 10 Jun 2019 22:45:07 +0700 Subject: [PATCH 3/4] Add file customer.sql --- 17020780_vu_van_hoc/mywallet/customers.sql.md | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 17020780_vu_van_hoc/mywallet/customers.sql.md diff --git a/17020780_vu_van_hoc/mywallet/customers.sql.md b/17020780_vu_van_hoc/mywallet/customers.sql.md deleted file mode 100644 index 904418d..0000000 --- a/17020780_vu_van_hoc/mywallet/customers.sql.md +++ /dev/null @@ -1,18 +0,0 @@ -create database if not exists `my_wallet_systems`; -use `my_wallet_systems`; - -drop table if exists `customers`; -create table `customers` ( - `id` int(11) auto_increment, - `name` varchar(100) not null, - `email` varchar(100) not null, - `phone` varchar(50) not null, - `balance` double not null, - `created_date` datetime not null, - `updated_date` datetime, - primary key (`id`) -)ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- insert into `customers`(`name`, `email`, `phone`, `balance`, `created_date`) values --- ("Vũ Văn Học", "hocvanvu1999@gmail.com", "0343847478", 1000000, "2019-05-19"), --- ("Nguyen Van An", "hocvanvu1999@gmail.com", "0963245801", 500000, "2019-05-19"); \ No newline at end of file From ecb49cf6d922b7ce3cee9604e6a4c2f2c3626061 Mon Sep 17 00:00:00 2001 From: VuVanHoc Date: Tue, 25 Jun 2019 13:17:43 +0700 Subject: [PATCH 4/4] Chia layer co ban. --- .../mywallet/.idea/dataSources.xml | 19 ++ .../mywallet/.idea/sqldialects.xml | 6 + .../mywallet/.idea/uiDesigner.xml | 124 ++++++++++++++ 17020780_vu_van_hoc/mywallet/pom.xml | 10 +- .../vuvanhoc/controller/SystemController.java | 162 +++++++++--------- .../uetcodecamp/vuvanhoc/model/Customer.java | 82 +++++++++ .../uetcodecamp/vuvanhoc/objects/User.java | 60 ------- .../repository/CustomerRepository.java | 10 ++ .../vuvanhoc/service/CustomerService.java | 37 ++++ .../src/main/resources/application.properties | 8 + .../mywallet/src/main/resources/customer.sql | 63 +++++++ .../src/main/webapp/WEB-INF/jsp/home.jsp | 36 ++-- .../jsp/{themUser.jsp => pageAddUser.jsp} | 2 +- ...{suaThongTin.jsp => pageEditUserInfor.jsp} | 15 +- .../jsp/{thongTinTK.jsp => pageInforUser.jsp} | 19 +- .../jsp/{dangNhap.jsp => pageLogin.jsp} | 0 ...rmChuyenTien.jsp => pageTransferMoney.jsp} | 2 +- 17 files changed, 478 insertions(+), 177 deletions(-) create mode 100644 17020780_vu_van_hoc/mywallet/.idea/dataSources.xml create mode 100644 17020780_vu_van_hoc/mywallet/.idea/sqldialects.xml create mode 100644 17020780_vu_van_hoc/mywallet/.idea/uiDesigner.xml create mode 100644 17020780_vu_van_hoc/mywallet/src/main/java/com/uetcodecamp/vuvanhoc/model/Customer.java delete mode 100644 17020780_vu_van_hoc/mywallet/src/main/java/com/uetcodecamp/vuvanhoc/objects/User.java create mode 100644 17020780_vu_van_hoc/mywallet/src/main/java/com/uetcodecamp/vuvanhoc/repository/CustomerRepository.java create mode 100644 17020780_vu_van_hoc/mywallet/src/main/java/com/uetcodecamp/vuvanhoc/service/CustomerService.java create mode 100644 17020780_vu_van_hoc/mywallet/src/main/resources/customer.sql rename 17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/{themUser.jsp => pageAddUser.jsp} (95%) rename 17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/{suaThongTin.jsp => pageEditUserInfor.jsp} (76%) rename 17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/{thongTinTK.jsp => pageInforUser.jsp} (59%) rename 17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/{dangNhap.jsp => pageLogin.jsp} (100%) rename 17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/{formChuyenTien.jsp => pageTransferMoney.jsp} (94%) diff --git a/17020780_vu_van_hoc/mywallet/.idea/dataSources.xml b/17020780_vu_van_hoc/mywallet/.idea/dataSources.xml new file mode 100644 index 0000000..32676e6 --- /dev/null +++ b/17020780_vu_van_hoc/mywallet/.idea/dataSources.xml @@ -0,0 +1,19 @@ + + + + + mysql.8 + true + com.mysql.cj.jdbc.Driver + jdbc:mysql://localhost:3306 + + + + + + + + + + + \ No newline at end of file diff --git a/17020780_vu_van_hoc/mywallet/.idea/sqldialects.xml b/17020780_vu_van_hoc/mywallet/.idea/sqldialects.xml new file mode 100644 index 0000000..a86bd42 --- /dev/null +++ b/17020780_vu_van_hoc/mywallet/.idea/sqldialects.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/17020780_vu_van_hoc/mywallet/.idea/uiDesigner.xml b/17020780_vu_van_hoc/mywallet/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/17020780_vu_van_hoc/mywallet/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/17020780_vu_van_hoc/mywallet/pom.xml b/17020780_vu_van_hoc/mywallet/pom.xml index 01dbb6e..2f461a1 100644 --- a/17020780_vu_van_hoc/mywallet/pom.xml +++ b/17020780_vu_van_hoc/mywallet/pom.xml @@ -38,13 +38,21 @@ bootstrap 3.4.1 - org.webjars bootstrap-datepicker 1.0.1 + + org.springframework.boot + spring-boot-starter-data-jpa + + + mysql + mysql-connector-java + runtime + org.webjars jquery diff --git a/17020780_vu_van_hoc/mywallet/src/main/java/com/uetcodecamp/vuvanhoc/controller/SystemController.java b/17020780_vu_van_hoc/mywallet/src/main/java/com/uetcodecamp/vuvanhoc/controller/SystemController.java index 77e4ff9..3432102 100644 --- a/17020780_vu_van_hoc/mywallet/src/main/java/com/uetcodecamp/vuvanhoc/controller/SystemController.java +++ b/17020780_vu_van_hoc/mywallet/src/main/java/com/uetcodecamp/vuvanhoc/controller/SystemController.java @@ -1,105 +1,109 @@ package com.uetcodecamp.vuvanhoc.controller; -import com.uetcodecamp.vuvanhoc.objects.User; +import com.uetcodecamp.vuvanhoc.model.Customer; +import com.uetcodecamp.vuvanhoc.service.CustomerService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; -import java.util.HashMap; +import java.sql.Timestamp; +import java.time.LocalDate; +import java.util.List; @Controller public class SystemController { - HashMap items = new HashMap<>(); - private int templateId; + + @Autowired + CustomerService customerService; + @RequestMapping(value = {"/"}) - public String index(Model model) { - model.addAttribute("items", items); + public String home(Model model) { + List customerList = customerService.getAllCustomer(); + model.addAttribute("customerList", customerList); return "home"; } @GetMapping(value = "/them-nguoi-dung") - public String formGet(){ - return "themUser"; - } - @PostMapping(value = "/them-nguoi-dung") - public String formPost(@RequestParam String name, @RequestParam String email, - @RequestParam String phone, @RequestParam int balance){ - User newUser = new User(name, email, phone, balance); - newUser.setId(templateId); - templateId++; - items.put(newUser.getId(), newUser); - return "redirect:/"; + public String pageFormAddUser(){ + return "pageAddUser"; } - - - @GetMapping(value = "/xoa-nguoi-dung") - public String removeUser(@RequestParam("id") int id ){ - System.out.println("Remove id " +id); - items.remove(id); + @PostMapping(value = "/xu-ly-them-nguoi-dung") + public String handleFormAddUser(@RequestParam("name") String name, @RequestParam("email") String email, + @RequestParam("phone") String phone, @RequestParam("balance") double balance){ + customerService.addNewUser(new Customer(name, email, phone, balance)); return "redirect:/"; } @GetMapping(value = "/sua-thong-tin") - public String formUpdateGet(@RequestParam("id") int key, Model model){ - model.addAttribute("key", key); - model.addAttribute("items", items); - System.out.println("Sua id " + key); - return "suaThongTin"; + public String pageFormEditUserInfor(@RequestParam("id") int id, Model model){ + Customer customer = customerService.getCustomerById(id); + model.addAttribute("customer", customer); + System.out.println("Sua id " + id); + return "pageEditUserInfor"; } - @PostMapping(value = "/xu-li-form-sua-thong-tin/{key}") - public String formUpdatePost( @PathVariable("key") int key,@RequestParam String name, - @RequestParam String email, @RequestParam String phone, - @RequestParam int balance){ - items.get(key).setName(name); - items.get(key).setPhone(phone); - items.get(key).setEmail(email); - items.get(key).setBalance(balance); + @DeleteMapping(value = "/xoa-nguoi-dung") + public String deleteUser(@RequestParam("id") int id ){ + System.out.println("Remove id " +id); + customerService.deleteUserById(id); return "redirect:/"; } + +// @PostMapping(value = "/xu-li-form-sua-thong-tin/{key}") +// public String formUpdatePost( @PathVariable("key") int key,@RequestParam String name, +// @RequestParam String email, @RequestParam String phone, +// @RequestParam int balance){ +// +// customerList.get(key).setName(name); +// customerList.get(key).setPhone(phone); +// customerList.get(key).setEmail(email); +// customerList.get(key).setBalance(balance); +// return "redirect:/"; +// } @GetMapping(value = "/dang-nhap") - public String formLoginGet(){ - return "dangNhap"; - } - @GetMapping(value = "/thong-tin-nguoi-dung/{key}") - public String formLoginPost(@PathVariable("key") int key, Model model){ - model.addAttribute("items", items); - model.addAttribute("key", key); - return "thongTinTK"; + public String pageFormLogin(){ + return "pageLogin"; } - @PostMapping(value = "/xu-li-dang-nhap") - public String xuLiDangNhap(@RequestParam String email, @RequestParam String password){ - String defaultPassword = "123456"; - for(int i : items.keySet()){ - if(items.get(i).getEmail().equals(email) && password.equals(defaultPassword)){ - System.out.println("dang nhap thanh cong"); - return "redirect:/thong-tin-nguoi-dung/" + i; - } - } -// System.out.println("dang nhap sai roi"); - return "thongBao/error"; + @GetMapping(value = "/thong-tin-nguoi-dung/{id}") + public String formLoginPost(@PathVariable("id") int id, Model model){ + Customer customer = customerService.getCustomerById(id); + model.addAttribute("customer", customer); + return "pageInforUser"; } - @PostMapping(value = "/giao-dich/{key}") - public String chuyenTien(@PathVariable("key") int key, Model model){ - model.addAttribute(key); - return "formChuyenTien"; - } - @PostMapping(value = "/xu-li-giao-dich/{key}") - public String xuLiGiaoDich(@PathVariable("key") int key, - @RequestParam int id, @RequestParam int amount) { - final int soDuToiThieu = 50000; - if (items.get(key).getBalance() - amount < soDuToiThieu) { - System.out.println("chuyen tien that bai"); - return "thongBao/loiGiaoDich"; - } else { - for (int i : items.keySet()) { - if (items.get(i).getId() == id) { - items.get(i).setBalance(items.get(i).getBalance() + amount); - items.get(key).setBalance(items.get(key).getBalance() - amount); - return "redirect:/"; - } - } - } - return "thongBao/idNotFound"; - } - +// @PostMapping(value = "/xu-li-dang-nhap") +// public String xuLiDangNhap(@RequestParam String email, @RequestParam String password){ +// String defaultPassword = "123456"; +// for(int i : customerList.keySet()){ +// if(customerList.get(i).getEmail().equals(email) && password.equals(defaultPassword)){ +// System.out.println("dang nhap thanh cong"); +// return "redirect:/thong-tin-nguoi-dung/" + i; +// } +// } +//// System.out.println("dang nhap sai roi"); +// return "thongBao/error"; +// } +// @PostMapping(value = "/giao-dich/{key}") +// public String chuyenTien(@PathVariable("key") int key, Model model){ +// model.addAttribute(key); +// return "pageTransferMoney"; +// } +// @PostMapping(value = "/xu-li-giao-dich/{key}") +// public String xuLiGiaoDich(@PathVariable("key") int key, +// @RequestParam int id, @RequestParam int amount) { +// final int soDuToiThieu = 50000; +// if (customerList.get(key).getBalance() - amount < soDuToiThieu) { +// System.out.println("chuyen tien that bai"); +// return "thongBao/loiGiaoDich"; +// } else { +// for (int i : customerList.keySet()) { +// if (customerList.get(i).getId() == id) { +// customerList.get(i).setBalance(customerList.get(i).getBalance() + amount); +// customerList.get(key).setBalance(customerList.get(key).getBalance() - amount); +// return "redirect:/"; +// } +// } +// } +// return "thongBao/idNotFound"; +// } +// } \ No newline at end of file diff --git a/17020780_vu_van_hoc/mywallet/src/main/java/com/uetcodecamp/vuvanhoc/model/Customer.java b/17020780_vu_van_hoc/mywallet/src/main/java/com/uetcodecamp/vuvanhoc/model/Customer.java new file mode 100644 index 0000000..a66d742 --- /dev/null +++ b/17020780_vu_van_hoc/mywallet/src/main/java/com/uetcodecamp/vuvanhoc/model/Customer.java @@ -0,0 +1,82 @@ +package com.uetcodecamp.vuvanhoc.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +import javax.persistence.*; + +@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) +@Entity +@Table(name = "customer") +public class Customer { + + @Id + @Column(name = "cus_id") + @GeneratedValue(strategy = GenerationType.AUTO) + private Integer id ; + + @Column(name = "cus_name") + private String name; + + @Column(name = "cus_email") + private String email; + + @Column(name = "cus_phone") + private String phone; + + @Column(name = "cus_balance") + private Double balance; + + + public Customer(String name, String email, String phone, Double balance) { + this.name = name; + this.email = email; + this.phone = phone; + this.balance = balance; + + } + + public Customer() { + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public Double getBalance() { + return balance; + } + + public void setBalance(Double balance) { + this.balance = balance; + } + + +} diff --git a/17020780_vu_van_hoc/mywallet/src/main/java/com/uetcodecamp/vuvanhoc/objects/User.java b/17020780_vu_van_hoc/mywallet/src/main/java/com/uetcodecamp/vuvanhoc/objects/User.java deleted file mode 100644 index 097b6ab..0000000 --- a/17020780_vu_van_hoc/mywallet/src/main/java/com/uetcodecamp/vuvanhoc/objects/User.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.uetcodecamp.vuvanhoc.objects; - -public class User { - private int id ; - private String name; - private String email; - private String phone; - private int balance; - - public User(String name, String email, String phone, int balance) { - this.name = name; - this.email = email; - this.phone = phone; - this.balance = balance; - } - - 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 getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - public String getPhone() { - return phone; - } - - public void setPhone(String phone) { - this.phone = phone; - } - - public int getBalance() { - return balance; - } - - public void setBalance(int balance) { - this.balance = balance; - } -} diff --git a/17020780_vu_van_hoc/mywallet/src/main/java/com/uetcodecamp/vuvanhoc/repository/CustomerRepository.java b/17020780_vu_van_hoc/mywallet/src/main/java/com/uetcodecamp/vuvanhoc/repository/CustomerRepository.java new file mode 100644 index 0000000..de42eb9 --- /dev/null +++ b/17020780_vu_van_hoc/mywallet/src/main/java/com/uetcodecamp/vuvanhoc/repository/CustomerRepository.java @@ -0,0 +1,10 @@ +package com.uetcodecamp.vuvanhoc.repository; + +import com.uetcodecamp.vuvanhoc.model.Customer; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface CustomerRepository extends JpaRepository { + +} diff --git a/17020780_vu_van_hoc/mywallet/src/main/java/com/uetcodecamp/vuvanhoc/service/CustomerService.java b/17020780_vu_van_hoc/mywallet/src/main/java/com/uetcodecamp/vuvanhoc/service/CustomerService.java new file mode 100644 index 0000000..c6e5fb1 --- /dev/null +++ b/17020780_vu_van_hoc/mywallet/src/main/java/com/uetcodecamp/vuvanhoc/service/CustomerService.java @@ -0,0 +1,37 @@ +package com.uetcodecamp.vuvanhoc.service; + +import com.uetcodecamp.vuvanhoc.model.Customer; +import com.uetcodecamp.vuvanhoc.repository.CustomerRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +@Service +public class CustomerService { + + @Autowired + CustomerRepository customerRepository; + + public Customer getCustomerById(int id){ + return customerRepository.getOne(id); + } + + public List getAllCustomer(){ + return customerRepository.findAll(); + } + + public void addNewUser(Customer customer){ + customerRepository.save(customer); + } + + public void deleteUserById(int id){ + Optional customer = customerRepository.findById(id); + if(!customer.isPresent()){ + System.out.println("Customer not found"); + return; + } + customerRepository.delete(customer.get()); + } +} diff --git a/17020780_vu_van_hoc/mywallet/src/main/resources/application.properties b/17020780_vu_van_hoc/mywallet/src/main/resources/application.properties index 7911474..bf66b09 100644 --- a/17020780_vu_van_hoc/mywallet/src/main/resources/application.properties +++ b/17020780_vu_van_hoc/mywallet/src/main/resources/application.properties @@ -1,2 +1,10 @@ spring.mvc.view.suffix=.jsp spring.mvc.view.prefix=/WEB-INF/jsp/ + +spring.datasource.driver-class-name=com.mysql.jdbc.Driver +spring.datasource.url=jdbc:mysql://localhost:3306/my_system_wallet?useSSL=false&autoReconnect=true +spring.datasource.username=root +spring.datasource.password=28060101 +spring.jpa.show-sql=true +spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect + diff --git a/17020780_vu_van_hoc/mywallet/src/main/resources/customer.sql b/17020780_vu_van_hoc/mywallet/src/main/resources/customer.sql new file mode 100644 index 0000000..2eda19e --- /dev/null +++ b/17020780_vu_van_hoc/mywallet/src/main/resources/customer.sql @@ -0,0 +1,63 @@ +-- phpMyAdmin SQL Dump +-- version 4.8.5 +-- https://www.phpmyadmin.net/ +-- +-- Host: 127.0.0.1 +-- Generation Time: Jun 10, 2019 at 05:33 PM +-- Server version: 10.1.38-MariaDB +-- PHP Version: 7.3.2 + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +SET AUTOCOMMIT = 0; +START TRANSACTION; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; + +-- +-- Database: `my_walllet_systems` +-- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `customer` +-- + +CREATE TABLE `customer` ( + `cus_id` int(11) NOT NULL, + `cus_name` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, + `cus_email` varchar(100) NOT NULL, + `cus_phone` varchar(50) NOT NULL, + `cus_balance` double UNSIGNED NOT NULL, + `cus_created_date` datetime NOT NULL , + `cus_updated_date` datetime DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- +-- Indexes for dumped tables +-- + +-- +-- Indexes for table `customer` +-- +ALTER TABLE `customer` + ADD PRIMARY KEY (`cus_id`); +-- +-- AUTO_INCREMENT for dumped tables +-- + +-- +-- AUTO_INCREMENT for table `customer` +-- +ALTER TABLE `customer` + MODIFY `cus_id` int(11) NOT NULL AUTO_INCREMENT; +COMMIT; + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/home.jsp b/17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/home.jsp index 18c0c7d..b5d365a 100644 --- a/17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/home.jsp +++ b/17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/home.jsp @@ -1,5 +1,5 @@ -<%@ page import="com.uetcodecamp.vuvanhoc.objects.User" %> -<%@ page import="java.util.HashMap" %> +<%@ page import="com.uetcodecamp.vuvanhoc.model.Customer" %> +<%@ page import="java.util.List" %> <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %> @@ -41,23 +41,25 @@ <% - HashMap results = (HashMap) request.getAttribute("items"); - for(int key : results.keySet()) { + List customerList= (List) request.getAttribute("customerList"); + for (Customer c: customerList) { + + %> - - <%=results.get(key).getId()%> + + <%=c.getId()%> - <%=results.get(key).getName()%> + <%=c.getName()%> - <%=results.get(key).getEmail()%> + <%=c.getEmail()%> - <%=results.get(key).getPhone()%> + <%=c.getPhone()%> - <%=results.get(key).getBalance()%> + <%=c.getBalance()%> - - + + <% @@ -85,26 +87,24 @@ }, success:function () { window.location = "/sua-thong-tin?id=" + id; - } }) - } function removeUser(id) { if (!confirm("Bạn muốn xóa người dùng có mã ID: " + id +"?")) return ; - $.ajax({ - url: "/xoa-nguoi-dung", + $.delete({ + url: "/xoa-nguoi-dung?id=" + id, + type: 'DELETE', data:{ id:id }, success:function () { $("#"+id).remove(); + } }) alert("Xóa thành công người dùng có ID: " + id ); } - - diff --git a/17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/themUser.jsp b/17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/pageAddUser.jsp similarity index 95% rename from 17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/themUser.jsp rename to 17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/pageAddUser.jsp index 6d90fdc..8292f61 100644 --- a/17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/themUser.jsp +++ b/17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/pageAddUser.jsp @@ -20,7 +20,7 @@
-
+


diff --git a/17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/suaThongTin.jsp b/17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/pageEditUserInfor.jsp similarity index 76% rename from 17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/suaThongTin.jsp rename to 17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/pageEditUserInfor.jsp index 14da350..5c25926 100644 --- a/17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/suaThongTin.jsp +++ b/17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/pageEditUserInfor.jsp @@ -1,4 +1,4 @@ -<%@ page import="com.uetcodecamp.vuvanhoc.objects.User" %> +<%@ page import="com.uetcodecamp.vuvanhoc.model.Customer" %> <%@ page import="java.util.HashMap" %> <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %> @@ -23,23 +23,22 @@
<% - HashMap results = (HashMap) request.getAttribute("items"); - int key = (int) request.getAttribute("key"); + Customer customer = (Customer) request.getAttribute("customer"); %> - +

+ value="<%=customer.getName()%>">

+ value="<%=customer.getEmail()%>">

+ value="<%=customer.getPhone()%>">

+ value="<%=customer.getBalance()%>">
diff --git a/17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/thongTinTK.jsp b/17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/pageInforUser.jsp similarity index 59% rename from 17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/thongTinTK.jsp rename to 17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/pageInforUser.jsp index 210b5e4..80b316c 100644 --- a/17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/thongTinTK.jsp +++ b/17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/pageInforUser.jsp @@ -1,4 +1,4 @@ -<%@ page import="com.uetcodecamp.vuvanhoc.objects.User" %> +<%@ page import="com.uetcodecamp.vuvanhoc.model.Customer" %> <%@ page import="java.util.HashMap" %> <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %> @@ -23,16 +23,17 @@
<% - HashMap results = (HashMap) request.getAttribute("items"); - int key = (int) request.getAttribute("key"); + Customer customer = (Customer) request.getAttribute("customer"); %> -
+

- ID: <%=results.get(key).getId()%>

- Tên: <%=results.get(key).getName()%>

- Email: <%=results.get(key).getEmail()%>

- Phone: <%=results.get(key).getPhone()%>

- Số dư khả dụng: <%=results.get(key).getBalance()%> VNĐ

+ ID: <%=customer.getId()%>

+ Tên: <%=customer.getName()%>

+ Email: <%=customer.getEmail()%>

+ Phone: <%=customer.getPhone()%>

+ Số dư khả dụng: <%=customer.getBalance()%> VNĐ

+ Ngày tạo tài khoản:

+ Ngày cập nhật:

diff --git a/17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/dangNhap.jsp b/17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/pageLogin.jsp similarity index 100% rename from 17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/dangNhap.jsp rename to 17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/pageLogin.jsp diff --git a/17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/formChuyenTien.jsp b/17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/pageTransferMoney.jsp similarity index 94% rename from 17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/formChuyenTien.jsp rename to 17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/pageTransferMoney.jsp index 6af4ce0..8facd8b 100644 --- a/17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/formChuyenTien.jsp +++ b/17020780_vu_van_hoc/mywallet/src/main/webapp/WEB-INF/jsp/pageTransferMoney.jsp @@ -1,4 +1,4 @@ -<%@ page import="com.uetcodecamp.vuvanhoc.objects.User" %> +<%@ page import="com.uetcodecamp.vuvanhoc.model.Customer" %> <%@ page import="java.util.HashMap" %> <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>