<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<!--
========================= RESOURCE DEFINITIONS
=========================
-->
<!--
Configurer that replaces ${...} placeholders with values from a
properties file
-->
<!--
(in this case, JDBC-related settings for the dataSource definition
below)
-->
<context:property-placeholder location="classpath:jdbc.properties" />
<!--
Uses Apache Commons DBCP for connection pooling. See Commons DBCP
documentation for the required JAR files. Alternatively you can use
another connection pool such as C3P0, similarly configured using
Spring.
-->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close" p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.url}" p:username="${jdbc.username}" p:password="${jdbc.password}" />
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
p:dataSource-ref="dataSource" p:mappingResources="dbtables.hbm.xml">
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
</props>
</property>
<property name="eventListeners">
<map>
<entry key="merge">
<bean
class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener" />
</entry>
</map>
</property>
</bean>
<!--
Transaction manager for a single Hibernate SessionFactory (alternative
to JTA)
-->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory" />
<!--
========================= BUSINESS OBJECT DEFINITIONS
=========================
-->
<!--
Activates various annotations to be detected in bean classes: Spring's
@Required and @Autowired, as well as JSR 250's @Resource.
-->
<context:annotation-config />
<!--
Instruct Spring to perform declarative transaction management
automatically on annotated classes.
-->
<tx:annotation-driven />
<!--
Exporter that exposes the Hibernate statistics service via JMX.
Autodetects the service MBean, using its bean name as JMX object name.
-->
<context:mbean-export />
<!--
Project's central data access object: Hibernate implementation
-->
<bean id="login" class="org.Spring.project.service.ILoginImpl" />
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
- Mapping file for the Hibernate implementation of the Login Interface
-->
<hibernate-mapping auto-import="true" default-lazy="false">
<class name="org.spring.project.model.Registration" table="Login">
<!--This code emphasize that usr_id is the primary key-->
<id name="usr_id" column="usr_id">
</id>
<!--Other fields in the DB-->
<property name="usr_name" column="usr_name"/>
<property name="usr_password" column="usr_password"/>
</class>
</hibernate-mapping>
package org.spring.project.model;
public class Registration
{
private String usr_id;
private String usr_name;
private String usr_password;
public String getUsr_id() {
return usr_id;
}
public void setUsr_id(String usrId) {
usr_id = usrId;
}
public String getUsr_name() {
return usr_name;
}
public void setUsr_name(String usrName) {
usr_name = usrName;
}
public String getUsr_password() {
return usr_password;
}
public void setUsr_password(String usrPassword) {
usr_password = usrPassword;
}
}
package org.spring.project.service;
import org.apache.log4j.Logger;
import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Expression;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.spring.project.model.Registration;
@Service(“loginservice”)
@Transactional
public class ILoginImpl implements ILogin {
@Autowired
private SessionFactory sessionFactory;
private final Logger log = Logger.getLogger(ILoginImpl.class);
@Override
public void insertData(Registration reg) {
log.info("Inside implementation");
sessionFactory.getCurrentSession().save(reg);
}
}
package org.spring.project.web;
import org.springframework.beans.factory.annotation.Autowired;
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;
import org.tbingo.project.model.PGRequestModel;
import org.spring.project.service.ILogin;
@Controller
@RequestMapping("/login")
public class LoginController{
private final ILogin login;
@Autowired
public PGForwardController(ILogin login) {
this.login = login;
}
@RequestMapping(method=RequestMethod.POST)
public String forwardPG(Registration reg,Model model){
String message = "";
if(login.insertData(reg))
{success="Data inserted successfully";}
else{success="Problem inserting Data";}
model.addAttribute("message",success);//Pass the msg to a JSP page
return "reg_success";//name of the JSP page
// To display the msg in JSP page, use ${message}. Thats it
}
}
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)