Advertisement
Guest User

Untitled

a guest
Jul 20th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. import javax.sql.DataSource;
  2.  
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.jdbc.core.JdbcTemplate;
  5. import org.springframework.stereotype.Component;
  6.  
  7. @Component
  8. public class OffersDAO {
  9.  
  10. private JdbcTemplate jdbcTemplate;
  11.  
  12. @Autowired
  13. public void setDataSource(DataSource dataSource) {
  14. this.jdbcTemplate = new JdbcTemplate(dataSource);
  15. }
  16.  
  17. public void addUser(String email, String password) {
  18.  
  19. String sql = "INSERT INTO USER_INFORMATION (EMAIL, PASSWORD) VALUES(?, ?)";
  20.  
  21. jdbcTemplate.update(sql, email, password);
  22.  
  23. System.out.println("ADDED USER : " + email + " " + password);
  24. }
  25. }
  26.  
  27. import java.util.ArrayList;
  28. import java.util.List;
  29.  
  30. import org.springframework.stereotype.Controller;
  31. import org.springframework.ui.Model;
  32. import org.springframework.web.bind.annotation.RequestMapping;
  33. import org.springframework.web.bind.annotation.RequestMethod;
  34. import org.springframework.web.servlet.ModelAndView;
  35.  
  36.  
  37. @Controller
  38. public class HomeController {
  39.  
  40. List<User> users = new ArrayList<User>();
  41.  
  42. @RequestMapping(value = "")
  43. public String welcome(Model model) {
  44. model.addAttribute("greeting", "Welcome to Web Store!");
  45. model.addAttribute("tagline", "The one and only amazing webstore");
  46. return "welcome";
  47. }
  48.  
  49. @RequestMapping(value="/login", method=RequestMethod.POST)
  50. public String login() {
  51. return "login";
  52. }
  53.  
  54. @RequestMapping(value="/verify", method=RequestMethod.POST)
  55. public ModelAndView verify(User user) {
  56.  
  57. System.out.println(user.toString());
  58.  
  59. OffersDAO offersDAO = new OffersDAO();
  60.  
  61. offersDAO.addUser(user.getEmail(), user.getPassword());
  62.  
  63. return new ModelAndView("success", "message", "User added successfully!");
  64.  
  65. }
  66.  
  67. @RequestMapping(value="/show")
  68. public ModelAndView listUsers() {
  69.  
  70. return new ModelAndView("show", "users", users);
  71.  
  72. }
  73.  
  74. @RequestMapping(value="delete")
  75. public ModelAndView delete() {
  76.  
  77. return new ModelAndView("show", "users", users);
  78.  
  79. }
  80.  
  81. }
  82.  
  83. <?xml version="1.0" encoding="UTF-8"?>
  84. <beans xmlns="http://www.springframework.org/schema/beans"
  85. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  86. xmlns:context="http://www.springframework.org/schema/context"
  87. xmlns:mvc="http://www.springframework.org/schema/mvc"
  88. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  89. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
  90. http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
  91.  
  92.  
  93. <mvc:annotation-driven />
  94. <context:component-scan base-package="com.example" />
  95.  
  96. <mvc:resources mapping="/resources/**" location="/resources/"
  97. cache-period="31556926"/>
  98.  
  99. <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  100. <property name="prefix" value="/jsp/" />
  101. <property name="suffix" value=".jsp"/>
  102. </bean>
  103.  
  104. <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  105. <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
  106. <property name="url" value="jdbc:oracle:thin:@localhost:1521:xe"/>
  107. <property name="username" value="system"/>
  108. <property name="password" value="root"/>
  109. </bean>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement