diff --git a/spring-rest-angular-pagination/src/main/webapp/index.html b/spring-rest-angular-pagination/src/main/webapp/index.html deleted file mode 100644 index a37c1b77fe..0000000000 --- a/spring-rest-angular-pagination/src/main/webapp/index.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - -
-
-
- - \ No newline at end of file diff --git a/spring-rest-angular-pagination/pom.xml b/spring-rest-angular/bin/pom.xml similarity index 96% rename from spring-rest-angular-pagination/pom.xml rename to spring-rest-angular/bin/pom.xml index 8b8a37cedf..331c9a644c 100644 --- a/spring-rest-angular-pagination/pom.xml +++ b/spring-rest-angular/bin/pom.xml @@ -3,8 +3,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 4.0.0 - angular-spring-rest-sample - angular-spring-rest-sample + spring-rest-angular + spring-rest-angular com.baeldung 1.0 war diff --git a/spring-rest-angular-pagination/src/main/resources/application.properties b/spring-rest-angular/bin/src/main/resources/application.properties similarity index 100% rename from spring-rest-angular-pagination/src/main/resources/application.properties rename to spring-rest-angular/bin/src/main/resources/application.properties diff --git a/spring-rest-angular-pagination/src/main/resources/db/sql/data.sql b/spring-rest-angular/bin/src/main/resources/db/sql/data.sql similarity index 100% rename from spring-rest-angular-pagination/src/main/resources/db/sql/data.sql rename to spring-rest-angular/bin/src/main/resources/db/sql/data.sql diff --git a/spring-rest-angular-pagination/src/main/webapp/WEB-INF/web.xml b/spring-rest-angular/bin/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from spring-rest-angular-pagination/src/main/webapp/WEB-INF/web.xml rename to spring-rest-angular/bin/src/main/webapp/WEB-INF/web.xml diff --git a/spring-rest-angular/bin/src/main/webapp/index.html b/spring-rest-angular/bin/src/main/webapp/index.html new file mode 100644 index 0000000000..49e0d6393d --- /dev/null +++ b/spring-rest-angular/bin/src/main/webapp/index.html @@ -0,0 +1,17 @@ + + + + + + + + + +
+
+
+ + \ No newline at end of file diff --git a/spring-rest-angular-pagination/src/main/webapp/view/app.js b/spring-rest-angular/bin/src/main/webapp/view/app.js similarity index 100% rename from spring-rest-angular-pagination/src/main/webapp/view/app.js rename to spring-rest-angular/bin/src/main/webapp/view/app.js diff --git a/spring-rest-angular/pom.xml b/spring-rest-angular/pom.xml new file mode 100644 index 0000000000..331c9a644c --- /dev/null +++ b/spring-rest-angular/pom.xml @@ -0,0 +1,95 @@ + + + 4.0.0 + spring-rest-angular + spring-rest-angular + com.baeldung + 1.0 + war + + org.springframework.boot + spring-boot-starter-parent + 1.3.3.RELEASE + + + + org.springframework.boot + spring-boot-starter-tomcat + provided + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.data + spring-data-commons + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.hsqldb + hsqldb + runtime + + + org.springframework + spring-test + test + + + org.apache.commons + commons-lang3 + 3.3 + + + com.google.guava + guava + 19.0 + + + junit + junit + test + + + io.rest-assured + rest-assured + 3.0.0 + test + + + io.rest-assured + spring-mock-mvc + 3.0.0 + test + + + + angular-spring-rest-sample + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + org.apache.maven.plugins + maven-war-plugin + + false + + + + + + diff --git a/spring-rest-angular-pagination/src/main/java/org/baeldung/web/dao/StudentRepository.java b/spring-rest-angular/src/main/java/org/baeldung/web/dao/StudentRepository.java similarity index 100% rename from spring-rest-angular-pagination/src/main/java/org/baeldung/web/dao/StudentRepository.java rename to spring-rest-angular/src/main/java/org/baeldung/web/dao/StudentRepository.java diff --git a/spring-rest-angular-pagination/src/main/java/org/baeldung/web/entity/Student.java b/spring-rest-angular/src/main/java/org/baeldung/web/entity/Student.java similarity index 100% rename from spring-rest-angular-pagination/src/main/java/org/baeldung/web/entity/Student.java rename to spring-rest-angular/src/main/java/org/baeldung/web/entity/Student.java diff --git a/spring-rest-angular-pagination/src/main/java/org/baeldung/web/exception/MyResourceNotFoundException.java b/spring-rest-angular/src/main/java/org/baeldung/web/exception/MyResourceNotFoundException.java similarity index 100% rename from spring-rest-angular-pagination/src/main/java/org/baeldung/web/exception/MyResourceNotFoundException.java rename to spring-rest-angular/src/main/java/org/baeldung/web/exception/MyResourceNotFoundException.java diff --git a/spring-rest-angular-pagination/src/main/java/org/baeldung/web/main/Application.java b/spring-rest-angular/src/main/java/org/baeldung/web/main/Application.java similarity index 100% rename from spring-rest-angular-pagination/src/main/java/org/baeldung/web/main/Application.java rename to spring-rest-angular/src/main/java/org/baeldung/web/main/Application.java diff --git a/spring-rest-angular-pagination/src/main/java/org/baeldung/web/main/PersistenceConfig.java b/spring-rest-angular/src/main/java/org/baeldung/web/main/PersistenceConfig.java similarity index 100% rename from spring-rest-angular-pagination/src/main/java/org/baeldung/web/main/PersistenceConfig.java rename to spring-rest-angular/src/main/java/org/baeldung/web/main/PersistenceConfig.java diff --git a/spring-rest-angular-pagination/src/main/java/org/baeldung/web/rest/StudentDirectoryRestController.java b/spring-rest-angular/src/main/java/org/baeldung/web/rest/StudentDirectoryRestController.java similarity index 100% rename from spring-rest-angular-pagination/src/main/java/org/baeldung/web/rest/StudentDirectoryRestController.java rename to spring-rest-angular/src/main/java/org/baeldung/web/rest/StudentDirectoryRestController.java diff --git a/spring-rest-angular-pagination/src/main/java/org/baeldung/web/service/IOperations.java b/spring-rest-angular/src/main/java/org/baeldung/web/service/IOperations.java similarity index 100% rename from spring-rest-angular-pagination/src/main/java/org/baeldung/web/service/IOperations.java rename to spring-rest-angular/src/main/java/org/baeldung/web/service/IOperations.java diff --git a/spring-rest-angular-pagination/src/main/java/org/baeldung/web/service/StudentService.java b/spring-rest-angular/src/main/java/org/baeldung/web/service/StudentService.java similarity index 100% rename from spring-rest-angular-pagination/src/main/java/org/baeldung/web/service/StudentService.java rename to spring-rest-angular/src/main/java/org/baeldung/web/service/StudentService.java diff --git a/spring-rest-angular-pagination/src/main/java/org/baeldung/web/service/StudentServiceImpl.java b/spring-rest-angular/src/main/java/org/baeldung/web/service/StudentServiceImpl.java similarity index 100% rename from spring-rest-angular-pagination/src/main/java/org/baeldung/web/service/StudentServiceImpl.java rename to spring-rest-angular/src/main/java/org/baeldung/web/service/StudentServiceImpl.java diff --git a/spring-rest-angular/src/main/resources/application.properties b/spring-rest-angular/src/main/resources/application.properties new file mode 100644 index 0000000000..e24db89c8f --- /dev/null +++ b/spring-rest-angular/src/main/resources/application.properties @@ -0,0 +1,4 @@ +server.contextPath=/ +spring.h2.console.enabled=true +logging.level.org.hibernate.SQL=info +spring.jpa.hibernate.ddl-auto=none \ No newline at end of file diff --git a/spring-rest-angular/src/main/resources/db/sql/data.sql b/spring-rest-angular/src/main/resources/db/sql/data.sql new file mode 100644 index 0000000000..418381a681 --- /dev/null +++ b/spring-rest-angular/src/main/resources/db/sql/data.sql @@ -0,0 +1,47 @@ +CREATE TABLE student ( + id INTEGER PRIMARY KEY, + name VARCHAR(30), + gender VARCHAR(10), + age INTEGER +); + +INSERT INTO student (id,name,gender,age) +VALUES (1,'Bryan', 'Male',20); +INSERT INTO student (id,name,gender,age) +VALUES (2, 'Ben', 'Male', 22); +INSERT INTO student (id,name,gender,age) +VALUES (3,'Lisa', 'Female',24); +INSERT INTO student (id,name,gender,age) +VALUES (4,'Sarah', 'Female',20); +INSERT INTO student (id,name,gender,age) +VALUES (5,'Jay', 'Male',20); +INSERT INTO student (id,name,gender,age) +VALUES (6,'John', 'Male',22); +INSERT INTO student (id,name,gender,age) +VALUES (7,'Jordan', 'Male',24); +INSERT INTO student (id,name,gender,age) +VALUES (8,'Rob', 'Male',26); +INSERT INTO student (id,name,gender,age) +VALUES (9,'Will', 'Male',20); +INSERT INTO student (id,name,gender,age) +VALUES (10,'Shawn', 'Male',22); +INSERT INTO student (id,name,gender,age) +VALUES (11,'Taylor', 'Female',24); +INSERT INTO student (id,name,gender,age) +VALUES (12,'Venus', 'Female',26); +INSERT INTO student (id,name,gender,age) +VALUES (13,'Vince', 'Male',20); +INSERT INTO student (id,name,gender,age) +VALUES (14,'Carol', 'Female',22); +INSERT INTO student (id,name,gender,age) +VALUES (15,'Joana', 'Female',24); +INSERT INTO student (id,name,gender,age) +VALUES (16,'Dion', 'Male',26); +INSERT INTO student (id,name,gender,age) +VALUES (17,'Evans', 'Male',20); +INSERT INTO student (id,name,gender,age) +VALUES (18,'Bart', 'Male',22); +INSERT INTO student (id,name,gender,age) +VALUES (19,'Jenny', 'Female',24); +INSERT INTO student (id,name,gender,age) +VALUES (20,'Kristine', 'Female',26); \ No newline at end of file diff --git a/spring-rest-angular/src/main/webapp/WEB-INF/web.xml b/spring-rest-angular/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..6adf31503f --- /dev/null +++ b/spring-rest-angular/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,11 @@ + + + + + index.html + + + \ No newline at end of file diff --git a/spring-rest-angular/src/main/webapp/index.html b/spring-rest-angular/src/main/webapp/index.html new file mode 100644 index 0000000000..49e0d6393d --- /dev/null +++ b/spring-rest-angular/src/main/webapp/index.html @@ -0,0 +1,17 @@ + + + + + + + + + +
+
+
+ + \ No newline at end of file diff --git a/spring-rest-angular/src/main/webapp/view/app.js b/spring-rest-angular/src/main/webapp/view/app.js new file mode 100644 index 0000000000..a41026d2c3 --- /dev/null +++ b/spring-rest-angular/src/main/webapp/view/app.js @@ -0,0 +1,56 @@ +var app = angular.module('app', ['ui.grid','ui.grid.pagination']); + +app.controller('StudentCtrl', ['$scope','StudentService', function ($scope,StudentService) { + var paginationOptions = { + pageNumber: 1, + pageSize: 5, + sort: null + }; + + StudentService.getStudents(paginationOptions.pageNumber, + paginationOptions.pageSize).success(function(data){ + $scope.gridOptions.data = data.content; + $scope.gridOptions.totalItems = data.totalElements; + }); + + $scope.gridOptions = { + paginationPageSizes: [5, 10, 20], + paginationPageSize: paginationOptions.pageSize, + enableColumnMenus:false, + useExternalPagination: true, + columnDefs: [ + { name: 'id' }, + { name: 'name' }, + { name: 'gender' }, + { name: 'age' } + ], + onRegisterApi: function(gridApi) { + $scope.gridApi = gridApi; + gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) { + paginationOptions.pageNumber = newPage; + paginationOptions.pageSize = pageSize; + StudentService.getStudents(newPage,pageSize).success(function(data){ + $scope.gridOptions.data = data.content; + $scope.gridOptions.totalItems = data.totalElements; + }); + }); + } + }; + +}]); + +app.service('StudentService',['$http', function ($http) { + + function getStudents(pageNumber,size) { + pageNumber = pageNumber > 0?pageNumber - 1:0; + return $http({ + method: 'GET', + url: 'student/get?page='+pageNumber+'&size='+size + }); + } + + return { + getStudents:getStudents + }; + +}]); \ No newline at end of file diff --git a/spring-rest-angular-pagination/src/test/java/org/baeldung/web/service/StudentServiceTest.java b/spring-rest-angular/src/test/java/org/baeldung/web/service/StudentServiceTest.java similarity index 100% rename from spring-rest-angular-pagination/src/test/java/org/baeldung/web/service/StudentServiceTest.java rename to spring-rest-angular/src/test/java/org/baeldung/web/service/StudentServiceTest.java