Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- 데이터베이스
- Oracle
- 리눅스
- Java
- 네트워크
- cisco packet
- 버추얼머신
- php
- autoset
- ciscopacket
- jsp연결
- sql
- ospf
- 정처기필기
- 오라클
- VLAN
- 네트워크관리사
- 라우터
- 이것이 자바다
- 자바
- html
- jsp
- NCS
- 원형그래프
- rinux
- 정보처리기사
- 참조타입
- w3school
- Cisco
- javaee
Archives
- Today
- Total
기록해! 정리해!
비즈니스 컴포넌트 실습 II 본문
package com.springbook.biz.user;
import lombok.Data;
@Data
public class UserVo {
private String id;
private String password;
private String name;
private String role;
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd">
<context:component-scan base-package="com.springbook.biz" />
<!--
1. id="userService" : UserServiceClient 의 container.getBean("userService")에서 사용
2. property name="userDao" 는 private UserDao userDao 와 일치
3. ref="userDAO" 는 밑에 있는 빈의 이름을 참조한다. <bean id="userDAO" ...
-->
<bean id="userService" class="com.springbook.biz.user.impl.UserServiceImpl">
<property name="userDao" ref="userDAO" ></property>
</bean>
<bean id="userDAO" class="com.springbook.biz.user.impl.UserDaoImpl" />
</beans>
package com.springbook.biz.user;
public interface UserDao {
public UserVo getUser(UserVo vo);
}
--------------------------------------------------------------------------
package com.springbook.biz.user;
public interface UserService {
public UserVo getUser(UserVo vo);
}
========================================================================
package com.springbook.biz.user.impl;
import java.sql.*;
import com.springbook.biz.common.JDBCUtil;
import com.springbook.biz.user.UserDao;
import com.springbook.biz.user.UserVo;
public class UserDaoImpl implements UserDao {
private JDBCUtil dbConn =null;
private Connection conn = null;
private PreparedStatement pstmt=null;
private ResultSet rs=null;
UserDaoImpl(){
dbConn=JDBCUtil.getInstance();
}
@Override
public UserVo getUser(UserVo vo) {
System.out.println(" ===> getUser(UserVo vo) 기능처리 " );
UserVo user = null;
try {
conn = dbConn.getConnection();
String SQL="select * from users where id=? and password=?";
pstmt=conn.prepareStatement(SQL);
pstmt.setString(1, vo.getId());
pstmt.setString(2, vo.getPassword());
rs=pstmt.executeQuery();
rs.next();
user=new UserVo();
user.setId(rs.getString("id"));
user.setName(rs.getString("name"));
user.setPassword(rs.getString("password"));
user.setRole(rs.getString("role"));
}catch(Exception e) {
e.printStackTrace();
}
return user;
}
}
======================================================================
package com.springbook.biz.user.impl;
import com.springbook.biz.user.UserDao;
import com.springbook.biz.user.UserService;
import com.springbook.biz.user.UserVo;
public class UserServiceImpl implements UserService {
private UserDao userDao;
public void setUserDao(UserDao userDao) {
this.userDao = userDao;
}
@Override
public UserVo getUser(UserVo vo) {
// TODO Auto-generated method stub
return userDao.getUser(vo);
}
}
----------------------------------------------------------------------------------------------------------------------
package com.springbook.biz.user;
import java.util.List;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
public class UserServiceClient {
public static void main(String[] args) {
AbstractApplicationContext container=
new GenericXmlApplicationContext("applicationContext.xml");
UserService service =(UserService) container.getBean("userService");
UserVo vo =new UserVo();
vo.setId("TEST");
vo.setPassword("TEST123");
UserVo user=service.getUser(vo);
if(user != null) {
System.out.println(user.getName() + "님 환영합니다.");
}else {
System.out.println(" 로그인 실패 !!! ");
}
container.close();
}
}
'Spring' 카테고리의 다른 글
AOP 사용하기 (0) | 2022.09.22 |
---|---|
비즈니스 컴포넌트 실습 II ( 어노테이션으로 수정 ) (0) | 2022.09.22 |
카카오 API 지도 (2) - 데이터 연동 (0) | 2022.09.21 |
비즈니스 컴포넌트 실습 I (복습) - Board (1) | 2022.09.21 |
비즈니스 컴포넌트 실습 I (복습) - 데이터베이스 드라이버 , JDBCUtil, applicationContext.xml (1) | 2022.09.21 |
Comments