<?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.springframe

<context:component-scan base-package="dao"></context:component-scan>

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">

<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>

<property name="url" value="jdbc:mysql://localhost/데이터베이스명"></property>

<property name="username" value="유저네임"></property>

<property name="password" value="비밀번호"></property>

</bean>

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">

<property name="dataSource" ref="dataSource"></property>

<property name="typeAliasesPackage" value="model"></property>

<property name="mapperLocations" value="classpath*:dao/mapper/**/*.xml"></property>

</bean>

<bean id="studentDao" class="org.mybatis.spring.mapper.MapperFactoryBean">

<property name="mapperInterface" value="dao.IStudentDao"></property>

<property name="sqlSessionFactory" ref="sqlSessionFactory"></property>

</bean>

</beans> 


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE mapper

PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"

"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="dao.IStudentDao">

    <insert id="insertStudent" parameterType="student">

        insert into student values( #{id}, #{name}, #{grade} )

    </insert>

    <update id="updateStudent" parameterType="student">

        update student set name=#{name}, grade=#{grade} where id=#{id}

    </update>

    <delete id="deleteStudent" parameterType="int">

        delete from student where id=#{id}

    </delete>

    <select id="selectAll" resultType="student">

        select * from student

    </select>

    <select id="selectOne" resultType="student" parameterType="int">

        select * from student where id=#{id}

    </select>

</mapper> 


package dao;

import java.util.List;

import model.Student;

public interface IStudentDao {

public List<Student> selectAll();

public Student selectOne(int id);

public void insertStudent(Student stu);

public void updateStudent(Student stu);

public void deleteStudent(int id);

}



' IOT 기반 응용 SW과정 > Review' 카테고리의 다른 글

jsp 마우스 액션  (0) 2016.07.07
CSS 반응형 웹 디자인  (0) 2016.06.21
三周整理考试  (0) 2016.04.04
套装  (0) 2016.04.04
约分  (0) 2016.03.30

+ Recent posts