@Component Scan Annotation Spring
Auto Binding Object
==================================
<?xml version='1.0' encoding='UTF-8' ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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.xsd ">
<context:component-scan base-package="com.hello"/>
<context:component-scan base-package="com.model"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
=======================================
package com.model;
public class Student
{
private String mail,pass;
public String getMail() {
return mail;
}
public void setMail(String mail) {
this.mail = mail;
}
public String getPass() {
return pass;
}
public void setPass(String pass) {
this.pass = pass;
}
@Override
public String toString() {
return "Student{" + "mail=" + mail + ", pass=" + pass + '}';
}
}
========================================
package com.hello;
import com.model.Student;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class Main
{
@RequestMapping("/postdata")
public String hello(Student s)
{
System.out.println("Student ::: " + s);
return "yes";
}
}
==========================================
Comments
Post a Comment