data Source

tenuousdrunkshipInternet και Εφαρμογές Web

12 Νοε 2013 (πριν από 3 χρόνια και 11 μήνες)

110 εμφανίσεις


write.jsp

http://locahost/~
~
~/write.action


<
form

action
=
"add.action"

method
=
"post"
>

<
table

border
=
"1"

width
=
"600"
>


<
tr
>


<
th
>
번호
</
th
>


<
td
><
input

type
=
"text"

name
=
"vo.deptno"
>

</
td
>

</
tr
>

<
tr
>


<
th
>
학과

이름
</
th
>


<
td
><
input

type
=
"text"

name
=
"vo.dname"
>

</
td
>

</
tr
>

<
tr
>


<
th
>
단과대

번호
</
th
>


<
td
><
input

type
=
"text"

name
=
"vo.colleage"
>

</
td
>

</
tr
>

</
table
>

</
form
>

<!
--

dataSource
생성

context.xml
내용을

적어줌
--
>

<
bean

id
=
"dataSource"


class
=
"org.springframework.jdbc.datasource.DriverManagerDataSource"
>

<
property

name
=
"driverClassName"

value
=
"oracle.jdbc.OracleDriver"
></
property
>

<
property

name
=
"url"

value
=
"jdbc:oracle:thin:@localhost:1521:xe"
></
property
>

<
property

name
=
"username"

value
=
"hr"
></
property
>

<
property

name
=
"password"

value
=
"1234"
></
property
>


</
bean
>

<!
--

sqlMapClient
생성

--
>

<
bean

id
=
"sqlMapClient"


class
=
"org.springframework.orm.ibatis.SqlMapClientFactoryBean"
>

<
property

name
=
"configLocation"

value
=
"/WEB
-
INF/SqlMapConfig.xml"
></
property
>

<
property

name
=
"dataSource"

ref
=
"dataSource"
></
property
>

</
bean
>


<!
--

daoImp
생성

--
>

<
bean

id
=
"daoImp"

class
=
"dao.DaoImp"
>

<
property

name
=
"sqlMapClient"

ref
=
"sqlMapClient"
></
property
>



</
bean
>

<!
--

ServiceImp
생성

--
>

<
bean

id
=
"serviceImp"

class
=
"service.ServiceImp"
>

<
property

name
=
"dao"

ref
=
"daoImp"
></
property
>

</
bean
>

<!
--

addAction
생성

--
>

<
bean

id
=
"addAction"

class
=
"action.AddAction"

scope
=
"prototype"
>

<
property

name
=
"service"

ref
=
"serviceImp"
></
property
>

</
bean
>

</
beans
>


struts.xml

<
struts
>

<!
--

객체의

생성을
spring


위임한다
..struts.property


내용

--
>

<
constant

name
=
"struts.objectFactory"

value
=
"spring"
></
constant
>



<
package

name
=
"default"

namespace
=
"/"

extends
=
"struts
-
default"
>

<
action

name
=
"write"
>



<
result
>
write.jsp
</
result
>

</
action
>



<
action

name
=
"add"

class
=
"AddAction"
>

<
result
>
/addComplete.jsp
</
result
>

</
action
>

sqlMapConfig.xml

<
sqlMapConfig
>

<
sqlMap

resource
=
"dao/dept.xml"
/>

</
sqlMapConfig
>

public

class

AddAction
{


private

DeptVO
vo
;


Service
service
;

service




setter


public

String execute()
throws

Exception {


//
비즈니스

로직처리를

위한

서비스

호출


service
.addDeptInfo(
vo
);


return

"success"
;

}


vo


getter & setter

}

public

class

ServiceImp

implements

Service{



private

Dao
dao
;


dao


setter



@Override


public

void

addDeptInfo
(DeptVO vo)
{



//DB
에서

해당

학과가

이미

존재하는지

확인하기



DeptVO dbtVO =
dao
.info(vo.getDeptno());





if

(dbtVO ==
null
) {



//
존재하지

않으면

DB


추가하기




dao
.insert(vo);

public

class

DaoImp
extends

SqlMapClientDaoSupport
implements

Dao{



@Override


public

void

insert(DeptVO vo) {


getSqlMapClientTemplate().insert(
"add"
, vo);

ibatis xml
파일

dept.xml

<
sqlMap

namespace
=
"dept"
>


<
insert

id
=
"add"

parameterClass
=
"vo.DeptVO"
>



insert into department



values(#deptno#,#dname#,#college#,#loc#)


</
insert
>

DB


</
sqlMap
>

package

vo;

public

class

DeptVO {




private

i n t

d e p t n o
;


p r i v a t e

St r i n g
d n a me
;


p r i v a t e

i n t

c o l l e g e
;


p r i v a t e

St r i n g
l o c
;

g e t t e r / s e t t e r