Spring Simple configuration and operation (Create entity class, configure XML file, Debug)

Source: Internet
Author: User

< 1 > Entity class person

 PackageJava_spring.modle;/*** One entity class (person)*/ Public classPerson {Private intuserId; PrivateString UserName; PrivateString Userage;  Public intgetUserId () {returnuserId; }     Public voidSetuserid (intuserId) {         This. UserId =userId; }     PublicString GetUserName () {returnUserName; }     Public voidsetusername (String userName) { This. UserName =UserName; }     PublicString getuserage () {returnUserage; }     Public voidsetuserage (String userage) { This. Userage =Userage; } @Override PublicString toString () {return"Person [userid= + userId +", username= "+ UserName +", userage= "+ Userage +"] "; }}

< 2 > configuration file spring.xml

<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" >    <!--Configure a person to power class Personone and assign values through spring -    <BeanID= "Personone"class= "Java_spring.modle.Person">        < Propertyname= "UserId"value= "1"></ Property>        < Propertyname= "UserName"value= "Zhang San Feng"></ Property>        < Propertyname= "Userage"value= "Male"></ Property>    </Bean></Beans>

< 3 > Test class Testone

 PackageJava_spring.a_main;ImportOrg.springframework.context.ApplicationContext;ImportOrg.springframework.context.support.ClassPathXmlApplicationContext;ImportJava_spring.modle.Person; Public classTestone { Public Static voidMain (string[] args) {//Gets the IOC container object for spring, which is the path of the configuration file relative to SRCApplicationContext AC =NewClasspathxmlapplicationcontext ("Java_spring/config/spring.xml"); //gets the configured JavaBean object through the container object, the parameter is the ID in the configuration filePerson Personone = (person) ac.getbean ("Personone");    System.out.println (Personone); }}

Spring Simple configuration and operation (Create entity class, configure XML file, Debug)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.