S2SH無配置詳解

2021-06-20 11:21:50 字數 2491 閱讀 7566

1.      hibernate

hebernate3.0後可以使用註解自動對映刪除配置檔案,加入的包是hibernate-annotations-3.3.1.ga.jar和ejb3-persistence-1.0.1.ga.jar就可以實現(版本可以不同)。

例子:@entity

@table

(name=

"airline")

public

classairlineimplementsserializable

public

voidsetalid(string alid)

@manytoone

(fetch=fetchtype.

lazy)

@joincolumn

(name=

"ofid")

publicoffice getofid()

public

voidsetofid(office ofid)

publicstring getname()

public

voidsetname(string name)

publicstring getnetaddress()

public

voidsetnetaddress(string netaddress)

publicstring getcode()

public

voidsetcode(string code)

publicstring getmoneyphone()

public

voidsetmoneyphone(string moneyphone)

publicstring getticketphone()

public

voidsetticketphone(string ticketphone)

publicinteger getimpower()

public

voidsetimpower(integer impower)

publicinteger gettype()

public

voidsettype(integer type) }

只有主鍵和關聯外來鍵有注釋其他都可以沒有注釋。

2.      struts2

struts2.1後可以使用「約定大約」外掛程式實現0配置檔案,規則是返回值為jsp的一部分名稱jsp的全名為「類名」-「返回值」中間橫槓隔開---convention_plugin.jar。

例子:publicclass hellowordaction{

publicstring list(){

return「list」;

對應的jsp頁面是:hello-word-list.jsp類名要小寫多個單詞的用橫崗隔開返回值在最後。

3.      spring

spring2.1以後set()、get()方法注入可以自動注入不用寫set()、get()方法。

例子:@autowired

privatefeaturemanager

featuremanager;

不用再寫出

featuremanager

的set()

、get()

方法了,在

中這樣配置:

<

context:component-scan

base-package

="org.eline.dao,org.eline.service"

/>

放在最外層的下

<

bean id=

"sessionfactory"

class

="org.springframework.orm.hibernate3.annotation.annotationsessionfactorybean"

> ……

之前不變在最後加入

<

property

name

="packagestoscan"

value

="org.eline.entity*.*"

/>

bean

>

就可以使用了

4,struts2配置action的入口

s2sh整合開發的配置

下面給出整合開發時struts 2 hibernate spring需要的jar,包太多不打字了,直接截圖。ps 我資料庫用的是mysql 的配置模版 第一步在 spring 中配置資料來源 第二步整合進 hibernate hibernate.dialect org.hibernate.diale...

S2SH整合步驟

s2sh 整合步驟 一.搭建開發環境 1.準備三者的 jar檔案 不要忘記相應資料庫的驅動.2.配置web.xml檔案,主要配置兩項內容 1 自動載入 spring 容器的 contextloaderlistener配置 2 應用 struts2 的過濾器 filterdispatcher配置 3....

s2sh中beanFactory的初始化

在s2sh中web.xml檔案中的如下語句 listener listener class org.springframework.web.context.contextloaderlistener listener class listener context param param name c...