Bs santosh spring mybatis (#1479)
* Spring and MyBatis integration maven project Complete article is available in http://inprogress.baeldung.com/wp-admin/post.php * Spring-MyBatis integration example This code demonstrates how to use MyBatis in Sring environment. Full details could be found in article http://inprogress.baeldung.com/?p=31706&preview=true
This commit is contained in:
parent
319dd2653a
commit
3140ea166d
62
spring-mybatis/pom.xml
Normal file
62
spring-mybatis/pom.xml
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.baeldung</groupId>
|
||||||
|
<artifactId>spring-mybatis</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<name>spring-mybatis Maven Webapp</name>
|
||||||
|
<url>http://maven.apache.org</url>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mybatis</groupId>
|
||||||
|
<artifactId>mybatis</artifactId>
|
||||||
|
<version>3.1.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mybatis</groupId>
|
||||||
|
<artifactId>mybatis-spring</artifactId>
|
||||||
|
<version>1.1.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-context-support</artifactId>
|
||||||
|
<version>3.1.1.RELEASE</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-test</artifactId>
|
||||||
|
<version>3.1.1.RELEASE</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>5.1.40</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.servlet</groupId>
|
||||||
|
<artifactId>jstl</artifactId>
|
||||||
|
<version>1.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-webmvc</artifactId>
|
||||||
|
<version>3.2.4.RELEASE</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.servlet</groupId>
|
||||||
|
<artifactId>servlet-api</artifactId>
|
||||||
|
<version>2.5</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<finalName>spring-mybatis</finalName>
|
||||||
|
</build>
|
||||||
|
</project>
|
@ -0,0 +1,48 @@
|
|||||||
|
package com.baeldung.spring.mybatis.application;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
|
import com.baeldung.spring.mybatis.model.Student;
|
||||||
|
import com.baeldung.spring.mybatis.service.StudentService;
|
||||||
|
|
||||||
|
public class SpringMyBatisApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args){
|
||||||
|
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("mybatis-spring.xml");
|
||||||
|
|
||||||
|
StudentService studentService = (StudentService) ctx.getBean("studentService");
|
||||||
|
Student student = new Student();
|
||||||
|
student.setFirstName("Santosh");
|
||||||
|
student.setLastName("B S");
|
||||||
|
student.setEmailAddress("santosh.bse@gmail.com");
|
||||||
|
student.setPassword("Test123");
|
||||||
|
student.setDateOfBirth(new Date());
|
||||||
|
student.setUserName("santoshbs1");
|
||||||
|
|
||||||
|
boolean result = studentService.insertStudent(student);
|
||||||
|
if(result){
|
||||||
|
System.out.println("Student record saved successfully");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
System.out.println("Encountered an error while saving student data");
|
||||||
|
}
|
||||||
|
|
||||||
|
final String userName = "santosh";
|
||||||
|
Student matchingStudent = studentService.getStudentByUserName(userName);
|
||||||
|
if(matchingStudent == null){
|
||||||
|
System.out.println("No matching student found for User Name - " + userName);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
System.out.println("Student Details are as follows : ");
|
||||||
|
System.out.println("First Name : " + matchingStudent.getFirstName());
|
||||||
|
System.out.println("Last Name : " + matchingStudent.getLastName());
|
||||||
|
System.out.println("EMail : " + matchingStudent.getEmailAddress());
|
||||||
|
System.out.println("DOB : " + matchingStudent.getDateOfBirth());
|
||||||
|
System.out.println("User Name : " + matchingStudent.getUserName());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
package com.baeldung.spring.mybatis.controller;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.ui.ModelMap;
|
||||||
|
import org.springframework.validation.BindingResult;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
import org.springframework.web.bind.annotation.SessionAttributes;
|
||||||
|
|
||||||
|
import com.baeldung.spring.mybatis.model.Student;
|
||||||
|
import com.baeldung.spring.mybatis.model.StudentLogin;
|
||||||
|
import com.baeldung.spring.mybatis.service.StudentService;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@SessionAttributes("student")
|
||||||
|
public class StudentController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private StudentService studentService;
|
||||||
|
|
||||||
|
@RequestMapping(value = "/signup", method = RequestMethod.GET)
|
||||||
|
public String signup(Model model) {
|
||||||
|
Student student = new Student();
|
||||||
|
model.addAttribute("student", student);
|
||||||
|
return "signup";
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/signup", method = RequestMethod.POST)
|
||||||
|
public String signup(@Validated @ModelAttribute("student") Student student, BindingResult result, ModelMap model) {
|
||||||
|
if (studentService.getStudentByUserName(student.getUserName())) {
|
||||||
|
model.addAttribute("message", "User Name exists. Try another user name");
|
||||||
|
return "signup";
|
||||||
|
} else {
|
||||||
|
studentService.insertStudent(student);
|
||||||
|
model.addAttribute("message", "Saved student details");
|
||||||
|
return "redirect:login.html";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/login", method = RequestMethod.GET)
|
||||||
|
public String login(Model model) {
|
||||||
|
StudentLogin studentLogin = new StudentLogin();
|
||||||
|
model.addAttribute("studentLogin", studentLogin);
|
||||||
|
return "login";
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
||||||
|
public String login(@ModelAttribute("studentLogin") StudentLogin studentLogin, BindingResult result, ModelMap model) {
|
||||||
|
boolean found = studentService.getStudentByLogin(studentLogin.getUserName(), studentLogin.getPassword());
|
||||||
|
if (found) {
|
||||||
|
return "success";
|
||||||
|
} else {
|
||||||
|
return "failure";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.baeldung.spring.mybatis.mappers;
|
||||||
|
|
||||||
|
import org.apache.ibatis.annotations.Insert;
|
||||||
|
import org.apache.ibatis.annotations.Options;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import com.baeldung.spring.mybatis.model.Student;
|
||||||
|
|
||||||
|
public interface StudentMapper {
|
||||||
|
@Insert("INSERT INTO student(userName, password, firstName,lastName, dateOfBirth, emailAddress) VALUES"
|
||||||
|
+ "(#{userName},#{password}, #{firstName}, #{lastName}, #{dateOfBirth}, #{emailAddress})")
|
||||||
|
@Options(useGeneratedKeys = true, keyProperty = "id", flushCache = true, keyColumn = "id")
|
||||||
|
public void insertStudent(Student student);
|
||||||
|
|
||||||
|
@Select("SELECT USERNAME as userName, PASSWORD as password, FIRSTNAME as firstName, LASTNAME as lastName, "
|
||||||
|
+ "DATEOFBIRTH as dateOfBirth, EMAILADDRESS as emailAddress " + "FROM student WHERE userName = #{userName}")
|
||||||
|
public Student getStudentByUserName(String userName);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
package com.baeldung.spring.mybatis.model;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class Student {
|
||||||
|
private Long id;
|
||||||
|
private String userName;
|
||||||
|
private String firstName;
|
||||||
|
private String lastName;
|
||||||
|
private String password;
|
||||||
|
private String emailAddress;
|
||||||
|
private Date dateOfBirth;
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
public String getUserName() {
|
||||||
|
return userName;
|
||||||
|
}
|
||||||
|
public void setUserName(String userName) {
|
||||||
|
this.userName = userName;
|
||||||
|
}
|
||||||
|
public String getFirstName() {
|
||||||
|
return firstName;
|
||||||
|
}
|
||||||
|
public void setFirstName(String firstName) {
|
||||||
|
this.firstName = firstName;
|
||||||
|
}
|
||||||
|
public String getLastName() {
|
||||||
|
return lastName;
|
||||||
|
}
|
||||||
|
public void setLastName(String lastName) {
|
||||||
|
this.lastName = lastName;
|
||||||
|
}
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
public String getEmailAddress() {
|
||||||
|
return emailAddress;
|
||||||
|
}
|
||||||
|
public void setEmailAddress(String emailAddress) {
|
||||||
|
this.emailAddress = emailAddress;
|
||||||
|
}
|
||||||
|
public Date getDateOfBirth() {
|
||||||
|
return dateOfBirth;
|
||||||
|
}
|
||||||
|
public void setDateOfBirth(Date dateOfBirth) {
|
||||||
|
this.dateOfBirth = dateOfBirth;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.baeldung.spring.mybatis.model;
|
||||||
|
|
||||||
|
public class StudentLogin {
|
||||||
|
private String userName;
|
||||||
|
private String password;
|
||||||
|
public String getUserName() {
|
||||||
|
return userName;
|
||||||
|
}
|
||||||
|
public void setUserName(String userName) {
|
||||||
|
this.userName = userName;
|
||||||
|
}
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.baeldung.spring.mybatis.service;
|
||||||
|
|
||||||
|
import com.baeldung.spring.mybatis.model.Student;
|
||||||
|
|
||||||
|
public interface StudentService {
|
||||||
|
public boolean insertStudent(Student student);
|
||||||
|
public Student getStudentByLogin(String userName, String password);
|
||||||
|
public Student getStudentByUserName(String userName);
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
package com.baeldung.spring.mybatis.service;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import com.baeldung.spring.mybatis.mappers.StudentMapper;
|
||||||
|
import com.baeldung.spring.mybatis.model.Student;
|
||||||
|
|
||||||
|
@Service("studentService")
|
||||||
|
public class StudentServiceImpl implements StudentService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private StudentMapper studentMapper;
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public boolean insertStudent(Student student) {
|
||||||
|
boolean result=false;
|
||||||
|
try{
|
||||||
|
studentMapper.insertStudent(student);
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
catch(Exception ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Student getStudentByLogin(String userName, String password) {
|
||||||
|
Student student = studentMapper.getStudentByUserName(userName);
|
||||||
|
return student;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Student getStudentByUserName(String userName) {
|
||||||
|
Student student = studentMapper.getStudentByUserName(userName);
|
||||||
|
return student;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
54
spring-mybatis/src/main/resources/mybatis-spring.xml
Normal file
54
spring-mybatis/src/main/resources/mybatis-spring.xml
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?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" xmlns:tx="http://www.springframework.org/schema/tx"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
|
||||||
|
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||||
|
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
|
||||||
|
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
|
||||||
|
|
||||||
|
<mvc:annotation-driven />
|
||||||
|
<context:component-scan base-package="com.baeldung.spring.mybatis" />
|
||||||
|
<bean
|
||||||
|
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
|
||||||
|
<property name="prefix" value="/WEB-INF/jsp/" />
|
||||||
|
<property name="suffix" value=".jsp" />
|
||||||
|
</bean>
|
||||||
|
<!-- <bean id="dataSource"
|
||||||
|
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
|
||||||
|
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
|
||||||
|
<property name="url" value="jdbc:mysql//localhost:3306/baeldung;" />
|
||||||
|
<property name="username" value="root" />
|
||||||
|
<property name="password" value="admin" />
|
||||||
|
</bean> -->
|
||||||
|
|
||||||
|
|
||||||
|
<bean id="dataSource"
|
||||||
|
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
|
||||||
|
|
||||||
|
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
|
||||||
|
<property name="url" value="jdbc:mysql://localhost:3306/baeldung" />
|
||||||
|
<property name="username" value="root" />
|
||||||
|
<property name="password" value="admin" />
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<tx:annotation-driven transaction-manager="transactionManager" />
|
||||||
|
<bean id="transactionManager"
|
||||||
|
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
|
||||||
|
<property name="dataSource" ref="dataSource" />
|
||||||
|
</bean>
|
||||||
|
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
|
||||||
|
<property name="dataSource" ref="dataSource" />
|
||||||
|
<property name="typeAliasesPackage" value="com.baeldung.spring.mybatis.model" />
|
||||||
|
<property name="mapperLocations" value="classpath*:com/baeldung/spring/mappers/*.xml" />
|
||||||
|
</bean>
|
||||||
|
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
|
||||||
|
<constructor-arg index="0" ref="sqlSessionFactory" />
|
||||||
|
</bean>
|
||||||
|
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
|
||||||
|
<property name="basePackage" value="com.baeldung.spring.mybatis.mappers" />
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<bean id="studentService" class="com.baeldung.spring.mybatis.service.StudentServiceImpl"></bean>
|
||||||
|
|
||||||
|
</beans>
|
@ -0,0 +1,51 @@
|
|||||||
|
<?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" xmlns:tx="http://www.springframework.org/schema/tx"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
|
||||||
|
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||||
|
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
|
||||||
|
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
|
||||||
|
|
||||||
|
<mvc:annotation-driven />
|
||||||
|
<context:component-scan base-package="com.baeldung.spring.mybatis" />
|
||||||
|
<bean
|
||||||
|
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
|
||||||
|
<property name="prefix" value="/WEB-INF/jsp/" />
|
||||||
|
<property name="suffix" value=".jsp" />
|
||||||
|
</bean>
|
||||||
|
<!-- <bean id="dataSource"
|
||||||
|
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
|
||||||
|
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
|
||||||
|
<property name="url" value="jdbc:mysql//localhost:3306/baeldung;" />
|
||||||
|
<property name="username" value="root" />
|
||||||
|
<property name="password" value="admin" />
|
||||||
|
</bean> -->
|
||||||
|
|
||||||
|
|
||||||
|
<bean id="dataSource"
|
||||||
|
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
|
||||||
|
|
||||||
|
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
|
||||||
|
<property name="url" value="jdbc:mysql://localhost:3306/baeldung" />
|
||||||
|
<property name="username" value="root" />
|
||||||
|
<property name="password" value="admin" />
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<tx:annotation-driven transaction-manager="transactionManager" />
|
||||||
|
<bean id="transactionManager"
|
||||||
|
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
|
||||||
|
<property name="dataSource" ref="dataSource" />
|
||||||
|
</bean>
|
||||||
|
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
|
||||||
|
<property name="dataSource" ref="dataSource" />
|
||||||
|
<property name="typeAliasesPackage" value="com.baeldung.spring.mybatis.model" />
|
||||||
|
<property name="mapperLocations" value="classpath*:com/baeldung/spring/mappers/*.xml" />
|
||||||
|
</bean>
|
||||||
|
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
|
||||||
|
<constructor-arg index="0" ref="sqlSessionFactory" />
|
||||||
|
</bean>
|
||||||
|
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
|
||||||
|
<property name="basePackage" value="com.baeldung.spring.mybatis.mappers" />
|
||||||
|
</bean>
|
||||||
|
</beans>
|
36
spring-mybatis/src/main/webapp/WEB-INF/jsp/failure.jsp
Normal file
36
spring-mybatis/src/main/webapp/WEB-INF/jsp/failure.jsp
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
|
||||||
|
pageEncoding="ISO-8859-1"%>
|
||||||
|
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
|
||||||
|
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||||
|
<title>Login Failure</title>
|
||||||
|
<link href="assets/css/bootstrap-united.css" rel="stylesheet" />
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div style="width: 100%">
|
||||||
|
<a href="login.html">Login</a> <a
|
||||||
|
href="signup.html">Signup</a>
|
||||||
|
</div>
|
||||||
|
<div class="panel panel-danger">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<h3 class="panel-title">Student Enrollment Login failure</h3>
|
||||||
|
</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<div class="alert alert-dismissable alert-danger">
|
||||||
|
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||||
|
<strong>Oh snap!</strong> Something is wrong. Change a few things up
|
||||||
|
and try submitting again.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div></div>
|
||||||
|
<div></div>
|
||||||
|
|
||||||
|
<a class="btn btn-primary" href="<spring:url value="login.html"/>">Try
|
||||||
|
again?</a>
|
||||||
|
</body>
|
||||||
|
</html>
|
81
spring-mybatis/src/main/webapp/WEB-INF/jsp/login.jsp
Normal file
81
spring-mybatis/src/main/webapp/WEB-INF/jsp/login.jsp
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
|
||||||
|
pageEncoding="ISO-8859-1"%>
|
||||||
|
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
|
||||||
|
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.error {
|
||||||
|
color: #ff0000;
|
||||||
|
font-size: 0.9em;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.errorblock {
|
||||||
|
color: #000;
|
||||||
|
background-color: #ffEEEE;
|
||||||
|
border: 3px solid #ff0000;
|
||||||
|
padding: 8px;
|
||||||
|
margin: 16px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<title>Student Login</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div style="width: 100%">
|
||||||
|
<a href="login.html">Login</a> <a
|
||||||
|
href="signup.html">Signup</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<div>
|
||||||
|
<div>
|
||||||
|
<h1>Welcome to Online Student Enrollment Application</h1>
|
||||||
|
<p>Login to explore the complete features!</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<fieldset>
|
||||||
|
<legend>Student Enrollment Login Form</legend>
|
||||||
|
<form:form id="myForm" method="post"
|
||||||
|
class="bs-example form-horizontal" modelAttribute="studentLogin" action="login.html">
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td><label for="userNameInput" class="col-lg-3 control-label">User
|
||||||
|
Name : </label></td>
|
||||||
|
<td><form:input type="text" class="form-control"
|
||||||
|
path="userName" id="userNameInput" placeholder="User Name" /> <form:errors
|
||||||
|
path="userName" cssClass="error" /></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><label for="passwordInput" class="col-lg-3 control-label">Password</label>
|
||||||
|
</td>
|
||||||
|
<td><form:input type="password" class="form-control"
|
||||||
|
path="password" id="passwordInput" placeholder="Password" /> <form:errors
|
||||||
|
path="password" cssClass="error" /></td>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<button class="btn btn-default">Cancel</button>
|
||||||
|
|
||||||
|
<button class="btn btn-primary">Login</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
</table>
|
||||||
|
|
||||||
|
</form:form>
|
||||||
|
</fieldset>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
130
spring-mybatis/src/main/webapp/WEB-INF/jsp/signup.jsp
Normal file
130
spring-mybatis/src/main/webapp/WEB-INF/jsp/signup.jsp
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
|
||||||
|
pageEncoding="ISO-8859-1"%>
|
||||||
|
|
||||||
|
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
|
||||||
|
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
|
||||||
|
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
|
||||||
|
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||||
|
<title>Student Signup</title>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.green {
|
||||||
|
font-weight: bold;
|
||||||
|
color: green;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
color: #ff0000;
|
||||||
|
font-size: 0.9em;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.errorblock {
|
||||||
|
color: #000;
|
||||||
|
background-color: #ffEEEE;
|
||||||
|
border: 3px solid #ff0000;
|
||||||
|
padding: 8px;
|
||||||
|
margin: 16px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div style="width: 100%">
|
||||||
|
<a href="login.html">Login</a> <a
|
||||||
|
href="signup.html">Signup</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<div>
|
||||||
|
<div>
|
||||||
|
<h1>Welcome to Online Student Enrollment Application</h1>
|
||||||
|
<p>Login to explore the complete features!</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<c:if test="${not empty message}">
|
||||||
|
<div class="message green">${message}</div>
|
||||||
|
</c:if>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="width: 100%;">
|
||||||
|
<form:form id="myForm" method="post"
|
||||||
|
class="bs-example form-horizontal" action="signup.html" modelAttribute="student">
|
||||||
|
<fieldset>
|
||||||
|
<legend>Student Enrollment Signup Form</legend>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td><label for="userNameInput" class="col-lg-3 control-label">User
|
||||||
|
Name</label></td>
|
||||||
|
<td><form:input type="text" class="form-control"
|
||||||
|
path="userName" id="userNameInput" placeholder="User Name" /> <form:errors
|
||||||
|
path="userName" cssClass="error" /></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><label for="passwordInput" class="col-lg-3 control-label">Password</label>
|
||||||
|
</td>
|
||||||
|
<td><form:input type="password" class="form-control"
|
||||||
|
path="password" id="passwordInput" placeholder="Password" /> <form:errors
|
||||||
|
path="password" cssClass="error" /></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td><label for="firstNameInput"
|
||||||
|
class="col-lg-3 control-label">First Name</label></td>
|
||||||
|
<td><form:input type="text" class="form-control"
|
||||||
|
path="firstName" id="firstNameInput" placeholder="First Name" />
|
||||||
|
<form:errors path="firstName" cssClass="error" /></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><label for="lastNameInput" class="col-lg-3 control-label">Last
|
||||||
|
Name</label></td>
|
||||||
|
<td><form:input type="text" class="form-control"
|
||||||
|
path="lastName" id="lastNameInput" placeholder="Last Name" /> <form:errors
|
||||||
|
path="lastName" cssClass="error" /></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td><label for="dateOfBirthInput"
|
||||||
|
class="col-lg-3 control-label">Date of Birth</label></td>
|
||||||
|
<td><form:input type="text" class="form-control"
|
||||||
|
path="dateOfBirth" id="dateOfBirthInput"
|
||||||
|
placeholder="Date of Birth" /> <form:errors path="dateOfBirth"
|
||||||
|
cssClass="error" /></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><label for="emailAddressInput"
|
||||||
|
class="col-lg-3 control-label">Email Address</label></td>
|
||||||
|
<td><form:input type="text" class="form-control"
|
||||||
|
path="emailAddress" id="emailAddressInput"
|
||||||
|
placeholder="Email Address" /> <form:errors path="emailAddress"
|
||||||
|
cssClass="error" /></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<button class="btn btn-default">Cancel</button>
|
||||||
|
|
||||||
|
<button class="btn btn-primary" data-toggle="modal"
|
||||||
|
data-target="#themodal">Submit</button>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</fieldset>
|
||||||
|
</form:form>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
35
spring-mybatis/src/main/webapp/WEB-INF/jsp/success.jsp
Normal file
35
spring-mybatis/src/main/webapp/WEB-INF/jsp/success.jsp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
|
||||||
|
pageEncoding="ISO-8859-1"%>
|
||||||
|
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||||
|
<title>Login Success</title>
|
||||||
|
<link href="assets/css/bootstrap-united.css" rel="stylesheet" />
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div style="width: 100%">
|
||||||
|
<a href="login.html">Login</a> <a
|
||||||
|
href="signup.html">Signup</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="panel panel-success">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<h3 class="panel-title">Student Enrollment Login success</h3>
|
||||||
|
</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<div class="alert alert-dismissable alert-success">
|
||||||
|
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||||
|
<strong>Well done!</strong> You successfully logged-into the system.
|
||||||
|
Now you can explore the complete features!
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div></div>
|
||||||
|
<div></div>
|
||||||
|
<a class="btn btn-primary" href="<spring:url value="login.html"/>">Login
|
||||||
|
as different user?</a>
|
||||||
|
</body>
|
||||||
|
</html>
|
Binary file not shown.
21
spring-mybatis/src/main/webapp/WEB-INF/web.xml
Normal file
21
spring-mybatis/src/main/webapp/WEB-INF/web.xml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>myBatisSpringServlet</servlet-name>
|
||||||
|
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
||||||
|
<init-param>
|
||||||
|
<param-name>contextConfigLocation</param-name>
|
||||||
|
<param-value>/WEB-INF/conf/mybatis-spring.xml</param-value>
|
||||||
|
</init-param>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>myBatisSpringServlet</servlet-name>
|
||||||
|
<url-pattern>*.html</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<display-name>MyBatis-Spring Integration</display-name>
|
||||||
|
</web-app>
|
34
spring-mybatis/src/main/webapp/index.jsp
Normal file
34
spring-mybatis/src/main/webapp/index.jsp
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<link href="assets/css/bootstrap-united.css" rel="stylesheet" />
|
||||||
|
<link href="bootstrap/css/bootstrap-responsive.css" rel="stylesheet" />
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
height: 100%;
|
||||||
|
margin: 0;
|
||||||
|
background: url(assets/img/books.jpg);
|
||||||
|
background-size: 1440px 800px;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
display: compact;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div style="width: 100%">
|
||||||
|
<a href="login.html">Login</a> <a
|
||||||
|
href="signup.html">Signup</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<div>
|
||||||
|
<div>
|
||||||
|
<h1>Welcome to Online Student Enrollment Application</h1>
|
||||||
|
<p>Login to explore the complete features!</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
x
Reference in New Issue
Block a user