Hibernate3 提供了DetachedCriteria,使得我们可以在Web层构造 2Z+Wu3#
GSoX<*i
detachedCriteria,然后调用业务层Bean,进行动态条件查询,根 =mO vs
GA$V0YQX
据这一功能,我设计了通用的抽象Bean基类和分页类支持,代码来 .T}Wdng
QVv#fy1"6
自于Quake Wang的javaeye-core包的相应类,然后又做了很多修改 P}Gj%4/G
h=W:^@G
。 %:M^4~dc
Ow+GS{-q
分页支持类: LD+{o 4i
1auIR/=-
java代码: iW)8j 8
6/f7<
k9<;woOBO
package com.javaeye.common.util; 35h8O,Y
'F/~o1\.
import java.util.List; fW{(lPx
{0L1X6eg
publicclass PaginationSupport { `xKp%9
^%d\qd`
publicfinalstaticint PAGESIZE = 30; YX!{P=Ua
n7zm>&
privateint pageSize = PAGESIZE; hwPw]Ln/
%41m~Wh2
privateList items; Me r/G2#&
lS"T4 5
privateint totalCount; Jf{*PgP
=J18eH!]
privateint[] indexes = newint[0]; {JO^tI
ZJnYIK
privateint startIndex = 0; `"Jj1O@
Q$a{\*[:+
public PaginationSupport(List items, int +! ]zA4x
6]&OrS[
totalCount){ .6ylZ
setPageSize(PAGESIZE); TtJH7
setTotalCount(totalCount); 9)h"-H;5:
setItems(items); Fe# 1
setStartIndex(0); 9>=;FY
} 9"N~yKa`"K
{dhXIs
public PaginationSupport(List items, int _:ReN_0
z{8bvuE
totalCount, int startIndex){ KWq+PeB5TS
setPageSize(PAGESIZE); B?OFe'*
setTotalCount(totalCount); '3R`lv
setItems(items); $By<$
setStartIndex(startIndex); 8^kGS-+^
} KKb,d0T[
IY_iB*T3jt
public PaginationSupport(List items, int .ODU
y;4OY
totalCount, int pageSize, int startIndex){ 4(#'_jS
setPageSize(pageSize); (j%~u&+-
setTotalCount(totalCount); MS
nG3]{z
setItems(items); ntu5{L'8
setStartIndex(startIndex); v3*_9e
} D.r<QO~6B
2+RUTOv/d
publicList getItems(){ yjO1 Ol
return items; .Hescg/S
} \Q {m9fE
_jvxc'6
publicvoid setItems(List items){ A9[ F
this.items = items; R#s)r
} NyaQI<5D
n"h`5p5'
publicint getPageSize(){ <]6SN
return pageSize; Ka'=o?'B5
} C0sX gM
Vouvr<43o
publicvoid setPageSize(int pageSize){ 2VPdw@"~}
this.pageSize = pageSize; *zaQx+L
} p99]
<3oWEm
publicint getTotalCount(){ <KJ/<0l
return totalCount; ;/bewivNJ
} H/"-Z;0{
vRznw&^E
publicvoid setTotalCount(int totalCount){ S:u:z=:r
if(totalCount > 0){ }V'}E\\
this.totalCount = totalCount; 2pZXZ
int count = totalCount / g6yB6vk
|sa]F5
pageSize; 'g">LQ~a+
if(totalCount % pageSize > 0) ):P?
count++; # ncRb
indexes = newint[count]; l.(v^3:X
for(int i = 0; i < count; i++){ .fn\]rUv
indexes = pageSize * ;RH;OE,A
a`wc\T^
i; FW;m\vu
} , |0}<%
}else{ W1WYej"
this.totalCount = 0; 4%{,]
q\p
} zp6C3RG(
} S\^Pha
q
32(^Te]:
publicint[] getIndexes(){ oF vfCrd
return indexes; &]Q@7Nl7:l
} o m!!Sl 3
/hpY f]t
publicvoid setIndexes(int[] indexes){ c|f<u{'
this.indexes = indexes; l\f*d6o
} B=U 3
y3vdUauOn
publicint getStartIndex(){ dR
K?~1
return startIndex; 3D6RLu
} Zj_b>O-V
# ' =a=8-$
publicvoid setStartIndex(int startIndex){ jY&k
if(totalCount <= 0) pk>^?MO
this.startIndex = 0; IWk4&yHUAu
elseif(startIndex >= totalCount) Lk|hQ
this.startIndex = indexes !zBhbmlKt
Plc-4y1
[indexes.length - 1]; 1&\0:vA^Y
elseif(startIndex < 0) ;[(oaK@+n
this.startIndex = 0; |O3q@
else{ 8aZ=?_gvT
this.startIndex = indexes cv8L-Z>x.=
3v(* 5
[startIndex / pageSize]; Pi=+/}
} ;$HftG>B
} f0!))/rSD
;i4Q|
publicint getNextIndex(){ o5d%w-'
int nextIndex = getStartIndex() + tE.FrZS
/{Is0+)
pageSize; ag;Q F
if(nextIndex >= totalCount) /Jta^Bj
return getStartIndex(); Y&`=jDI
else 85>05?
return nextIndex; W=lyIb{?^0
} mD/9J5:
@efh{
publicint getPreviousIndex(){ "_P;2N6
int previousIndex = getStartIndex() - 0*VWzH
q$p%ZefZ
pageSize; ysJQb~2q
if(previousIndex < 0) md=TjMaY
return0; JELTo u
else "Hya6k>j
return previousIndex; IO wj>t
} o\BOL3H
1Vsz4P"O $
} A_V]yP
H[m:0eF'5
R$v[!A+:'
>~#yu&*D
抽象业务类 >q#rw
java代码: _uWpJhCT
B3: ez
jj
ZLc -RM
/** %}[i'rT>
* Created on 2005-7-12 A mvEf
*/ @_-hk|Nl@
package com.javaeye.common.business; $>G8_q
yZ
@"\Z!
import java.io.Serializable; m];]7uB5=
import java.util.List; ,ly\Ka?zO
=FlDb
5t{
import org.hibernate.Criteria; }bs+-K
import org.hibernate.HibernateException; C](f>)Dz
/
import org.hibernate.Session; dFRsm0T
import org.hibernate.criterion.DetachedCriteria; 6RG)`bu
import org.hibernate.criterion.Projections; iyA'#bE-
import C\\~E9+
:=}BN
org.springframework.orm.hibernate3.HibernateCallback; 5rwu!Y;7*
import -]L6=
wHzEMwY_
org.springframework.orm.hibernate3.support.HibernateDaoS 3("_Z%
f6EZ(
v
upport; \"qY "V
Olt`:;j-
import com.javaeye.common.util.PaginationSupport; ) dn(G@5
T m,b,hi$
public abstract class AbstractManager extends oin$-i|Xp!
<x@}01~
HibernateDaoSupport { YO#M/%^j
|pm7 _[
privateboolean cacheQueries = false; pyH:#5
T{Gj+7bQ~
privateString queryCacheRegion; !_"@^?,q
DD7h^-x
publicvoid setCacheQueries(boolean $g@=Z"
xRJ\E }/7
cacheQueries){ M.Y~1c4f
this.cacheQueries = cacheQueries; VAWF3
} dOa+(fMe
RtGWG*v4]
publicvoid setQueryCacheRegion(String u0 P|0\
~F7-HaQJ
queryCacheRegion){ uYn_? G
this.queryCacheRegion = 7[w,:9& }
TBs|r#
queryCacheRegion; 0f~C#/[t7
} :a^t3s
Ed"h16j?z
publicvoid save(finalObject entity){ e63uLWDT
getHibernateTemplate().save(entity); 4h~iPn'Wl
} :imW\@u
"*($cQ$v
publicvoid persist(finalObject entity){ YbR!+ 0\g
getHibernateTemplate().save(entity); |P[w==AAf
} PbW(%7o(t
%+f>2U4I
publicvoid update(finalObject entity){ >,TUZ
getHibernateTemplate().update(entity); V:qSy#e
} vBRQp&YwX
J3,fk)
publicvoid delete(finalObject entity){ !i{aMxUP
getHibernateTemplate().delete(entity); |h- QP#]/
} 0Z~p%C<LW
Z?}dq-Vh&
publicObject load(finalClass entity, 'w!Cn>
FQm`~rA~zt
finalSerializable id){ >go,K{cK6
return getHibernateTemplate().load 7"aN#;&
`2' #!-
(entity, id); SFO({w(
} D'7SAFOM
_XG/Pp)
publicObject get(finalClass entity, XDsx3Ws
H!?c\7adX
finalSerializable id){ U@g4w!$r
return getHibernateTemplate().get )+l\w3^6
l9}3XI.=
(entity, id); q'|rgT
} pczug-nB
;fsZ7k4]do
publicList findAll(finalClass entity){ GO8GJ;B-U
return getHibernateTemplate().find("from $AfM>+GQ`n
yXz*5W_0D
" + entity.getName()); P=7zs;k
} ^.KwcXr
?>hPO73{
publicList findByNamedQuery(finalString MJOz.=CbhR
;hYS6
namedQuery){ 6;u$&&c(
return getHibernateTemplate }M1`di4e
'3_]Gu-D
().findByNamedQuery(namedQuery); Ge2q%
} Z8zmHc"IH
]or>?{4g
publicList findByNamedQuery(finalString query, cJN7bA{
Ai:BEPKe
finalObject parameter){ {/"2Vk<H8
return getHibernateTemplate @HQ`~C#Z'
)#P;
x"
().findByNamedQuery(query, parameter); 1>*#%R?W
} 9XPo3;
u\ #"L
publicList findByNamedQuery(finalString query, a&tSj35*6
" 7!;KHc
finalObject[] parameters){ 5Y.vJz
return getHibernateTemplate 1xD=ffM>8N
WfWN(:dF
().findByNamedQuery(query, parameters); b6}H$Sx~
} t?q@H8
h?rp|uPQ
publicList find(finalString query){ iJ~Zkd
return getHibernateTemplate().find V"*O=h
.l>77zM6
(query); #z&&M"*a|
} '>&^zgr
} ~h3c|
publicList find(finalString query, finalObject M*z~gOZ
#1`-*.u
parameter){ >xF/Pl
return getHibernateTemplate().find #N#'5w-G
eAXc:222
(query, parameter); v\!Be[ ?
} bvS(@
afv~r>q(-
public PaginationSupport findPageByCriteria OZx
W?wnd
AmaT0tzJC
(final DetachedCriteria detachedCriteria){ ]e^c=O`$
return findPageByCriteria |zR8rqBX;
3 DD ML,
(detachedCriteria, PaginationSupport.PAGESIZE, 0); vI2^tX9
} "B=
}!;s.[y
public PaginationSupport findPageByCriteria p;._HJ(
:z4)5=
6M
(final DetachedCriteria detachedCriteria, finalint %<E$,w>
e<=cdze
startIndex){ [onGNq?#
return findPageByCriteria lp<g\
v5By :z
(detachedCriteria, PaginationSupport.PAGESIZE, Av"R[)
"$N#p5
startIndex); L!rw[x
} L{hnU7sY
9{-EJ)
public PaginationSupport findPageByCriteria vWRju*Z&
K%"5ImM
(final DetachedCriteria detachedCriteria, finalint Q7R~{5r>W
ZT,B(#m
pageSize, T?
tG~
finalint startIndex){ j:k[90
return(PaginationSupport) '`eO\huf
]Bm/eRy"
getHibernateTemplate().execute(new HibernateCallback(){ <1FC%f/
publicObject doInHibernate E0u~i59Z
D[^m{ 9_
(Session session)throws HibernateException { 5!l0zLQPo
Criteria criteria = wS4.8iJ
RT)d ]u
detachedCriteria.getExecutableCriteria(session); 9:,V5n=
int totalCount = &Rx{.9
aemc2b*
((Integer) criteria.setProjection(Projections.rowCount /x5rf
VCn{mp*h
()).uniqueResult()).intValue(); an|x$e7|?
criteria.setProjection p8Q,@ql.
HR
;)|j{!
(null); )^4\,u\@
List items = T(e!_VY|m
3T"j)R_=l
criteria.setFirstResult(startIndex).setMaxResults 2C/$Ei^t
/h*>P:i].
(pageSize).list(); P^w#S
PaginationSupport ps = Z2TL #@
kB'Fkqwm
new PaginationSupport(items, totalCount, pageSize, Eve.QAl|
U}MXT<6
startIndex); ^;/b+ /B0
return ps; sB^<6W!`(
} 3H|_mX
}, true); u[L`-zI
} 2'_:S@
cgm81+[%r
public List findAllByCriteria(final Fb7#<h
eU<]o<
\Qo
DetachedCriteria detachedCriteria){ O+?<h{"
return(List) getHibernateTemplate Au4yBm
u
UVw~8o9s
().execute(new HibernateCallback(){ ag*mG*Z
publicObject doInHibernate :cq9f2)
EX?MA6U
(Session session)throws HibernateException { ^1Zeb$Nw'
Criteria criteria = } p&&_?
wQwQXNG
detachedCriteria.getExecutableCriteria(session); 0JlZs]
return criteria.list(); o(:[r@Z0z
}
"Qja1TQ
}, true); CAcS~ "
} MxY/`9>E|+
u>TZt]h8
public int getCountByCriteria(final -[6z 1"*
*d"DA[(
DetachedCriteria detachedCriteria){ e pU:
Integer count = (Integer) ))&;}2{
m|=H#
getHibernateTemplate().execute(new HibernateCallback(){ q{t*34R
publicObject doInHibernate NX|v=
,`gl&iB
(Session session)throws HibernateException { d/bEt&
Criteria criteria = mnmP<<8C,
=$nB/K,8AX
detachedCriteria.getExecutableCriteria(session); .G+Pe'4a
return M@?xa/E64
p;W.lcO`0
criteria.setProjection(Projections.rowCount DdVF,
kAu+zX>S+
()).uniqueResult(); pek%08VSEU
} wi4=OU1L)a
}, true); 1RK=,Wx
return count.intValue(); ?r?jl;A&
} UN zlN
} -5T=:2M
:_t}QP"
J2j U4mR
i { \%e
rk7QZVE
cG?cUw).E
用户在web层构造查询条件detachedCriteria,和可选的 n84GZ5O>7
|fSe>uVZ
startIndex,调用业务bean的相应findByCriteria方法,返回一个 !"<MsoY@
e46/{4F,
PaginationSupport的实例ps。 <
V\I~;
(rkU)Q
ps.getItems()得到已分页好的结果集 'A:x/iv}^
ps.getIndexes()得到分页索引的数组 ]R=,5kK3
ps.getTotalCount()得到总结果数 mExVYp h
ps.getStartIndex()当前分页索引 5g9; +}X;
ps.getNextIndex()下一页索引 DSt]{fl`P
ps.getPreviousIndex()上一页索引 ppFe-wY
tUgEeh6
cIp
D~0\
/r-aPJX
7}vg.hmZ
*Mw_0Y
CT1ja.\;
连续看了两篇robbin有关DetachedCriteria的介绍,感觉真的不错 2AtLyN'.
6%fKuMpK(
,尤其是上面的示例代码,让我着实觉得该对我原来的分页查询做 (4\d]*u5-c
QK+(g,)_86
一下代码重构了。 ed:@C?
HO[wTB|D]
我把原本我的做法也提供出来供大家讨论吧: '
4ER00
ET[kpL
首先,为了实现分页查询,我封装了一个Page类: TOoQZTI
java代码: wbe<'/X+
2 ho>eRX
)=-0M9e.{
/*Created on 2005-4-14*/ KID,|K
package org.flyware.util.page; A0Zt8>w
bzvh%RsW
/** E@P %v{)
* @author Joa Qu7T[<
* >P/][MT
*/ xY$iz)^0&
publicclass Page { Y}[ c^$S
<}sq?Sfq!
/** imply if the page has previous page */ ;>AL`M+
privateboolean hasPrePage; 1?| flK
0
s70r
/** imply if the page has next page */ 2hee./F`
privateboolean hasNextPage; wN2QK6Oc
O)Y?=G)
/** the number of every page */ gt/zpiKmV
privateint everyPage; ;L,mBQB?0b
Y&
F=t/U2
/** the total page number */ &`fhEN
privateint totalPage; {&"L~>/o
(I@rLvZr{
/** the number of current page */ eQVZO>)P1+
privateint currentPage; J@OB`2?Zv
H<QT3RF2
/** the begin index of the records by the current EZYBeqv
9
Rx
s
query */ 0d3+0EN{
privateint beginIndex; gd0Vp Xf'
|,aG%MTL
.cR
-V`
/** The default constructor */ Y2O"]phi@
public Page(){ ;/0 Q1-
!o>H1#2l
} /[9t`
W$'R}L
/** construct the page by everyPage nwN@DqO
* @param everyPage /"?HZ% W
* */ oX4q`rt
public Page(int everyPage){ ~`D|IWMDq
this.everyPage = everyPage; Z(ZiFPx2Z
} HXoX
b]7GmRekl
/** The whole constructor */ /RyR>G!
public Page(boolean hasPrePage, boolean hasNextPage, ?h0X,fl3
$-&BB(-{E&
rLU/W<F8
int everyPage, int totalPage, [y0O{,lI
int currentPage, int beginIndex){ Dk='+\
this.hasPrePage = hasPrePage; sO5?aB&
this.hasNextPage = hasNextPage; J-ePE7i
this.everyPage = everyPage; o=RM-tR`v
this.totalPage = totalPage; T2D<UhP
this.currentPage = currentPage; w ~ dk#=
this.beginIndex = beginIndex; .)+hH y
} }/,HM9Ke
*-12VIG'H
/** 4:7V./" 9
* @return iL=
m{
* Returns the beginIndex. (oJ9k[(
*/ `juLQH
publicint getBeginIndex(){ ZbT/$\0(6
return beginIndex; KE1ao9H8wR
} zh$}~RG[
5qf
BEPJ
/** o0ZM[0@j
* @param beginIndex =E&OuX-R
* The beginIndex to set. E0/mSm"(T
*/ Z--@.IYoJ
publicvoid setBeginIndex(int beginIndex){ #UtFD^h
this.beginIndex = beginIndex; `y+-H|%?
} WO6/X/#8b
Lw'9
/** bT6sb#"W
* @return )XfzLF7
* Returns the currentPage. HAYMX:%
*/ f""`cdqAOh
publicint getCurrentPage(){ ms_ VM>l
return currentPage; `+#G+Vu5
} xBFJ} v
a,Gxm!
/** 'u4ezwF;
* @param currentPage zd]D(qeX
* The currentPage to set. TrdZJ21#M
*/ {u[V{XIUh
publicvoid setCurrentPage(int currentPage){ CAT.4GM
this.currentPage = currentPage; !vn1v)6
} ^VT1vu
%03
@h?shW=^
/** &/A8-:m
* @return F/1#l@qN
* Returns the everyPage. +
<c^=&7Lq
*/ s!+"yK
publicint getEveryPage(){ 4Iq'/r
return everyPage; z5*=MlZ)R.
} jEz+1Nl)
@=5qT]%U3J
/** nJ?^?M'F%
* @param everyPage L&-hXGx=7
* The everyPage to set. $hR)i
*/ \#'TNmS
publicvoid setEveryPage(int everyPage){ FA90`VOWYU
this.everyPage = everyPage; ]0B|V2D#e
} #&8}<8V
L0%hnA@
/** !'=15&5@
* @return }<jb vCeK
* Returns the hasNextPage. mfny4R1_
*/ -;;Z 'NM;8
publicboolean getHasNextPage(){ i{^Z1;Yl
return hasNextPage; ^O^:$nXhYy
} h5kPn~
/$"[k2 N
/** INSkgOo
* @param hasNextPage Y`6rEA0
* The hasNextPage to set. L?Yoh<
*/ N:VX!w
publicvoid setHasNextPage(boolean hasNextPage){ W
YW|P2*
this.hasNextPage = hasNextPage; o$.e^XL
} x\s,= n3z
pWE `x|J
/** 6O2=Ns;J6
* @return 7:NmCpgL!
* Returns the hasPrePage. Q6C-4ja
*/ 'z=:[#b
publicboolean getHasPrePage(){ W2-=U@
return hasPrePage; gLE7Edcp6V
}
\4ghYQ:
*pzq.#
/** iP3Z
* @param hasPrePage :`vP}I ^
* The hasPrePage to set. 6qo^2
*/ >cL{Ya}Rz
publicvoid setHasPrePage(boolean hasPrePage){ DZ
^1s~
this.hasPrePage = hasPrePage; s]27l3)B
} HjWq[[Nz
=wi*Nd7L
/** t j Vh^
* @return Returns the totalPage. VyG4(Xva
* Z<b"`ty.
*/ 4\
/*jA
publicint getTotalPage(){ G&eP5'B4i
return totalPage; t@?u
} SKY*.IW/Z
9=dkx^q
/** FZpKFsPx
* @param totalPage pL1s@KR
* The totalPage to set. Lb=W;9;
*/ RBGlzk
publicvoid setTotalPage(int totalPage){ -qV{WZ Hp
this.totalPage = totalPage; FdOFE.l
} X7*`
TB
aVW
} O';ew)tI
g+zJ?
o5Rz%k#h
^%oUmwP<$
b 1^n KB
上面的这个Page类对象只是一个完整的Page描述,接下来我写了一 VFD%h
}
MN;/*t
个PageUtil,负责对Page对象进行构造: cJ}QXuuUv
java代码: oholt/gb+0
CidM(
eo#^L}
/*Created on 2005-4-14*/ #$'"cfRxc
package org.flyware.util.page; j;P+_Hfe/E
w3*-^: ?j
import org.apache.commons.logging.Log; \X}8q
import org.apache.commons.logging.LogFactory; S9Y[4*//
YwT-T,oD
/** _EYB
8e
* @author Joa \Xg?Ug*9w
* y)J(K*x/$
*/ wod/&!)]A
publicclass PageUtil { =F%RLpNU4
2O""4_G
privatestaticfinal Log logger = LogFactory.getLog 3=4SGt5m
1|y$~R.H
(PageUtil.class); <ZPZk'53<f
+S {
/** "4}wnu6/
* Use the origin page to create a new page T.?k>Ak
* @param page (
76{2
* @param totalRecords -
HOnB=
* @return j^u[F"
*/ f$xhb3Qn
publicstatic Page createPage(Page page, int +/'<z
)q?$p9
totalRecords){ z)L}ECZh9
return createPage(page.getEveryPage(), -]"T^wib
2g`[u|
page.getCurrentPage(), totalRecords); E)'8U
} }B!cv{{
M?:\9DDd
/** r:l96^xs
* the basic page utils not including exception oFg'wAO.
}N3`gCy9eN
handler XdIah<F2
* @param everyPage JAb$M{t
* @param currentPage >2-F2E,
* @param totalRecords Z^6#4Q]YC
* @return page CUhV$A#oo
*/ *=nO
publicstatic Page createPage(int everyPage, int j]> uZalr
d?Y-;-|8Qh
currentPage, int totalRecords){ B%b_/F]e
everyPage = getEveryPage(everyPage); fNhT;Bux
currentPage = getCurrentPage(currentPage); ,?b78_,2
int beginIndex = getBeginIndex(everyPage, /mbCP>bcG
5j[#'3TSU
currentPage); Sb<\-O14"
int totalPage = getTotalPage(everyPage, _-a|VTM
%jKH?%Ih
totalRecords); u(vw|nj`
boolean hasNextPage = hasNextPage(currentPage, E[S' :Q
@W9H9PWv&
totalPage); i!~>\r\6\
boolean hasPrePage = hasPrePage(currentPage); 8 lS($@@{
{rGYRn,
returnnew Page(hasPrePage, hasNextPage, .ewZV9P)t
everyPage, totalPage, <?|6*2_=
currentPage, p{H0dj ^|
G,DOBA
beginIndex); "a(1s},
} S %+R#A1
t"YIq/08
privatestaticint getEveryPage(int everyPage){ d^aNR
Lv
return everyPage == 0 ? 10 : everyPage; 5~xeO@%I
} %Dyh:h
Mvof%I
privatestaticint getCurrentPage(int currentPage){ NWISS
return currentPage == 0 ? 1 : currentPage; [
-12]3
} [h", D5
^![{,o@"A
privatestaticint getBeginIndex(int everyPage, int &:8T$UV
GVObz?Z]SB
currentPage){ aJ-}
return(currentPage - 1) * everyPage; M.k|bh8
} wznn #j
=HPu{K$
privatestaticint getTotalPage(int everyPage, int a/e\vwHLv
;eR{tH /4
totalRecords){ (5(fd.m+_
int totalPage = 0; |BJqy/
x(6vh2#vD
if(totalRecords % everyPage == 0) 1~EO+
totalPage = totalRecords / everyPage; D=9}|b/
else V_M@g;<o
totalPage = totalRecords / everyPage + 1 ; SQIdJG^:
0^iJlR2
return totalPage; Ki 3_N*z
} (w2(qT&