diff --git a/src/main/java/Team5/SmartTowns/Data/DatabaseController.java b/src/main/java/Team5/SmartTowns/Data/DatabaseController.java index 55fa1a5499f72cf8b73f85e924ec5cb035da03e2..b91d7d880368f6cb405e3ed71c38242f612bfae2 100644 --- a/src/main/java/Team5/SmartTowns/Data/DatabaseController.java +++ b/src/main/java/Team5/SmartTowns/Data/DatabaseController.java @@ -11,15 +11,11 @@ public class DatabaseController { @Autowired private UserRepository userRepository; -// @Autowired -// private locationRepository locationRepository; + @Autowired + private locationRepository locationRepository; @Autowired private trailsRepository trailsRepository; -// public DatabaseController() { -// -// } - @GetMapping("/userList") public ModelAndView userList() { ModelAndView mav = new ModelAndView("towns/userData"); @@ -34,11 +30,11 @@ public class DatabaseController { mav1.addObject("trails", trail); return mav1; } -// @GetMapping("locationList") -// public ModelAndView locationList(){ -// ModelAndView mav2 = new ModelAndView("towns/locationData"); -// List<location> location = locationRepository.getAllLocations(); -// mav2.addObject("location", location); -// return mav2; -// } + @GetMapping("locationList") + public ModelAndView locationList(){ + ModelAndView mav2 = new ModelAndView("towns/locationData"); + List<location> locations = locationRepository.getAllLocation(); + mav2.addObject("location", locations); + return mav2; + } } diff --git a/src/main/java/Team5/SmartTowns/Data/location.java b/src/main/java/Team5/SmartTowns/Data/location.java index 03fff518a84e4165aab1487de9f5657743b1e099..827dabdb39c93f15e04b97e939509465a3cab458 100644 --- a/src/main/java/Team5/SmartTowns/Data/location.java +++ b/src/main/java/Team5/SmartTowns/Data/location.java @@ -6,6 +6,6 @@ import lombok.Data; @Data @AllArgsConstructor public class location { - private int locationId; + private int locationID; private String name; } diff --git a/src/main/java/Team5/SmartTowns/Data/locationRepository.java b/src/main/java/Team5/SmartTowns/Data/locationRepository.java index ce30cda95d0cc319703e5f4e8e18df6bbfe80f01..cce73286be5e46308af9461fd35d923cab819cec 100644 --- a/src/main/java/Team5/SmartTowns/Data/locationRepository.java +++ b/src/main/java/Team5/SmartTowns/Data/locationRepository.java @@ -3,7 +3,7 @@ package Team5.SmartTowns.Data; import java.util.List; public interface locationRepository { - List<location> getAllLocations(); + List<location> getAllLocation(); } diff --git a/src/main/java/Team5/SmartTowns/Data/locationRepositoryJDBC.java b/src/main/java/Team5/SmartTowns/Data/locationRepositoryJDBC.java index 4743ea8b37a42c7f591ddf7ee3ea9bafcc352266..f72787ed88f8b894a3a90a73e6bdab3d02971a39 100644 --- a/src/main/java/Team5/SmartTowns/Data/locationRepositoryJDBC.java +++ b/src/main/java/Team5/SmartTowns/Data/locationRepositoryJDBC.java @@ -7,7 +7,7 @@ import org.springframework.stereotype.Repository; import java.util.List; @Repository -public abstract class locationRepositoryJDBC implements locationRepository { +public class locationRepositoryJDBC implements locationRepository { private JdbcTemplate jdbc; private RowMapper<location> locationMapper; @@ -17,12 +17,12 @@ public abstract class locationRepositoryJDBC implements locationRepository { } private void setlocationMapper(){ locationMapper = (rs, i) -> new location( - rs.getInt("locationId"), + rs.getInt("locationID"), rs.getString("name") ); } public List<location> getAllLocation(){ - String sql= "SELECT * FROM location"; + String sql= "SELECT * FROM locations"; return jdbc.query(sql, locationMapper); } } diff --git a/src/main/java/Team5/SmartTowns/Data/trailsRepositoryJDBC.java b/src/main/java/Team5/SmartTowns/Data/trailsRepositoryJDBC.java index 40ce5ff0e5ce708f2b4fdc6b3e1499cfd7b21d46..eb26156c1fa41ec6c5ccf9866623cbd10ef44e09 100644 --- a/src/main/java/Team5/SmartTowns/Data/trailsRepositoryJDBC.java +++ b/src/main/java/Team5/SmartTowns/Data/trailsRepositoryJDBC.java @@ -7,7 +7,7 @@ import org.springframework.stereotype.Repository; import java.util.List; @Repository -public class trailsRepositoryJDBC { +public class trailsRepositoryJDBC implements trailsRepository{ private JdbcTemplate jdbc; private RowMapper<trail> trailMapper; public trailsRepositoryJDBC(JdbcTemplate aJdbc){ @@ -16,7 +16,7 @@ public class trailsRepositoryJDBC { } private void settrailsMapper(){ trailMapper = (rs, i) -> new trail( - rs.getInt("trailsId"), + rs.getInt("trailID"), rs.getString("name") ); } diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 7f91a409f37f850bfc1fdd60269f5699cc20cf69..f7656769c7d1b2afd5e78e3a93c3cd3ed44abe3b 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -6,6 +6,6 @@ delete from trails; insert into trails (trailID, Name) value ('1', 'Caerphilly Coffee Trail'); insert into trails (trailID, Name) value ('2', 'Penarth Dragon Trail'); -delete from location; -insert into location (locationID, Name) value ('1', 'Caerphilly'); -insert into location (locationID, Name) value ('2', 'Penarth'); \ No newline at end of file +delete from locations; +insert into locations (locationID, Name) value ('1', 'Caerphilly'); +insert into locations (locationID, Name) value ('2', 'Penarth'); \ No newline at end of file diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index 0374c292ac614600c422671c9ac6cc2199186ef0..c10ffb8186c2c575d7aaa927c410fe330d3947d6 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -1,10 +1,10 @@ -drop table if exists trails; -create table if not exists trails( +drop table if exists trail; +create table if not exists trail( trailID bigint auto_increment primary key, name varchar(100) ) engine=InnoDB; -drop table if exists location; -create table if not exists location( +drop table if exists locations; +create table if not exists locations( locationID bigint auto_increment primary key, name varchar(100) ) engine=InnoDB; diff --git a/src/main/resources/templates/towns/locationData.html b/src/main/resources/templates/towns/locationData.html index 1ff2892209ef8688ee2bbbf58f1ac095e551ae19..f7636f05a3a0dbfc2ed2e87a8964f637b5e91046 100644 --- a/src/main/resources/templates/towns/locationData.html +++ b/src/main/resources/templates/towns/locationData.html @@ -6,8 +6,8 @@ </head> <body> <div> - <ul th:each="location:${locations}"> - <li th:text="${location}"></li> + <ul th:each="locations:${location}"> + <li th:text="${locations}"></li> </ul> </div> </body>