Skip to content
Snippets Groups Projects
Commit 873e67ac authored by Rhys Evans's avatar Rhys Evans
Browse files

form correctly adds valid submits to locations table, attemnpting to add Java...

 form correctly adds valid submits to locations table, attemnpting to add Java alert to identify correct submission
parent da7b1929
No related branches found
No related tags found
1 merge request!23Resolve "As a developer I want all landmarks to be stored together"
......@@ -33,20 +33,12 @@ public class locationRepositoryJDBC implements locationRepository {
return jdbc.query(sql, locationMapper);
}
@Override
@Override // intended implementation at current: user data from templates/Landmarks/LandmarkFormTh.html is added to the location table, todo change location class to Location as its better code grammar and looks funky otherwise.
public void addLocation(location llocation) {
String sql = "insert into locations(locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) values (?,?,?,?,?,?)";
jdbc.update(sql, llocation.getLocationID(),llocation.getLocationName(),llocation.getLocationEmail(),llocation.getLocationDescription(),llocation.getLocationPlace(),llocation.getLocationTrailID());
}
// public void insertLocation(Landmarks landmark){
// String sql = "INSERT INTO locations(locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID)"+"VALUES("+ landmark.getLandmarkID()+","+","+landmark.getLandmarkName()+","+landmark.getLandmarkEmail()+","+landmark.getLandmarkDescription()+","+landmark.getLandmarkLocation()+","+landmark.getTrailID()+")";
// try{
// executeUpdate(sql);
// }
// catch(SQLException e){
//
// }
// }
}
package Team5.SmartTowns.Landmarks;
......@@ -11,7 +11,9 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import javax.swing.*;
import java.sql.PreparedStatement;
//import jakarta.validation.Valid;
......@@ -30,7 +32,7 @@ public class LandmarksController {
@Autowired
private locationRepository locationRepository;
@PostMapping("/landmarkSub")
public ModelAndView landmarkSent(@Valid @ModelAttribute("landmarkData") Landmarks landmarks, BindingResult bindingResult, Model model ) {
public ModelAndView landmarkSent(@Valid @ModelAttribute("landmarkData") Landmarks landmarks, BindingResult bindingResult, Model model, RedirectAttributes redirectAttributes ) {
if (bindingResult.hasErrors()) {
......@@ -39,14 +41,21 @@ public class LandmarksController {
} else{
System.out.println(landmarks);
// JFrame frame = new JFrame("Main Window");
//
// JOptionPane.showMessageDialog(frame, "Message for the dialog box goes here.","Error", JOptionPane.ERROR_MESSAGE);
//
// frame.setSize(350,350);
// frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// frame.setVisible(true);
location loc= new location(landmarks.getLandmarkID(),landmarks.getLandmarkName(), landmarks.getLandmarkEmail(), landmarks.getLandmarkDescription(), landmarks.getLandmarkLocation(), landmarks.getTrailID());
System.out.println(loc);
locationRepository.addLocation(loc);
ModelAndView modelAndView = new ModelAndView("redirect:/home");
// redirectAttributes.addFlashAttribute("notification",
// String.format("Contractor \"%s\" successfully saved"));
// redirectAttributes.addFlashAttribute("msg", "Success");
ModelAndView modelAndView = new ModelAndView("redirect:/home");
return modelAndView;
}
......
......@@ -11,7 +11,7 @@ create table if not exists locations
locationID bigint auto_increment primary key,
locationName varchar(128),
locationEmail varchar(128),
locationDescription longtext, #to store large text data
locationDescription longtext,
locationPlace varchar(255),
locationTrailID varchar(128)
) engine=InnoDB;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment