实验一:熟悉java EE编程环境
实验内容: 创建学生数据库,建学生信息表(sno,sname,ssex,birthday,major)并输入几行数据。
参考本章案例,查询所有女生的信息。
实验步骤
- 1、创建maven项目,在pom.xml文件中配置依赖:MyBatis、mysql、Junit依赖
- 2、创建module
- 3、在resources下建db.properties、mybatis-config.xml文件。注意要在mybatis-config.xml文件中引入db.properties文件
- 4、创建学生信息表并输入数据
- 5、在src.main.java中建包com.pojo,包中创建学生表对应的POJO类,建包com.dao,包中定义接口StudentDAO,接口中定义查询女生的抽象方法。
- 6、在src.main.resources中建包com.dao,包中建StudentMapper.xml文件,在文件中绑定接口com.dao.StudentDAO,定义查询映射语句。
- 7、在mybatis-config.xml文件中注册StudentMapper.xml文件
- 8、在Test.java目录中创建测试类。
- 10、utils
- 10、运行测试方法。
1、创建maven项目,在pom.xml文件中配置依赖:MyBatis、mysql、Junit依赖
<?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>org.example</groupId>
<artifactId>IDEA</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>md1</module>
</modules>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
2、创建module
mysql.driver=com