一時

41938 ワード

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

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.koreait</groupId>
  <artifactId>Day9</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>Day9 Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    	<dependency>
	    <groupId>mysql</groupId>
	    <artifactId>mysql-connector-java</artifactId>
	    <version>8.0.25</version>
	</dependency>
	<dependency>
	    <groupId>servlets.com</groupId>
	    <artifactId>cos</artifactId>
	    <version>05Nov2002</version>
	</dependency>
	<dependency>
	    <groupId>org.apache.taglibs</groupId>
	    <artifactId>taglibs-standard-impl</artifactId>
	    <version>1.2.5</version>
	    <scope>runtime</scope>
	</dependency>
	<dependency>
    <groupId>org.apache.taglibs</groupId>
    <artifactId>taglibs-standard-spec</artifactId>
    <version>1.2.5</version>
	</dependency>
	<dependency>
    <groupId>org.apache.taglibs</groupId>
    <artifactId>taglibs-standard-jstlel</artifactId>
    <version>1.2.5</version>
	</dependency>
	<dependency>
    <groupId>org.apache.taglibs</groupId>
    <artifactId>taglibs-standard-compat</artifactId>
    <version>1.2.5</version>
	</dependency>
	<dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis</artifactId>
    <version>3.5.9</version>
</dependency>
  </dependencies>

  <build>
    <finalName>Day9</finalName>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>
Dbconn.java
package com.koreait.db;

import java.sql.Connection;
import java.sql.DriverManager;

public class Dbconn {
	public static Connection getConnection() {
		Connection conn =null;
		try {
			String url = "jdbc:mysql://localhost:3306/aiclass";
			String uid = "root";
			String upw = "1234";
			
			Class.forName("com.mysql.cj.jdbc.Driver");
			conn = DriverManager.getConnection(url, uid, upw);
			
		}catch(Exception e) {
			e.printStackTrace();
		}
		return conn;
	}
}
config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
  PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
  <environments default="development">
    <environment id="development">
      <transactionManager type="JDBC"/>
      <dataSource type="POOLED">
        <property name="driver" value="com.mysql.cj.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost:3306/aiclass"/>
        <property name="username" value="root"/>
        <property name="password" value="1234"/>
      </dataSource>
    </environment>
  </environments>
  <mappers>
    <mapper resource="com/koreait/db/member.xml"/>
  </mappers>
</configuration>
member.xml
<?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="Member">
  <select id="login" parameterType="map" resultType="map">
    select mem_idx, mem_userid, mem_name from tb_member where mem_userid=#{mem_userid} and mem_userpw=#{mem_userpw}
  </select>
  
  <insert id="join" parameterType="map">
  	insert into tb_member(mem_userid, mem_userpw, mem_name, mem_hp, mem_email, mem_hobby, mem_ssn1, mem_ssn2, mem_zipcode, mem_address1, mem_address2, mem_address3) values (#{mem_userid}, #{mem_userpw}, #{mem_name}, #{mem_hp}, #{mem_email}, #{mem_hobby}, #{mem_ssn1}, #{mem_ssn2}, #{mem_zipcode}, #{mem_address1}, #{mem_address2}, #{mem_address3})
  </insert>
  
  <select id="info" parameterType="map" resultType="map">
  	select mem_idx, mem_userid, mem_userpw, mem_name, mem_hp, mem_email, mem_hobby, mem_ssn1, mem_ssn2, mem_zipcode, mem_address1, mem_address2, mem_address3 from tb_member where mem_idx=#{mem_idx}
  </select>
  
  <update id="edit" parameterType="map">
  	update tb_member set mem_name= #{mem_name}, mem_hp= #{mem_hp}, mem_email= #{mem_email}, mem_hobby= #{mem_hobby},mem_zipcode= #{mem_zipcode}, mem_address1= #{mem_address1}, mem_address2= #{mem_address2}, mem_address3= #{mem_address3} where mem_idx= #{mem_idx}
  </update>
</mapper>
pom.xml
<?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="Member">
  <select id="login" parameterType="map" resultType="map">
    select mem_idx, mem_userid, mem_name from tb_member where mem_userid=#{mem_userid} and mem_userpw=#{mem_userpw}
  </select>
  
  <insert id="join" parameterType="map">
  	insert into tb_member(mem_userid, mem_userpw, mem_name, mem_hp, mem_email, mem_hobby, mem_ssn1, mem_ssn2, mem_zipcode, mem_address1, mem_address2, mem_address3) values (#{mem_userid}, #{mem_userpw}, #{mem_name}, #{mem_hp}, #{mem_email}, #{mem_hobby}, #{mem_ssn1}, #{mem_ssn2}, #{mem_zipcode}, #{mem_address1}, #{mem_address2}, #{mem_address3})
  </insert>
  
  <select id="info" parameterType="map" resultType="map">
  	select mem_idx, mem_userid, mem_userpw, mem_name, mem_hp, mem_email, mem_hobby, mem_ssn1, mem_ssn2, mem_zipcode, mem_address1, mem_address2, mem_address3 from tb_member where mem_idx=#{mem_idx}
  </select>
  
  <update id="edit" parameterType="map">
  	update tb_member set mem_name= #{mem_name}, mem_hp= #{mem_hp}, mem_email= #{mem_email}, mem_hobby= #{mem_hobby},mem_zipcode= #{mem_zipcode}, mem_address1= #{mem_address1}, mem_address2= #{mem_address2}, mem_address3= #{mem_address3} where mem_idx= #{mem_idx}
  </update>
</mapper>