Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.sql.DataSource;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.jdbc.core.JdbcTemplate;
- import org.springframework.stereotype.Component;
- @Component
- public class OffersDAO {
- private JdbcTemplate jdbcTemplate;
- @Autowired
- public void setDataSource(DataSource dataSource) {
- this.jdbcTemplate = new JdbcTemplate(dataSource);
- }
- public void addUser(String email, String password) {
- String sql = "INSERT INTO USER_INFORMATION (EMAIL, PASSWORD) VALUES(?, ?)";
- jdbcTemplate.update(sql, email, password);
- System.out.println("ADDED USER : " + email + " " + password);
- }
- }
- import java.util.ArrayList;
- import java.util.List;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.servlet.ModelAndView;
- @Controller
- public class HomeController {
- List<User> users = new ArrayList<User>();
- @RequestMapping(value = "")
- public String welcome(Model model) {
- model.addAttribute("greeting", "Welcome to Web Store!");
- model.addAttribute("tagline", "The one and only amazing webstore");
- return "welcome";
- }
- @RequestMapping(value="/login", method=RequestMethod.POST)
- public String login() {
- return "login";
- }
- @RequestMapping(value="/verify", method=RequestMethod.POST)
- public ModelAndView verify(User user) {
- System.out.println(user.toString());
- OffersDAO offersDAO = new OffersDAO();
- offersDAO.addUser(user.getEmail(), user.getPassword());
- return new ModelAndView("success", "message", "User added successfully!");
- }
- @RequestMapping(value="/show")
- public ModelAndView listUsers() {
- return new ModelAndView("show", "users", users);
- }
- @RequestMapping(value="delete")
- public ModelAndView delete() {
- return new ModelAndView("show", "users", users);
- }
- }
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:mvc="http://www.springframework.org/schema/mvc"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
- http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
- <mvc:annotation-driven />
- <context:component-scan base-package="com.example" />
- <mvc:resources mapping="/resources/**" location="/resources/"
- cache-period="31556926"/>
- <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
- <property name="prefix" value="/jsp/" />
- <property name="suffix" value=".jsp"/>
- </bean>
- <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
- <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
- <property name="url" value="jdbc:oracle:thin:@localhost:1521:xe"/>
- <property name="username" value="system"/>
- <property name="password" value="root"/>
- </bean>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement