Skip to content
Snippets Groups Projects
Commit 264db9d2 authored by Rhys Nute's avatar Rhys Nute
Browse files

finished database

parent a1bd0569
No related branches found
No related tags found
1 merge request!16Ready to merge - Database
......@@ -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;
}
}
......@@ -6,6 +6,6 @@ import lombok.Data;
@Data
@AllArgsConstructor
public class location {
private int locationId;
private int locationID;
private String name;
}
......@@ -3,7 +3,7 @@ package Team5.SmartTowns.Data;
import java.util.List;
public interface locationRepository {
List<location> getAllLocations();
List<location> getAllLocation();
}
......@@ -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);
}
}
......@@ -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")
);
}
......
......@@ -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
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;
......
......@@ -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>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment