日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

spring第一个小例子(Spring_xjs1)

發(fā)布時間:2025/6/17 javascript 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 spring第一个小例子(Spring_xjs1) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.


第一個spring小例子(使用Spring4.0版本)

Spring-HelloWord

**導(dǎo)入核心jar包:

spring-beans

spring-context

spring-core

spring-aop

spring-expression

spring-logging

?步驟:1

在項目名上右鍵選擇properties-->Project Facets/Runtimes進行配置。


pom.xml文件:

<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/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.oracle.dwp</groupId><artifactId>Spring_first</artifactId><version>1.0.0</version><dependencies><!-- aop --><dependency><groupId>org.springframework</groupId><artifactId>spring-aop</artifactId><version>4.0.0.RELEASE</version></dependency><!-- 上下文 --><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>4.0.0.RELEASE</version></dependency><!-- junit單元測試 --><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.10</version><scope>test</scope></dependency></dependencies> </project>

Students.java實體類:

package com.entity;import java.io.Serializable; import java.util.Date;public class Students implements Serializable{private String sid;//學(xué)號private String name;//姓名private String gender;//性別private Date birthday;//生日private String address;//住址public Students(String sid, String name, String gender, Date birthday,String address) {this.sid = sid;this.name = name;this.gender = gender;this.birthday = birthday;this.address = address;}public Students() {}public String getSid() {return sid;}public void setSid(String sid) {this.sid = sid;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getGender() {return gender;}public void setGender(String gender) {this.gender = gender;}public Date getBirthday() {return birthday;}public void setBirthday(Date birthday) {this.birthday = birthday;}public String getAddress() {return address;}public void setAddress(String address) {this.address = address;}public String toString() {return "Students [sid=" + sid + ", name=" + name + ", gender=" + gender+ ", birthday=" + birthday + ", address=" + address + "]";}}

applicationContext.xml配置文件---Spring的配置文件

注意:里面有日期轉(zhuǎn)換的問題***

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="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-4.0.xsd"><bean id="dateFormat" class="java.text.SimpleDateFormat"><constructor-arg value="yyyy-MM-dd"/></bean><bean id="stu" class="com.entity.Students"><property name="sid" value="s0001"></property><property name="name" value="謝軍帥"></property><property name="gender" value="男"></property><property name="birthday"><bean factory-bean="dateFormat" factory-method="parse"><constructor-arg value="1998-07-15"></constructor-arg></bean></property><property name="address" value="安陽"></property></bean> </beans>

測試類StudentsTest.java:

package com.entity;import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;public class StudentsTest {@Testpublic void fun1(){//獲得上下文對象ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");//獲得名字叫stu的學(xué)生對象。通過IOC容器獲得//這個學(xué)生對象是通過IOC容器注入給你的,無需用new.---利用反射//兩大核心技術(shù):1.XML解析2.反射Students s = (Students) ctx.getBean("stu");System.out.println(s); } }

測試結(jié)果:

Students [sid=s0001, name=謝軍帥, gender=男, birthday=Wed Jul 15 00:00:00 GMT+08:00 1998, address=安陽]

  

?

轉(zhuǎn)載于:https://www.cnblogs.com/xjs1874704478/p/11171158.html

總結(jié)

以上是生活随笔為你收集整理的spring第一个小例子(Spring_xjs1)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。