forked from khozema-nullwala/online-shopping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Project_Steps.txt
3119 lines (1584 loc) · 97 KB
/
Project_Steps.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
|-----------------------------------------------------------------
| Complete Project Step By Step with
| Spring, Hibernate, Maven, Angular JS and Bootstrap
| - Khozema Nullwala
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| Prerequisite - Tools
|-----------------------------------------------------------------
1. Install JDK latest version and path setup along with JAVA_HOME
2. Install Git (distributed version control system)
3. Unzip eclipse (at the time of this recording I am using Mars you can try with others too)
4. Apache Tomcat (I am going to use version 8)
We would also be needing a GitHub account to push the project from local machine to GitHub.
|-----------------------------------------------------------------
| Part 01 - Project Directory and uploading in GitHub repository
|-----------------------------------------------------------------
--------------------------------------------------------------------
1. Create an empty git repository on the Github. Select a repository name.
2. Check to add the README.md file and select your technology to add it inside the gitignore file.
3. Copy the github repository url.
4. Open the eclipse IDE
5. Go to Window -> Show View -> Other -> Type Git on the filter and select Git Repositories
6. Now clone this repository at your desired location in which we are going to keep the project specific files (both front-end and back-end project)
7. Create the maven webapp project. Add it to the repository by right clicking on the project -> Team -> Share Project. Select the git repository which was created above.
8. Similary, create the maven quick start project and add it to the same git repository
9. Open the gitignore file and ignore the target folder of both the projects as shown. (for example target folder)
10. Open window -> Preference -> Filter for Git configuration select it then add two entries if it is not present
11. Click on Add Entry
Key - user.name
Value - Your Name
12. Again click on Add Entry
Key - user.email
Value - Your Email Id
13. Right click on the repository select Commit -> Git Staging view. Select all the files in the unstaged changes and drag it to the Staged Changes.
14. Enter your commit message. Click on Commit and Push. It will ask for your credentials enter your github account username and password.
TO BE CONTINUED in PART 02 - Building the user interface in webapp project.
|-----------------------------------------------------------------
| Complete Project Step By Step with
| Spring, Hibernate, Maven, Angular JS and Bootstrap
| - Khozema Nullwala
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| Part 02 - Building the user interface in webapp project
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| 01 - Solving Error and Updating for latest versions of servlet
|-----------------------------------------------------------------
1. We will get the error -
The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
2. We will be using all the latest configuration to work in our project so first we will be changing the version of JRE inside pom.xml
3. To work with the latest version of servlet change the web.xml file version
Right Click on Project -> Maven -> Update Project
4. You will get an error as version mismatch
Solution - Right Click on Project -> Properties -> Project Facets -> Uncheck Dynamic Web Module. Ensure java version is to the version you have.
Right Click on Project -> Maven -> Update Project
TO BE CONTINUED in PART 02 - 02 - Adding Spring Dependency and Printing a message using Spring WebMvc.
|-----------------------------------------------------------------
| Complete Project Step By Step with
| Spring, Hibernate, Maven, Angular JS and Bootstrap
| - Khozema Nullwala
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| Part 02 - Building the user interface in webapp project
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| 02 - Adding Spring Dependency and Printing a message
|-----------------------------------------------------------------
1. Add the spring dependency in the pom.xml file
2. Configure the FrontController that will intercept all the incoming request first. It would be done inside web.xml
3. Create a directory with the following structure.
--src
----main
------java
4. Add a package in src/main/java directory keeping the following convention for naming it use the convention
groupid.artifactid.XXX (where XXX is the group of classes doing specific work)
5. We will be creating a controller class that will handle various url mapping like /, /index, /home all will be mapped to the same method handler. It will generate the data (greeting in our case) and along with it the logical view name.
6. Create a views folder inside WEB-INF and add a page.jsp file inside that folder.
--src
----main
------webapp
--------WEB-INF
----------views
------------page.jsp
TO BE CONTINUED in PART 02 - 03 - Creating a Spring Bean XML Configuration file to integrate everything together.
|-----------------------------------------------------------------
| Complete Project Step By Step with
| Spring, Hibernate, Maven, Angular JS and Bootstrap
| - Khozema Nullwala
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| Part 02 - Building the user interface in webapp project
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| 03 - Creating a Spring Bean XML Configuration file.
|-----------------------------------------------------------------
1. We need to create a dispatcher-servlet file for creating the bean to resolve the view for every mapping and we are scanning the package where other controllers could be found.
NOTE: - The name of the file will be the servlet_name-servlet.xml as per the convention else we have to do additional configuration that will be shown later.
2. Configure the ViewResolver inside the dispatcher-servlet to map the logical name to the actual physical filename.
3. Add the apache tomcat server.
4. Adding the jstl dependency.
TO BE CONTINUED in PART 02 - 04 - Understanding @RequestParam and @PathVariable
|-----------------------------------------------------------------
| Complete Project Step By Step with
| Spring, Hibernate, Maven, Angular JS and Bootstrap
| - Khozema Nullwala
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| Part 02 - Building the user interface in webapp project
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| 04 - Understanding @RequestParam and @PathVariable
|-----------------------------------------------------------------
1. A query string is any string that is part of the URL that starts after the '?' where data is transferred through URL in the form of 'key=value' pair.
http://localhost:8080/onlineshopping/test?greeting=hi&key1=value1&key2=value2
http://localhost:8080/onlineshopping/test?greeting=hello
http://localhost:8080/onlineshopping/test?greeting=welcome
2. In order to keep the URL clean and make it more SEO friendly we need to access the value from the path for example: -
http://localhost:8080/onlineshopping/test/hi
http://localhost:8080/onlineshopping/test/hello
http://localhost:8080/onlineshopping/test/welcome
TO BE CONTINUED in PART 02 - 05 - Creating Landing Page and Loading Static Resources.
|-----------------------------------------------------------------
| Complete Project Step By Step with
| Spring, Hibernate, Maven, Angular JS and Bootstrap
| - Khozema Nullwala
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| Part 02 - Building the user interface in webapp project
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| 05 - Creating Landing Page and Loading Static Resources.
|-----------------------------------------------------------------
1. Create a directory inside the
--src
----main
------resources
------webapp
--------assets
2. Get the bootstrap js, css and fonts files. Also create the directory for images and place it inside the assets directory created in above step.
3. Search for unstyled bootstrap starter template.
4. Bootstrap javascript code is dependent on jquery so we will copy that also.
5. In the dispatcher-servlet.xml file we have to add the mvc namespace.
6. Configure it to load the static resources.
7. Add the spring url tag library.
8. Create three variables name css, js and images using spring:url element.
9. Replace the css, js and images path with the variable name created above.
10. Commit the changes done till now.
TO BE CONTINUED in PART 02 - 06 - Creating Master Page
|-----------------------------------------------------------------
| Complete Project Step By Step with
| Spring, Hibernate, Maven, Angular JS and Bootstrap
| - Khozema Nullwala
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| Part 02 - Building the user interface in webapp project
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| 06 - Creating Master Page
|-----------------------------------------------------------------
1. Identify the different sections of the page. i.e. the navigation bar, the main section and the footer section.
2. Separate out each section into different jsp file so that it becomes easier to modify later.
3. Include the files that we have separated out in the page.jsp
4. Now we will be adding the title and also make sure that the main content is only loaded when the user clicks on home by adding two objects in the model.
5. Modify the navigation bar to include the contact and about us page
6. Add the request mapping in the page controller.
7. Test the link.
TO BE CONTINUED in PART 02 - 07 - Solving Active Menu Problem using jQuery
|-----------------------------------------------------------------
| Complete Project Step By Step with
| Spring, Hibernate, Maven, Angular JS and Bootstrap
| - Khozema Nullwala
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| Part 02 - Building the user interface in webapp project
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| 07 - Solving Active Menu Problem using jQuery
|-----------------------------------------------------------------
1. Let us add the id to the list of elements in the navbar.jsp
2. Add a small script element in the head section and create a new property with the name of menu in the window global object.
3. Create a myapp.js file in the js directory created earlier and add a script element at the end.
4. Add a function when the document is ready using the jquery short hand function.
5. Using a switch case element we would be adding a class of active to the menu list to which we have assigned the id in the first step.
TO BE CONTINUED in PART 02 - 08 - Fixing the footer problem and changing the theme of the page.
|-----------------------------------------------------------------
| Complete Project Step By Step with
| Spring, Hibernate, Maven, Angular JS and Bootstrap
| - Khozema Nullwala
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| Part 02 - Building the user interface in webapp project
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| 08 - Fixing the footer problem and changing the theme of the page.
|-----------------------------------------------------------------
1. Wrap the entire body code inside another div element.
2. Wrap the page content section inside another div element.
3. We will be using percentage so we need to specify the parent element i.e. body and html having 100% as the width.
4. Next we will be adding css styling properties to fix it.
5. To add a theme to the project we can download a theme from bootswatch.com
6. Commit the changes done till now.
TO BE CONTINUED in PART 03 - Linking Backend Project with Frontend Project.
|-----------------------------------------------------------------
| Complete Project Step By Step with
| Spring, Hibernate, Maven, Angular JS and Bootstrap
| - Khozema Nullwala
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| Part 03 - Linking Backend Project with Frontend Project.
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| 01 - Creating DTO and DAO classes.
|-----------------------------------------------------------------
1. We will start designing the classes required for our online shopping website.
2. First create the packages to organize your classes
NOTE: if you are using the convention as I'm doing it so it would be
groupid.artifactid.dto (for classes that will be used to transfer data to database table where dto stands for Data Transfer Object)
groupid.artifactid.dao (for interfaces that will be useful in accessing the data where dao stands for Data Access Object)
groupid.artifactid.daoimpl (for classes that will implements interfaces which will be used for accessing the data)
3. We will start by creating the Category class in the backend project inside the dto package.
4. We are going to create the DAO (data access object) interface and DAOImpl classes to access the data.
5. Add some dummy data to a static list for testing purpose which would be replaced later by access to records in database tables.
TO BE CONTINUED in PART 03 - 02 - Linking Backend Project with UI.
|-----------------------------------------------------------------
| Complete Project Step By Step with
| Spring, Hibernate, Maven, Angular JS and Bootstrap
| - Khozema Nullwala
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| Part 03 - Linking Backend Project with Frontend Project.
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| 02 - Linking Backend Project with UI
|-----------------------------------------------------------------
1. Add the backend dependency to the frontend project.
2. We are going to use the dependency injection feature of Spring framework and 'Autowired' the class which implements DAO interface.
3. Add the @Repository annotation. The @Repository annotation is a marker for class specifying that it fulfills the role of providing access to the data and will be managed by spring framework.
Error - Repository cannot be resolved
Solution - We will add the spring context dependency in the backend project as well
4. Modify the user interface to access the category in the sidebar.
5. Error - org.springframework.beans.factory.UnsatisfiedDependencyException
Solution -
Is to let the spring framework know where to get that categoryDAO dependency from. Add an context element in dispatcher servlet to scan the packages in the backend.
TO BE CONTINUED in PART 03 - 03 - Updating the URL to access Dynamic Page.
|-----------------------------------------------------------------
| Complete Project Step By Step with
| Spring, Hibernate, Maven, Angular JS and Bootstrap
| - Khozema Nullwala
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| Part 03 - Linking Backend Project with Frontend Project.
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| 03 - Updating the URL to access Dynamic Page
|-----------------------------------------------------------------
1. Modify the URL in the sidebar.jsp and navbar.jsp
2. Add two request mapping one to display all the products and display products based on Category but we would be using the same view for both the mapping.
3. Add a new DAO method in CategoryDAO to fetch a single category based on its id.
4. Create a view called listProducts.jsp. This page will be further divided into two to display the category on the side and other to display the data table.
5. We will add the bootstrap component of breadcrumb to test our page.
Home/Category/Mobile
6. Modify page.jsp to load the view based on user click.
7. Activate the menu of View Products and rearrange the menu as per your requirement.
8. Activate the menu of category as well.
9. Commit the changes done till now.
TO BE CONTINUED in PART 03 - 04 - Getting H2 Database and Hibernate Dependency.
|-----------------------------------------------------------------
| Complete Project Step By Step with
| Spring, Hibernate, Maven, Angular JS and Bootstrap
| - Khozema Nullwala
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| Part 03 - Linking Backend Project with Frontend Project.
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| 04 - Getting H2 Database and Hibernate Dependency
|-----------------------------------------------------------------
1. Get the database from the given url and extract it to a location of your choice.
http://www.h2database.com
2. Select the Generic H2 (Server) and you can create a database of your choice.
NOTE:
driver : - org.h2.Driver
url: - jdbc:h2:tcp://localhost/~/onlineshopping
username: - sa
password: -
3. Add the following dependency in the backend project to work with database.
com.h2database -> h2 -> 1.4.193
org.hibernate -> hibernate-core -> 5.2.7.Final
org.springframework -> spring-orm -> ${spring.version}
4. To enable connection pooling we are going to use another dependency
org.apache.commons -> commons-dbcp2 -> 2.1.1
TO BE CONTINUED in PART 03 - 05 - Hibernate Configuration to work with H2 Database.
|-----------------------------------------------------------------
| Complete Project Step By Step with
| Spring, Hibernate, Maven, Angular JS and Bootstrap
| - Khozema Nullwala
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| Part 03 - Linking Backend Project with Frontend Project.
|-----------------------------------------------------------------
|--------------------------------------------------------------------
| 05 - Hibernate Configuration to work with H2 Database
|--------------------------------------------------------------------
1. Create a package to keep all the application related configuration file inside the config package.
2. Create a HibernateConfig class and annotate it with the @Configuration, @ComponentScan and @EnableTransactionManagement
3. Create five static final variables to provide the database related information
DATABASE_URL - jdbc:h2:tcp://localhost/~/onlineshopping
DATABASE_DRIVER - org.h2.Driver
DATABASE_DIALECT - org.hibernate.dialect.H2Dialect
DATABASE_USERNAME - sa
DATABASE_PASSWORD -
4. Three beans will be created i.e.
-- DataSource (providing the connection information of the database)
-- SessionFactory (configures application to use Hibernate and create a session object)
-- HibernateTransactionManager (to manage the hibernate transactions)
TO BE CONTINUED Part 03 - 06 - Creating our first @Entity class
|-----------------------------------------------------------------
| Complete Project Step By Step with
| Spring, Hibernate, Maven, Angular JS and Bootstrap
| - Khozema Nullwala
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| Part 03 - Linking Backend Project with Frontend Project.
|-----------------------------------------------------------------
|--------------------------------------------------------------------
| 06 - Creating our first @Entity class
|--------------------------------------------------------------------
1. Keep the database queries in an sql file so that we dont have to write it again and again.
2. Write the create table query for Category and exceute it on the database.
3. Annotate the class with the @Entity annotation the entity name will be same as the class unless you want to change it.
4. All the entity class needs to have an id so we are going to annotate it using @Id
5. Use the auto generation strategy of IDENTITY
6. Change the column name as per the fields in table.
7. It always a good idea to add the toString method for checking purpose and solving errors.
8. Modify the DAO implementing class to add a new category to the database table using hibernate.
TO BE CONTINUED Part 03 - 07 - Writing JUnit Test Case
|-----------------------------------------------------------------
| Complete Project Step By Step with
| Spring, Hibernate, Maven, Angular JS and Bootstrap
| - Khozema Nullwala
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| Part 03 - Linking Backend Project with Frontend Project.
|-----------------------------------------------------------------
|--------------------------------------------------------------------
| 07 - Writing JUnit Test Case
|--------------------------------------------------------------------
1. We will be using the latest version of JUnit test case. Changing version to 4.12
2. Create a CategoryTestCase class in the net.kzn.shoppingbackend.test
3. The class will be using the AnnotationConfigApplicationContext and CategoryDAO class.
4. Code the static init method and annotate it with @BeforeClass.
5. Write the test case method and annotate it with @Test.
6. Run the test case by right clicking on the class and Run As -> JUnit Test
TO BE CONTINUED Part 03 - 08 - Writing Complete JUnit Test Case for doing Category CRUD operation
|-----------------------------------------------------------------
| Complete Project Step By Step with
| Spring, Hibernate, Maven, Angular JS and Bootstrap
| - Khozema Nullwala
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| Part 03 - Linking Backend Project with Frontend Project.
|-----------------------------------------------------------------
|--------------------------------------------------------------------
| 08 - CRUD Operation JUnit Test Case
|--------------------------------------------------------------------
1. Modify the DAO to include all the CRUD related methods
2. Modify the DAOImpl class to include all those methods.
3. Write the test case to get a single category.
4. Write the test case to update a single category.
5. Write a test case to delete a single category here deleting means to update the category is_deleted fields as false.
6. Write a test case to fetch the list of active category
7. Write a single test case now integrating all the test cases together.
8. Check with the frontend project if categories are fetched properly now from the database as we have already removed the static list.
--------------------------------------------------------------------
TO BE CONTINUTED Part 04 - Working with DataTables to display Product Details
--------------------------------------------------------------------
|-----------------------------------------------------------------
| Complete Project Step By Step with
| Spring, Hibernate, Maven, Angular JS and Bootstrap
| - Khozema Nullwala
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| Part 04 - Working with DataTables to display Product Details.
|-----------------------------------------------------------------
|--------------------------------------------------------------------
| 01 - Creating tables and classes for Products
|--------------------------------------------------------------------
1. First write the sql query for product and user table. Run in on the browser console to fill up some dummy data.
2. Next create the Product DTO class with the fields that we want to persist inside the database tables. Add a constructor to it that will generate a unique code for that table.
3. Let us create the ProductDAO interface along with the ProductDAOImpl class.
4. Write the test cases to ensure we can use the class without any problem in the ui project.
TO BE CONTINUED - Part 04 - 02 - Getting Product Data in JSON format.
|-----------------------------------------------------------------
| Complete Project Step By Step with
| Spring, Hibernate, Maven, Angular JS and Bootstrap
| - Khozema Nullwala
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| Part 04 - Working with DataTables to display Product Details.
|-----------------------------------------------------------------
|--------------------------------------------------------------------
| 02 - Getting Product Data in JSON format
|--------------------------------------------------------------------
1. To get the product in JSON format we need to have a converter in the classpath for achieving this we will be adding new dependencies
in backend project
com.fasterxml.jackson.core -> jackson-databind -> 2.8.7
com.fasterxml.jackson.core -> jackson-annotations -> 2.8.7
2. Create a JsonDataController whose job will be to provide data in JSON format. At the class level we are going to add a RequestMapping of "/json/data" and for method we will add like all/products and category/{id}/products so the entire url will be
/json/data/all/products and
/json/data/category/{id}/products;
3. Install the Postman or RestClient extension for Google Chrome & Mozilla firefox respectively.
4. Open the extension and put the address of json/data in the address bar. Check for the JSON response.
5. Now we will add JsonIgnore annotation to ignore the field that we do not want to send in the form of JSON.
TO BE CONTINUED - Part 04 - 03 - Getting the jQuery DataTable plugin.
|-----------------------------------------------------------------
| Complete Project Step By Step with
| Spring, Hibernate, Maven, Angular JS and Bootstrap
| - Khozema Nullwala
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| Part 04 - Working with DataTables to display Product Details.
|-----------------------------------------------------------------
|--------------------------------------------------------------------
| 03 - Getting the jQuery DataTable plugin
|--------------------------------------------------------------------
1. Go to the below website to download the jQuery DataTable plugin.
https://datatables.net/
2. Add the jquery.dataTable.js file to the proper location and link it in our project master page in proper order.
3. Create a new table element with some dummy fields inside the listProducts.jsp.
4. Code the javascript to fill the table with the some dummy data. Here the data will be a collection of some products. We will be using the data property to provide the dummy data. For more information on other property you can refer to the jQuery datatable documentation on how to use different data.
TO BE CONTINUED - Part 04 - 04 - Showing JSON data in jQuery DataTable plugin using Spring MVC.
|-----------------------------------------------------------------
| Complete Project Step By Step with
| Spring, Hibernate, Maven, Angular JS and Bootstrap
| - Khozema Nullwala
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| Part 04 - Working with DataTables to display Product Details.
|-----------------------------------------------------------------
|--------------------------------------------------------------------
| 04 - Showing JSON data in jQuery DataTable plugin using Spring MVC
|--------------------------------------------------------------------
1. Add the other files in the project which is required for making dataTable boostrapish.
i.e. dataTables.bootstrap.js & dataTables.bootstrap.css
2. Modify the page.jsp file to add the contextRoot to window global object and also add categoryId to it in listProducts.jsp
3. We are going to prepare the jsonUrl in javascript to fetch the data in JSON format from the respective controller for this we will be using the contextRoot that was added previously.
contextRoot/json/data/all/products
contextRoot/json/data/category/{id}/products
4. Modify the jQuery dataTable code to display the data. We will be using the following properties:
ajax -> url and dataSrc
columns
5. We will use the following url for adding two anchor tags one to view the product and other to add the product to the cart.
The URL will be:
contextRoot/show/{id}/product
contextRoot/cart/add/{id}/product
6. We are also going to add the image in this dataTable.
TO BE CONTINUED - Part 04 - 05 - Showing the entire Product in Single Dynamic Page on click of View.
|-----------------------------------------------------------------
| Complete Project Step By Step with
| Spring, Hibernate, Maven, Angular JS and Bootstrap
| - Khozema Nullwala
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| Part 04 - Working with DataTables to display Product Details.
|-----------------------------------------------------------------
|--------------------------------------------------------------------
| 05 - Showing the entire Product in Single Dynamic Page
| on click of view button.
|--------------------------------------------------------------------
1. Add the the request mapping to PageController to display the single product page.
2. Create a jsp page to display the product.
3. Include the single product page inside the master page that is already available.
TO BE CONTINUED - Part 04 - 06 - Using SLF4J Logging facility.
|-----------------------------------------------------------------
| Complete Project Step By Step with
| Spring, Hibernate, Maven, Angular JS and Bootstrap
| - Khozema Nullwala
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| Part 04 - Working with DataTables to display Product Details.
|-----------------------------------------------------------------
|--------------------------------------------------------------------
| 06 - Using SLF4J Logging facility.
|--------------------------------------------------------------------
The Simple Logging Facade for Java (SLF4J) serves as a simple facade or abstraction for various logging frameworks, such as java.util.logging, logback and log4j. SLF4J allows the end-user to plug in the desired logging framework at deployment time.
1. We will be excluding the commomns-logging from the spring-core as well as from the commons-dbcp2 in backend project to use slf4j
2. We will be using the logback classic which implements slf4j directly and we have to use the jcl-over-slf4j dependency.
<!-- SLF4J Logging -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.24</version>
</dependency>
3. Create a separate logback.xml file in the src-->main-->resources directory.
It will consist of the following elements
|--appender (name, class)
| |----encoder
| |--- Pattern
|
configuration---|
|--logger (name, level, additivity)
| |--appender-ref (ref)
|
|--root (by default level is DEBUG so keep it simple to INFO)
|--appender-ref (ref)
4. We will add an appender for the console. Along with the following encoder pattern: %-5level %msg %d{HH:mm:ss.SSS} %logger{36} %n
%-5level – means the level of the logging event should be left justified to a width of five characters
%msg – outputs the application-supplied message associated with the logging event.
%d{HH:mm:ss.SSS} – Used to output the date of the logging event.
%logger{36} – outputs the name of the logger at the origin of the logging event. It takes an integer
%n – outputs the platform dependent line separator character or characters.
5. We will add the logger for displaying the DEBUG information.
6. Add the root element.
7. We will use it inside our controller let us first test it with the PageController.
TO BE CONTINUED - Part 04 - 07 - Global Exception Handling.
|-----------------------------------------------------------------
| Complete Project Step By Step with
| Spring, Hibernate, Maven, Angular JS and Bootstrap
| - Khozema Nullwala
|-----------------------------------------------------------------
|-----------------------------------------------------------------
| Part 04 - Working with DataTables to display Product Details.
|-----------------------------------------------------------------
|--------------------------------------------------------------------
| 07 - Global Exception Handling
|--------------------------------------------------------------------
1. We will create a package following our own standard i.e.
groupid.artifactid.exception