기록해! 정리해!

비즈니스 컴포넌트 실습 II ( 어노테이션으로 수정 ) 본문

Spring

비즈니스 컴포넌트 실습 II ( 어노테이션으로 수정 )

zsuling 2022. 9. 22. 09:54

[ 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"
	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" />

</beans>
---------------------------------------------------------------------------------------------------------------------------

​

package com.springbook.biz.user.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.springbook.biz.user.UserDao;
import com.springbook.biz.user.UserService;
import com.springbook.biz.user.UserVo;

@Service("userService")
public class UserServiceImpl  implements UserService  {

	@Autowired
	private  UserDao userDao;
		
	@Override
	public UserVo getUser(UserVo vo) {
		// TODO Auto-generated method stub
		return userDao.getUser(vo);
	}

}
======================================================================

​

package com.springbook.biz.user.impl;

import java.sql.*;

import org.springframework.stereotype.Repository;

import com.springbook.biz.common.JDBCUtil;
import com.springbook.biz.user.UserDao;
import com.springbook.biz.user.UserVo;

@Repository
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;
	}

}​

'Spring' 카테고리의 다른 글

JoinPoint 메소드 사용하기  (0) 2022.09.22
AOP 사용하기  (0) 2022.09.22
비즈니스 컴포넌트 실습 II  (0) 2022.09.22
카카오 API 지도 (2) - 데이터 연동  (0) 2022.09.21
비즈니스 컴포넌트 실습 I (복습) - Board  (1) 2022.09.21
Comments