From 0f14a293d3ba34c19dfbb6618d7c452417b1a874 Mon Sep 17 00:00:00 2001 From: ruong32 Date: Wed, 15 May 2019 19:55:49 +0700 Subject: [PATCH 1/5] bai 3 4 --- .../com/jwb/bankservice/AddingController.java | 4 +- .../java/com/jwb/bankservice/Customer.java | 5 +- .../com/jwb/bankservice/CustomerList.java | 24 ++- .../jwb/bankservice/DeletingController.java | 16 ++ .../bankservice/ListCustomerController.java | 3 +- .../main/java/com/jwb/bankservice/Search.java | 35 +++ .../bankservice/TransferingController.java | 17 +- .../main/webapp/WEB-INF/jsp/CustomerList.jsp | 155 ++++++++----- .../src/main/webapp/WEB-INF/jsp/Transfer.jsp | 2 + .../my_system/.idea/vcs.xml | 6 + .../my_system/.idea/workspace.xml | 204 ++++++++---------- .../jwb01/AddCustomerController.class | Bin 1128 -> 0 bytes .../com/uetcodecamp/jwb01/Application.class | Bin 731 -> 0 bytes .../com/uetcodecamp/jwb01/Customer.class | Bin 1626 -> 0 bytes .../com/uetcodecamp/jwb01/Customers.class | Bin 510 -> 0 bytes .../jwb01/EditCustomerController.class | Bin 1485 -> 0 bytes .../uetcodecamp/jwb01/HomeController.class | Bin 2082 -> 0 bytes .../uetcodecamp/jwb01/LoginController.class | Bin 2167 -> 0 bytes .../jwb01/TransfersController.class | Bin 2595 -> 0 bytes 18020020_Chu_Van_Hung/my_system/.classpath | 49 +++++ 18020020_Chu_Van_Hung/my_system/.project | 23 ++ .../org.eclipse.core.resources.prefs | 4 + .../.settings/org.eclipse.jdt.apt.core.prefs | 2 + .../.settings/org.eclipse.jdt.core.prefs | 10 + .../.settings/org.eclipse.m2e.core.prefs | 4 + .../my_system/.vscode/launch.json | 11 + .../com/uetcodecamp/jwb01/Application.class | Bin 1276 -> 1276 bytes .../uetcodecamp/jwb01/HelloController.class | Bin 3670 -> 3670 bytes .../classes/com/uetcodecamp/jwb01/User.class | Bin 1172 -> 1172 bytes 29 files changed, 388 insertions(+), 186 deletions(-) create mode 100644 17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/DeletingController.java create mode 100644 17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/Search.java create mode 100644 17021115_vu_van_tung/FirstProjectSpringBoot/my_system/.idea/vcs.xml delete mode 100644 17021115_vu_van_tung/FirstProjectSpringBoot/my_system/target/classes/com/uetcodecamp/jwb01/AddCustomerController.class delete mode 100644 17021115_vu_van_tung/FirstProjectSpringBoot/my_system/target/classes/com/uetcodecamp/jwb01/Application.class delete mode 100644 17021115_vu_van_tung/FirstProjectSpringBoot/my_system/target/classes/com/uetcodecamp/jwb01/Customer.class delete mode 100644 17021115_vu_van_tung/FirstProjectSpringBoot/my_system/target/classes/com/uetcodecamp/jwb01/Customers.class delete mode 100644 17021115_vu_van_tung/FirstProjectSpringBoot/my_system/target/classes/com/uetcodecamp/jwb01/EditCustomerController.class delete mode 100644 17021115_vu_van_tung/FirstProjectSpringBoot/my_system/target/classes/com/uetcodecamp/jwb01/HomeController.class delete mode 100644 17021115_vu_van_tung/FirstProjectSpringBoot/my_system/target/classes/com/uetcodecamp/jwb01/LoginController.class delete mode 100644 17021115_vu_van_tung/FirstProjectSpringBoot/my_system/target/classes/com/uetcodecamp/jwb01/TransfersController.class create mode 100644 18020020_Chu_Van_Hung/my_system/.classpath create mode 100644 18020020_Chu_Van_Hung/my_system/.project create mode 100644 18020020_Chu_Van_Hung/my_system/.settings/org.eclipse.core.resources.prefs create mode 100644 18020020_Chu_Van_Hung/my_system/.settings/org.eclipse.jdt.apt.core.prefs create mode 100644 18020020_Chu_Van_Hung/my_system/.settings/org.eclipse.jdt.core.prefs create mode 100644 18020020_Chu_Van_Hung/my_system/.settings/org.eclipse.m2e.core.prefs create mode 100644 18020020_Chu_Van_Hung/my_system/.vscode/launch.json diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/AddingController.java b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/AddingController.java index f4417f5..8611172 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/AddingController.java +++ b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/AddingController.java @@ -8,9 +8,7 @@ public class AddingController { @PostMapping(value="/add-customer") public String addCustomer(@ModelAttribute("customerInfo") Customer customer) { - int id = CustomerList.customerList.size(); - customer.setId(id); - CustomerList.customerList.add(customer); + CustomerList.addCustomer(customer); return "redirect:/customer-list"; } } \ No newline at end of file diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/Customer.java b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/Customer.java index f37ee1a..03ae24c 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/Customer.java +++ b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/Customer.java @@ -3,14 +3,13 @@ public class Customer { private String name, email, phoneNumber, password = "123456"; - private int id, balance, login = 0; + private int id, balance, login = 1; public Customer() { } - public Customer(int id, String name, String email, String phoneNumber, int balance) { - this.id = id; + public Customer(String name, String email, String phoneNumber, int balance) { this.name = name; this.email = email; this.phoneNumber = phoneNumber; diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/CustomerList.java b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/CustomerList.java index 0088bd6..0134590 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/CustomerList.java +++ b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/CustomerList.java @@ -4,8 +4,28 @@ public class CustomerList { public static ArrayList customerList = new ArrayList(); + private static int id = 0; + + public static void addCustomer(Customer ctm){ + ctm.setId(id); + customerList.add(ctm); + id++; + } + + public static void delCustomerList(int id){ + int n = customerList.size(); + for(int i=0; i search(String data){ + String result = new String(); + ArrayList listResult = new ArrayList<>(); + for(Customer customer : CustomerList.customerList){ + if (customer.getName().contains(data) || customer.getEmail().contains(data) || customer.getPhoneNumber().contains(data)){ + result += " " + customer.getName() + " " + customer.getEmail() + " " + customer.getPhoneNumber() + " "; + listResult.add(result); + result = ""; + } + } + return listResult; + } + + @PostMapping(value="/search") + public ArrayList searchCustomer(@RequestBody String data) { + int n = data.length(); + data = data.substring(1, n-1); + ArrayList listResult = search(data); + System.out.println(listResult); + return listResult; + } +} \ No newline at end of file diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/TransferingController.java b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/TransferingController.java index 7cae1f8..6802857 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/TransferingController.java +++ b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/TransferingController.java @@ -8,11 +8,16 @@ public class TransferingController { @PostMapping(value="/transfer") public String transfer(@RequestParam(name = "sentId") Integer sId, @RequestParam(name="receivedId") Integer rId, @RequestParam(name="amount") Integer amount){ - if (rId >= CustomerList.customerList.size() || rId == sId) return "Error"; - else{ - CustomerList.customerList.get(sId).transferMoney(amount); - CustomerList.customerList.get(rId).receiveMoney(amount); - } - return "redirect:/customer-list"; + if (rId == sId) return "Error"; + System.out.println(rId); + int n = CustomerList.customerList.size(); + for(int i=0; i - - - Customer list - - - - -
- - + + + + Customer list + + + + + + +
+ +
+
+
+ + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + +
IdNameEmailPhoneBalance
NameEmailPhoneBalance
${customer.name}${customer.email}${customer.phoneNumber}${customer.balance} -
- - -
+
${customer.id}${customer.name}${customer.email}${customer.phoneNumber}${customer.balance} +
+ + +
+ +
+ + + +
-
- - -
+
+ + +
+ +
+
+ + +
+
+
+ -
- - -
- - - - -
- - -
- -
- - - - - - - \ No newline at end of file diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Transfer.jsp b/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Transfer.jsp index fbb8e83..81e30d9 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Transfer.jsp +++ b/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Transfer.jsp @@ -9,6 +9,8 @@
Transfer + Available:
+
${balance} $
ID:

diff --git a/17021115_vu_van_tung/FirstProjectSpringBoot/my_system/.idea/vcs.xml b/17021115_vu_van_tung/FirstProjectSpringBoot/my_system/.idea/vcs.xml new file mode 100644 index 0000000..c2365ab --- /dev/null +++ b/17021115_vu_van_tung/FirstProjectSpringBoot/my_system/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/17021115_vu_van_tung/FirstProjectSpringBoot/my_system/.idea/workspace.xml b/17021115_vu_van_tung/FirstProjectSpringBoot/my_system/.idea/workspace.xml index a7cf663..3735200 100644 --- a/17021115_vu_van_tung/FirstProjectSpringBoot/my_system/.idea/workspace.xml +++ b/17021115_vu_van_tung/FirstProjectSpringBoot/my_system/.idea/workspace.xml @@ -1,7 +1,20 @@ - + + + + + + + + + + + + + +
- - + + + + + Add customer + + + +
+
+ Add customer + + +
+ +
+ +
+ +
+ +
+
+
+ + \ No newline at end of file diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/CustomerList.jsp b/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/CustomerList.jsp index 997030f..4e4594b 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/CustomerList.jsp +++ b/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/CustomerList.jsp @@ -17,8 +17,8 @@ } $(document).ready(function () { - $("#search").keyup(function () { - var info = $("#search").val(); + $("#searchInput").keyup(function () { + var info = $("#searchInput").val(); if (info != "") { $.ajax({ type: "POST", @@ -44,8 +44,8 @@ -
- +
@@ -57,7 +57,7 @@ Email Phone Balance - + @@ -69,36 +69,43 @@ ${customer.phoneNumber} ${customer.balance} - + - + - + +
- +
+ + + + +
- +
-
- +
- +
- + + +
diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Edit.jsp b/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Edit.jsp index 949502d..8473801 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Edit.jsp +++ b/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Edit.jsp @@ -4,21 +4,22 @@ + Edit customer
Edit customer - Name:
+
- Email:
+
- Phone number:
+
- Password:
-
- + +
+
diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Error.jsp b/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Error.jsp index 1344bec..6ac5b41 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Error.jsp +++ b/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Error.jsp @@ -4,11 +4,10 @@ Error +

Error!

-
- -
+ back to Home \ No newline at end of file diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Login.jsp b/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Login.jsp index 597f02e..243ce10 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Login.jsp +++ b/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Login.jsp @@ -3,6 +3,7 @@ + Login @@ -14,7 +15,7 @@
Password:

- + diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Transfer.jsp b/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Transfer.jsp index 81e30d9..1222aec 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Transfer.jsp +++ b/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Transfer.jsp @@ -3,20 +3,20 @@ + Transfer -
+
Transfer - Available:
-
${balance} $
- ID:
-
+
+ +
- Amount:
-
- + +
+
From ec5b39806bb0dd20fc133e494a9d24633df3e82c Mon Sep 17 00:00:00 2001 From: ruong32 Date: Sun, 19 May 2019 15:44:56 +0700 Subject: [PATCH 3/5] bai 3 4 update --- .../com/jwb/bankservice/AddingController.java | 9 +- .../jwb/bankservice/DeletingController.java | 8 +- .../jwb/bankservice/EditingController.java | 13 +-- .../bankservice/ListCustomerController.java | 15 +++- .../com/jwb/bankservice/LoginController.java | 11 ++- .../com/jwb/bankservice/LogoutController.java | 8 +- .../main/java/com/jwb/bankservice/Search.java | 21 ++--- .../bankservice/TransferingController.java | 19 ++--- .../com/jwb/bankservice/models/Customer.java | 82 +++++++++++++++++++ .../repositories/CustomerList.java | 34 ++++++++ .../services/CustomerServices.java | 75 +++++++++++++++++ .../main/webapp/WEB-INF/jsp/CustomerList.jsp | 2 +- .../src/main/webapp/WEB-INF/jsp/Edit.jsp | 1 + .../src/main/webapp/WEB-INF/jsp/Login.jsp | 5 +- .../src/main/webapp/WEB-INF/jsp/Transfer.jsp | 3 +- 15 files changed, 261 insertions(+), 45 deletions(-) create mode 100644 17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/models/Customer.java create mode 100644 17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/repositories/CustomerList.java create mode 100644 17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/services/CustomerServices.java diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/AddingController.java b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/AddingController.java index 8611172..a8b83bb 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/AddingController.java +++ b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/AddingController.java @@ -1,14 +1,21 @@ package com.jwb.bankservice; +import com.jwb.bankservice.models.Customer; +import com.jwb.bankservice.services.CustomerServices; + +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; @Controller public class AddingController { + @Autowired + CustomerServices cServices; + @PostMapping(value="/add-customer") public String addCustomer(@ModelAttribute("customerInfo") Customer customer) { - CustomerList.addCustomer(customer); + cServices.addCustomer(customer); return "redirect:/customer-list"; } } \ No newline at end of file diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/DeletingController.java b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/DeletingController.java index 07b6a92..c8bcf81 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/DeletingController.java +++ b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/DeletingController.java @@ -1,5 +1,8 @@ package com.jwb.bankservice; +import com.jwb.bankservice.services.CustomerServices; + +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RequestBody; @@ -7,10 +10,13 @@ @RestController public class DeletingController { + @Autowired + CustomerServices cServices; + @PostMapping(value="/delete") public void delCustomer(@RequestBody String delId) { delId = delId.substring(3,delId.length()); int id = Integer.parseInt(delId); - CustomerList.delCustomerList(id); + cServices.delCustomerList(id); } } \ No newline at end of file diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/EditingController.java b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/EditingController.java index 0bedf2d..209e500 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/EditingController.java +++ b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/EditingController.java @@ -1,18 +1,21 @@ package com.jwb.bankservice; +import com.jwb.bankservice.models.Customer; +import com.jwb.bankservice.services.CustomerServices; + +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; @Controller public class EditingController { + @Autowired + CustomerServices cServices; + @PostMapping(value="/edit-customer") public String addCustomer(@ModelAttribute("customerInfo") Customer customer) { - int id = CustomerList.customerList.size()-1; - CustomerList.customerList.get(id).setName(customer.getName()); - CustomerList.customerList.get(id).setEmail(customer.getEmail()); - CustomerList.customerList.get(id).setPhoneNumber(customer.getPhoneNumber()); - CustomerList.customerList.get(id).setPassword(customer.getPassword()); + cServices.editCustomer(customer); return "redirect:/customer-list"; } } \ No newline at end of file diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/ListCustomerController.java b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/ListCustomerController.java index 12103be..f6a8ade 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/ListCustomerController.java +++ b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/ListCustomerController.java @@ -1,18 +1,25 @@ package com.jwb.bankservice; +import com.jwb.bankservice.models.Customer; +import com.jwb.bankservice.services.CustomerServices; + +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; @Controller public class ListCustomerController { + @Autowired + CustomerServices cServices; @RequestMapping(value = {"/", "/customer-list" }, method = RequestMethod.GET) public String index(ModelMap modelMap) { - modelMap.addAttribute("customerList", CustomerList.customerList); + modelMap.addAttribute("customerList", cServices.getAllCustomer()); return "CustomerList"; } @@ -23,15 +30,15 @@ public String addForm(ModelMap modelmap) { } @GetMapping(value="/editing-form") public String editForm(@RequestParam(name="customerId") Integer id, ModelMap modelMap) { - modelMap.addAttribute("customerInfo", CustomerList.customerList.get(id)); + modelMap.addAttribute("customerInfo", cServices.getCustomer(id)); return "Edit"; } @GetMapping(value="/login-form") public String loginForm(@RequestParam(name="customerId") Integer id, ModelMap modelMap){ - modelMap.addAttribute("customerInfo", CustomerList.customerList.get(id)); + modelMap.addAttribute("customerInfo", cServices.getCustomer(id)); return "Login"; } - @GetMapping(value="/transfering-form") + @PostMapping(value="/transfering-form") public String transferingForm(@RequestParam(name="customerId") Integer id, @RequestParam(name="availableBalance") Integer balance, ModelMap modelMap){ modelMap.addAttribute("customerId", id); modelMap.addAttribute("balance", balance); diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/LoginController.java b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/LoginController.java index e1a8e61..c2af74e 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/LoginController.java +++ b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/LoginController.java @@ -1,16 +1,21 @@ package com.jwb.bankservice; +import com.jwb.bankservice.services.CustomerServices; + +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; @Controller public class LoginController { + @Autowired + CustomerServices cServices; + @PostMapping(value="/login") public String addCustomer(@RequestParam(name="id") Integer id, @RequestParam(name="pw") String password) { - System.out.println(id); - if (CustomerList.customerList.get(id).getPassword().equals(password)){ - CustomerList.customerList.get(id).setLogin(1); + if (cServices.getCustomer(id).getPassword().equals(password)){ + cServices.getCustomer(id).setLogin(1); } return "redirect:/customer-list"; } diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/LogoutController.java b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/LogoutController.java index 5ddec68..5ec7710 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/LogoutController.java +++ b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/LogoutController.java @@ -1,14 +1,20 @@ package com.jwb.bankservice; +import com.jwb.bankservice.services.CustomerServices; + +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; @Controller public class LogoutController { + @Autowired + CustomerServices cServices; + @GetMapping(value="/logout") public String logout(@RequestParam(name="customerId") Integer id){ - CustomerList.customerList.get(id).setLogin(0); + cServices.getCustomer(id).setLogin(0); return "redirect:/customer-list"; } } \ No newline at end of file diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/Search.java b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/Search.java index de6f9c3..6cdd0b3 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/Search.java +++ b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/Search.java @@ -4,32 +4,23 @@ import java.util.ArrayList; +import com.jwb.bankservice.services.CustomerServices; + +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @RestController public class Search { - - private ArrayList search(String data){ - String result = new String(); - ArrayList listResult = new ArrayList<>(); - for(Customer customer : CustomerList.customerList){ - if (customer.getName().contains(data) || customer.getEmail().contains(data) || customer.getPhoneNumber().contains(data)){ - result += " " + customer.getName() + " " + customer.getEmail() + " " + customer.getPhoneNumber() + " Edit "; - listResult.add(result); - result = ""; - } - } - return listResult; - } + @Autowired + CustomerServices cServices; @PostMapping(value="/search") public ArrayList searchCustomer(@RequestBody String data) { int n = data.length(); data = data.substring(1, n-1); - ArrayList listResult = search(data); - System.out.println(listResult); + ArrayList listResult = cServices.search(data); return listResult; } } \ No newline at end of file diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/TransferingController.java b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/TransferingController.java index 6802857..09d1cb7 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/TransferingController.java +++ b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/TransferingController.java @@ -1,23 +1,22 @@ package com.jwb.bankservice; +import com.jwb.bankservice.services.CustomerServices; + +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; @Controller public class TransferingController { + @Autowired + CustomerServices cServices; + @PostMapping(value="/transfer") public String transfer(@RequestParam(name = "sentId") Integer sId, @RequestParam(name="receivedId") Integer rId, @RequestParam(name="amount") Integer amount){ if (rId == sId) return "Error"; - System.out.println(rId); - int n = CustomerList.customerList.size(); - for(int i=0; i cServices.getCustomer(sId).getBalance()) return "Error"; + cServices.transferMoney(sId, rId, amount); + return "redirect:/"; } } \ No newline at end of file diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/models/Customer.java b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/models/Customer.java new file mode 100644 index 0000000..1b922ab --- /dev/null +++ b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/models/Customer.java @@ -0,0 +1,82 @@ +package com.jwb.bankservice.models; + +public class Customer { + + private String name, email, phoneNumber, password = "123456"; + private int id, balance, login = 1; + + public Customer() { + + } + + public Customer(String name, String email, String phoneNumber, int balance) { + this.name = name; + this.email = email; + this.phoneNumber = phoneNumber; + this.balance = balance; + } + + public int getId(){ + return id; + } + + public void setId(int id){ + this.id = id; + } + + public int getLogin(){ + return login; + } + + public void setLogin(int isLogin){ + this.login = isLogin; + } + + public String getPassword(){ + return password; + } + + public void setPassword(String newPw){ + this.password = newPw; + } + + 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 getPhoneNumber() { + return phoneNumber; + } + + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + public int getBalance() { + return balance; + } + + public void setBalance(int balance) { + this.balance = balance; + } + + public void transferMoney(int amount){ + balance -= amount; + } + + public void receiveMoney(int amount){ + balance += amount; + } +} \ No newline at end of file diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/repositories/CustomerList.java b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/repositories/CustomerList.java new file mode 100644 index 0000000..298bc7d --- /dev/null +++ b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/repositories/CustomerList.java @@ -0,0 +1,34 @@ +package com.jwb.bankservice.repositories; + +import java.util.ArrayList; +import com.jwb.bankservice.models.Customer; +import org.springframework.stereotype.Repository; + +@Repository +public class CustomerList { + public ArrayList customerList = new ArrayList(); + // private static int id = 0; + + // public static void addCustomer(Customer ctm){ + // ctm.setId(id); + // customerList.add(ctm); + // id++; + // } + + // public static void delCustomerList(int id){ + // int n = customerList.size(); + // for(int i=0; i getAllCustomer(){ + return cList.customerList; + } + + public void addCustomer(Customer ctm){ + ctm.setId(id); + cList.customerList.add(ctm); + id++; + } + + public void delCustomerList(int id){ + int n = cList.customerList.size(); + for(int i=0; i search(String data){ + String result = new String(); + ArrayList listResult = new ArrayList<>(); + for(Customer customer : getAllCustomer()){ + if (customer.getName().contains(data) || customer.getEmail().contains(data) || customer.getPhoneNumber().contains(data)){ + result += " " + customer.getName() + " " + customer.getEmail() + " " + customer.getPhoneNumber() + " Edit "; + listResult.add(result); + result = ""; + } + } + return listResult; + } +} \ No newline at end of file diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/CustomerList.jsp b/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/CustomerList.jsp index 4e4594b..4f31ba0 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/CustomerList.jsp +++ b/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/CustomerList.jsp @@ -76,7 +76,7 @@ -
+ diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Edit.jsp b/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Edit.jsp index 8473801..3a0c514 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Edit.jsp +++ b/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Edit.jsp @@ -11,6 +11,7 @@
Edit customer +
diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Login.jsp b/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Login.jsp index 243ce10..bc66054 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Login.jsp +++ b/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Login.jsp @@ -10,10 +10,9 @@
Login - Email:
- ${customerInfo.email}
+

- Password:
+ Password:
diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Transfer.jsp b/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Transfer.jsp index 1222aec..2c267ef 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Transfer.jsp +++ b/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Transfer.jsp @@ -10,7 +10,8 @@
Transfer -
+
+

From 7a82fbec4073fc7f9889b0c595e580e8364ec2c1 Mon Sep 17 00:00:00 2001 From: ruong32 Date: Tue, 25 Jun 2019 10:39:23 +0700 Subject: [PATCH 4/5] csdl --- 17020996_nguyen_trong_ruong/my-system/pom.xml | 39 +++++++--- .../com/jwb/bankservice/AddingController.java | 10 +-- .../jwb/bankservice/EditingController.java | 10 +-- .../bankservice/ListCustomerController.java | 27 ++----- .../com/jwb/bankservice/LoginController.java | 14 +++- .../com/jwb/bankservice/LogoutController.java | 2 +- .../main/java/com/jwb/bankservice/Search.java | 6 +- .../bankservice/TransferingController.java | 8 ++ .../com/jwb/bankservice/models/Customer.java | 31 +++++--- .../repositories/CustomerRepository.java | 10 +++ .../services/CustomerServices.java | 72 ++++++++--------- .../src/main/resources/application.properties | 15 +++- .../src/main/resources/static/css/Add.css | 2 - .../src/main/resources/static/css/Edit.css | 2 - .../src/main/resources/static/css/Login.css | 51 ++++++------ .../main/resources/static/css/Transfer.css | 1 - .../src/main/webapp/WEB-INF/jsp/Add.jsp | 61 +++++++++++---- .../src/main/webapp/WEB-INF/jsp/Edit.jsp | 78 +++++++++++++------ .../src/main/webapp/WEB-INF/jsp/Login.jsp | 37 +++++---- .../src/main/webapp/WEB-INF/jsp/Transfer.jsp | 4 +- 20 files changed, 295 insertions(+), 185 deletions(-) create mode 100644 17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/repositories/CustomerRepository.java diff --git a/17020996_nguyen_trong_ruong/my-system/pom.xml b/17020996_nguyen_trong_ruong/my-system/pom.xml index eb4a84e..e966c69 100644 --- a/17020996_nguyen_trong_ruong/my-system/pom.xml +++ b/17020996_nguyen_trong_ruong/my-system/pom.xml @@ -19,12 +19,12 @@ - - org.springframework.boot - spring-boot-starter-web - - - + + org.springframework.boot + spring-boot-starter-web + + + org.apache.tomcat.embed tomcat-embed-jasper @@ -33,13 +33,28 @@ javax.servlet jstl + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + + + mysql + mysql-connector-java + + + + + org.springframework.boot + spring-boot-starter-test + test + - - org.springframework.boot - spring-boot-starter-test - test - - + diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/AddingController.java b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/AddingController.java index a8b83bb..1998434 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/AddingController.java +++ b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/AddingController.java @@ -4,18 +4,18 @@ import com.jwb.bankservice.services.CustomerServices; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; -@Controller +@RestController public class AddingController { @Autowired CustomerServices cServices; @PostMapping(value="/add-customer") - public String addCustomer(@ModelAttribute("customerInfo") Customer customer) { + public String addCustomer(@RequestBody Customer customer) { cServices.addCustomer(customer); - return "redirect:/customer-list"; + return "/"; } } \ No newline at end of file diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/EditingController.java b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/EditingController.java index 209e500..f6cdcb8 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/EditingController.java +++ b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/EditingController.java @@ -4,18 +4,18 @@ import com.jwb.bankservice.services.CustomerServices; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; -@Controller +@RestController public class EditingController { @Autowired CustomerServices cServices; @PostMapping(value="/edit-customer") - public String addCustomer(@ModelAttribute("customerInfo") Customer customer) { + public String addCustomer(@RequestBody Customer customer) { cServices.editCustomer(customer); - return "redirect:/customer-list"; + return "/"; } } \ No newline at end of file diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/ListCustomerController.java b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/ListCustomerController.java index f6a8ade..9c73355 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/ListCustomerController.java +++ b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/ListCustomerController.java @@ -7,9 +7,6 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; @Controller @@ -17,31 +14,21 @@ public class ListCustomerController { @Autowired CustomerServices cServices; - @RequestMapping(value = {"/", "/customer-list" }, method = RequestMethod.GET) + @GetMapping(value = {"/", "/customer-list" }) public String index(ModelMap modelMap) { modelMap.addAttribute("customerList", cServices.getAllCustomer()); return "CustomerList"; } - @RequestMapping(value = { "/adding-form" }, method = RequestMethod.GET) - public String addForm(ModelMap modelmap) { - modelmap.addAttribute("customerInfo", new Customer()); - return "Add"; - } @GetMapping(value="/editing-form") public String editForm(@RequestParam(name="customerId") Integer id, ModelMap modelMap) { - modelMap.addAttribute("customerInfo", cServices.getCustomer(id)); + Customer c = cServices.getCustomer(id); + modelMap.addAttribute("customerInfo", c); return "Edit"; } - @GetMapping(value="/login-form") - public String loginForm(@RequestParam(name="customerId") Integer id, ModelMap modelMap){ - modelMap.addAttribute("customerInfo", cServices.getCustomer(id)); - return "Login"; - } - @PostMapping(value="/transfering-form") - public String transferingForm(@RequestParam(name="customerId") Integer id, @RequestParam(name="availableBalance") Integer balance, ModelMap modelMap){ - modelMap.addAttribute("customerId", id); - modelMap.addAttribute("balance", balance); - return "Transfer"; + + @GetMapping(value = { "/adding-form" }) + public String addForm(ModelMap modelmap) { + return "Add"; } } \ No newline at end of file diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/LoginController.java b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/LoginController.java index c2af74e..ce76ca0 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/LoginController.java +++ b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/LoginController.java @@ -4,6 +4,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -12,11 +14,17 @@ public class LoginController { @Autowired CustomerServices cServices; + @GetMapping(value="/login-form") + public String loginForm(@RequestParam(name="customerId") Integer id, ModelMap modelMap){ + modelMap.addAttribute("customerInfo", cServices.getCustomer(id)); + return "Login"; + } + @PostMapping(value="/login") public String addCustomer(@RequestParam(name="id") Integer id, @RequestParam(name="pw") String password) { - if (cServices.getCustomer(id).getPassword().equals(password)){ - cServices.getCustomer(id).setLogin(1); + if (cServices.login(id, password)){ + return "redirect:/customer-list"; } - return "redirect:/customer-list"; + return "Error"; } } \ No newline at end of file diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/LogoutController.java b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/LogoutController.java index 5ec7710..fb90c5f 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/LogoutController.java +++ b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/LogoutController.java @@ -14,7 +14,7 @@ public class LogoutController { @GetMapping(value="/logout") public String logout(@RequestParam(name="customerId") Integer id){ - cServices.getCustomer(id).setLogin(0); + cServices.logout(id); return "redirect:/customer-list"; } } \ No newline at end of file diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/Search.java b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/Search.java index 6cdd0b3..4c31e27 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/Search.java +++ b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/Search.java @@ -2,7 +2,7 @@ import org.springframework.web.bind.annotation.RestController; -import java.util.ArrayList; +import java.util.List; import com.jwb.bankservice.services.CustomerServices; @@ -17,10 +17,10 @@ public class Search { CustomerServices cServices; @PostMapping(value="/search") - public ArrayList searchCustomer(@RequestBody String data) { + public List searchCustomer(@RequestBody String data) { int n = data.length(); data = data.substring(1, n-1); - ArrayList listResult = cServices.search(data); + List listResult = cServices.search(data); return listResult; } } \ No newline at end of file diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/TransferingController.java b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/TransferingController.java index 09d1cb7..cafb6fc 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/TransferingController.java +++ b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/TransferingController.java @@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -12,6 +13,13 @@ public class TransferingController { @Autowired CustomerServices cServices; + @PostMapping(value="/transfering-form") + public String transferingForm(@RequestParam(name="customerId") Integer id, @RequestParam(name="availableBalance") Integer balance, ModelMap modelMap){ + modelMap.addAttribute("customerId", id); + modelMap.addAttribute("balance", balance); + return "Transfer"; + } + @PostMapping(value="/transfer") public String transfer(@RequestParam(name = "sentId") Integer sId, @RequestParam(name="receivedId") Integer rId, @RequestParam(name="amount") Integer amount){ if (rId == sId) return "Error"; diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/models/Customer.java b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/models/Customer.java index 1b922ab..6f6acd6 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/models/Customer.java +++ b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/models/Customer.java @@ -1,21 +1,32 @@ package com.jwb.bankservice.models; +import javax.persistence.*; + +@Entity +@Table(name = "Customer") public class Customer { + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + private int id; - private String name, email, phoneNumber, password = "123456"; - private int id, balance, login = 1; + @Column(name = "name") + private String name; - public Customer() { + @Column(name = "email") + private String email; - } + @Column(name = "phone") + private String phoneNumber; - public Customer(String name, String email, String phoneNumber, int balance) { - this.name = name; - this.email = email; - this.phoneNumber = phoneNumber; - this.balance = balance; - } + @Column(name = "password") + private String password = "123456"; + + @Column(name = "balance") + private int balance; + @Column(name = "login") + private int login = 1; + public int getId(){ return id; } diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/repositories/CustomerRepository.java b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/repositories/CustomerRepository.java new file mode 100644 index 0000000..8abff5e --- /dev/null +++ b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/repositories/CustomerRepository.java @@ -0,0 +1,10 @@ +package com.jwb.bankservice.repositories; + +import com.jwb.bankservice.models.Customer; +import org.springframework.stereotype.Repository; +import org.springframework.data.jpa.repository.JpaRepository; + +@Repository +public interface CustomerRepository extends JpaRepository{ + +} \ No newline at end of file diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/services/CustomerServices.java b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/services/CustomerServices.java index d77811f..d8244f0 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/services/CustomerServices.java +++ b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/services/CustomerServices.java @@ -1,68 +1,68 @@ package com.jwb.bankservice.services; -import java.util.ArrayList; - import com.jwb.bankservice.models.Customer; -import com.jwb.bankservice.repositories.CustomerList; +import com.jwb.bankservice.repositories.CustomerRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.List; + @Service public class CustomerServices { @Autowired - CustomerList cList; - private static int id = 0; + private CustomerRepository customerRepository; public Customer getCustomer(int id){ - for(Customer c : cList.customerList){ - if (c.getId() == id) return c; - } - return null; + return customerRepository.getOne(id); } - public ArrayList getAllCustomer(){ - return cList.customerList; + public List getAllCustomer(){ + return customerRepository.findAll(); } public void addCustomer(Customer ctm){ - ctm.setId(id); - cList.customerList.add(ctm); - id++; + customerRepository.save(ctm); } public void delCustomerList(int id){ - int n = cList.customerList.size(); - for(int i=0; i search(String data){ + public List search(String data){ String result = new String(); - ArrayList listResult = new ArrayList<>(); + + List listResult = new ArrayList<>(); for(Customer customer : getAllCustomer()){ if (customer.getName().contains(data) || customer.getEmail().contains(data) || customer.getPhoneNumber().contains(data)){ result += " " + customer.getName() + " " + customer.getEmail() + " " + customer.getPhoneNumber() + " Edit "; diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/resources/application.properties b/17020996_nguyen_trong_ruong/my-system/src/main/resources/application.properties index 3bf1cbf..2cccfed 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/resources/application.properties +++ b/17020996_nguyen_trong_ruong/my-system/src/main/resources/application.properties @@ -1,2 +1,15 @@ +server.port=8080 + spring.mvc.view.prefix=/WEB-INF/jsp/ -spring.mvc.view.suffix=.jsp \ No newline at end of file +spring.mvc.view.suffix=.jsp + +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver +spring.datasource.url = jdbc:mysql://localhost:3306/bankdata +spring.datasource.username=root +spring.datasource.password=ruong0302 + +spring.jpa.show-sql=true +spring.jpa.properties.hibernate.format_sql=true +spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect +spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext +spring.jpa.hibernate.ddl-auto=update \ No newline at end of file diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/resources/static/css/Add.css b/17020996_nguyen_trong_ruong/my-system/src/main/resources/static/css/Add.css index 0349bf2..620c850 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/resources/static/css/Add.css +++ b/17020996_nguyen_trong_ruong/my-system/src/main/resources/static/css/Add.css @@ -8,7 +8,6 @@ text-align: center; background-color: #15ace6; border: none; - padding: 10px 36px; border-radius: 3px; color: white; cursor: pointer; @@ -22,7 +21,6 @@ input { height: 38px; border-radius: 3px; border: none; - /* text-align: left; */ margin-bottom: 30px; text-indent: 10px; } diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/resources/static/css/Edit.css b/17020996_nguyen_trong_ruong/my-system/src/main/resources/static/css/Edit.css index bfdb498..bca2e01 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/resources/static/css/Edit.css +++ b/17020996_nguyen_trong_ruong/my-system/src/main/resources/static/css/Edit.css @@ -8,7 +8,6 @@ text-align: center; background-color: #15ace6; border: none; - padding: 10px 36px; border-radius: 3px; color: white; cursor: pointer; @@ -22,7 +21,6 @@ input { height: 38px; border-radius: 3px; border: none; - /* text-align: left; */ margin-bottom: 30px; text-indent: 10px; } diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/resources/static/css/Login.css b/17020996_nguyen_trong_ruong/my-system/src/main/resources/static/css/Login.css index bfdb498..2af7cc0 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/resources/static/css/Login.css +++ b/17020996_nguyen_trong_ruong/my-system/src/main/resources/static/css/Login.css @@ -1,20 +1,19 @@ -.submit:hover { - background-color: #104f66; +fieldset { + padding-top: 12px; + padding-bottom: 12px; + background-color: #4CAF50; color: white; + text-align: center; + width: 480px; + height: 480px; + margin: auto; } -.submit { - width: 120px; - text-align: center; - background-color: #15ace6; - border: none; - padding: 10px 36px; - border-radius: 3px; - color: white; - cursor: pointer; - outline: none; +label { + width: 130px; + text-align: left; font-size: 20px; - margin: auto; + float: left; } input { @@ -27,14 +26,22 @@ input { text-indent: 10px; } - -fieldset { - padding-top: 12px; - padding-bottom: 12px; - background-color: #4CAF50; +.submit:hover { + background-color: #104f66; color: white; +} + +.submit { + width: 120px; text-align: center; - width: 480px; + background-color: #15ace6; + border: none; + padding: 10px 36px; + border-radius: 3px; + color: white; + cursor: pointer; + outline: none; + font-size: 20px; margin: auto; } @@ -46,12 +53,6 @@ legend { font-size: 25px; } -label { - width: 130px; - text-align: left; - font-size: 20px; - float: left; -} body{ background-color: aliceblue; } \ No newline at end of file diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/resources/static/css/Transfer.css b/17020996_nguyen_trong_ruong/my-system/src/main/resources/static/css/Transfer.css index e86f8f0..cbfd6e4 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/resources/static/css/Transfer.css +++ b/17020996_nguyen_trong_ruong/my-system/src/main/resources/static/css/Transfer.css @@ -8,7 +8,6 @@ text-align: center; background-color: #15ace6; border: none; - padding: 10px 36px; border-radius: 3px; color: white; cursor: pointer; diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Add.jsp b/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Add.jsp index fd6bbe1..843833a 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Add.jsp +++ b/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Add.jsp @@ -1,5 +1,6 @@ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> -<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> +<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %> + @@ -7,25 +8,51 @@ Add customer + + -
-
- Add customer - - -
- -
- -
- -
- -
-
-
+
+ Add customer + +
+ +
+ +
+ +
+ +
+

+ +
\ No newline at end of file diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Edit.jsp b/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Edit.jsp index 3a0c514..5106401 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Edit.jsp +++ b/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Edit.jsp @@ -1,27 +1,59 @@ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> -<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> +<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %> + - - - - Edit customer - - - -
- Edit customer - - -
- -
- -
- -
- -
-
- + + + + + Edit customer + + + + + + +
+ Edit customer + + +
+ +
+ +
+ +
+ + + +
+ + \ No newline at end of file diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Login.jsp b/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Login.jsp index bc66054..ea101f4 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Login.jsp +++ b/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Login.jsp @@ -1,21 +1,24 @@ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> - - - - Login - - - -
- Login -
-
- Password: -
- -
- - + + + + + Login + + + +
+
+ Login +
+ + Password: +
+ +
+
+ + \ No newline at end of file diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Transfer.jsp b/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Transfer.jsp index 2c267ef..8cd2a20 100644 --- a/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Transfer.jsp +++ b/17020996_nguyen_trong_ruong/my-system/src/main/webapp/WEB-INF/jsp/Transfer.jsp @@ -10,8 +10,8 @@
Transfer -
-
+
+

From 65872271b7bf6bf42df0c9a2e2ca791a98fe51f7 Mon Sep 17 00:00:00 2001 From: ruong32 Date: Tue, 25 Jun 2019 10:45:45 +0700 Subject: [PATCH 5/5] db --- .../java/com/jwb/bankservice/Customer.java | 82 ------------------- .../com/jwb/bankservice/CustomerList.java | 31 ------- .../repositories/CustomerList.java | 34 -------- 3 files changed, 147 deletions(-) delete mode 100644 17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/Customer.java delete mode 100644 17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/CustomerList.java delete mode 100644 17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/repositories/CustomerList.java diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/Customer.java b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/Customer.java deleted file mode 100644 index 03ae24c..0000000 --- a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/Customer.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.jwb.bankservice; - -public class Customer { - - private String name, email, phoneNumber, password = "123456"; - private int id, balance, login = 1; - - public Customer() { - - } - - public Customer(String name, String email, String phoneNumber, int balance) { - this.name = name; - this.email = email; - this.phoneNumber = phoneNumber; - this.balance = balance; - } - - public int getId(){ - return id; - } - - public void setId(int id){ - this.id = id; - } - - public int getLogin(){ - return login; - } - - public void setLogin(int isLogin){ - this.login = isLogin; - } - - public String getPassword(){ - return password; - } - - public void setPassword(String newPw){ - this.password = newPw; - } - - 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 getPhoneNumber() { - return phoneNumber; - } - - public void setPhoneNumber(String phoneNumber) { - this.phoneNumber = phoneNumber; - } - - public int getBalance() { - return balance; - } - - public void setBalance(int balance) { - this.balance = balance; - } - - public void transferMoney(int amount){ - balance -= amount; - } - - public void receiveMoney(int amount){ - balance += amount; - } -} \ No newline at end of file diff --git a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/CustomerList.java b/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/CustomerList.java deleted file mode 100644 index 0134590..0000000 --- a/17020996_nguyen_trong_ruong/my-system/src/main/java/com/jwb/bankservice/CustomerList.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.jwb.bankservice; - -import java.util.ArrayList; - -public class CustomerList { - public static ArrayList customerList = new ArrayList(); - private static int id = 0; - - public static void addCustomer(Customer ctm){ - ctm.setId(id); - customerList.add(ctm); - id++; - } - - public static void delCustomerList(int id){ - int n = customerList.size(); - for(int i=0; i customerList = new ArrayList(); - // private static int id = 0; - - // public static void addCustomer(Customer ctm){ - // ctm.setId(id); - // customerList.add(ctm); - // id++; - // } - - // public static void delCustomerList(int id){ - // int n = customerList.size(); - // for(int i=0; i