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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

spring框架学习笔记(一)

發(fā)布時(shí)間:2025/5/22 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 spring框架学习笔记(一) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

僅為個(gè)人筆記,方便自己日后查看。

?

eclipse安裝spring插件的方法:

http://jingyan.baidu.com/article/1612d5005fd087e20f1eee10.html

?

使用maven添加spring需要的jar包。

幾個(gè)必須的jar包:core、bean、context、express。另外依賴一個(gè)日志包c(diǎn)ommons—logging

pom.xml文件中為了統(tǒng)一版本,因此在properties寫了版本號(hào)如下:

<properties><!-- spring版本號(hào) --><spring.version>4.0.2.RELEASE</spring.version><!-- mybatis版本號(hào) --><mybatis.version>3.2.6</mybatis.version><!-- log4j日志文件管理包版本 --><slf4j.version>1.7.7</slf4j.version><log4j.version>1.2.17</log4j.version></properties>

完整示例pom文件為:

<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.pf.Soft</groupId><artifactId>MySpringLearn</artifactId><version>0.0.1-SNAPSHOT</version><properties><!-- spring版本號(hào) --><spring.version>4.0.2.RELEASE</spring.version><!-- Mybatis版本號(hào) --><mybatis.version>3.2.6</mybatis.version><!-- log4j日志文件管理包版本 --><slf4j.version>1.7.7</slf4j.version><log4j.version>1.2.17</log4j.version></properties><dependencies><!-- Spring核心包 --><dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-beans</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-expression</artifactId><version>${spring.version}</version></dependency><!-- Spring依賴的日志包--><dependency><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId><version>1.1.3</version></dependency></dependencies> </project>

?

創(chuàng)建實(shí)體類ProductEntity:

public class ProductEntity {/*** 商品編碼*/private String prodNo;/*** 商品名稱*/private String prodName;/*** * @return the prodNo*/public String getProdNo() {return prodNo;}/*** @param prodNo the prodNo to set*/public void setProdNo(String prodNo) {this.prodNo = prodNo;}/*** * @return the prodName*/public String getProdName() {return prodName;}/*** @param prodName the prodName to set*/public void setProdName(String prodName) {this.prodName = prodName;}

關(guān)鍵點(diǎn):

  • spring的application配置文件
  • 使用spring來獲取對(duì)象
  • applicationContext.xml文件如下:

    <?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.xsd"><!--xml的方式配置bean --><bean id="productBean" class="com.pfSoft.beans.ProductEntity"><property name="prodNo" value="牙膏"></property><property name="prodName" value="筷子"></property></bean></beans>

    ?

    ?

    測(cè)試,使用spring來創(chuàng)建對(duì)象:

    ApplicationContext applicationContext;@Beforepublic void init() {applicationContext=new ClassPathXmlApplicationContext("applicationContext.xml");}@Testpublic void test() {try {ProductEntity productEntity= (ProductEntity) applicationContext.getBean("productBean");System.out.println(productEntity.getProdNo());System.out.println(productEntity.getProdName());} catch (Exception e) {// TODO: handle exception}Calendar calendar = Calendar.getInstance();}

    ?

    轉(zhuǎn)載于:https://www.cnblogs.com/falcon-fei/p/5398795.html

    總結(jié)

    以上是生活随笔為你收集整理的spring框架学习笔记(一)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

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