[筆記] C++ 單元測試 (boost.test)
阿新 • • 發佈:2022-03-10
1、匯入jar包
<!--mybatis連線mysql--> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.2</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.4.0</version> </dependency>
2、在application.yml配置資料來源(此處是mysql)和 mybatis
#連線資料庫 spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&serverTimezone=UTC hikari: username: root password: 123456 mybatis: #配置mapper對映檔案 classpath代表resources下 mapper-locations: classpath:mapper/*.xml #開啟sql執行日誌 configuration: log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #所有pojo類所在包路徑 type-aliases-package: com.wwc.demo.pojo
3、建立實體類物件
public class UserInfo { private int id; private String userName; private String userPwd; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getUserPwd() { return userPwd; } public void setUserPwd(String userPwd) { this.userPwd = userPwd; } public UserInfo(int id, String userName, String userPwd) { this.id = id; this.userName = userName; this.userPwd = userPwd; } public UserInfo() { } @Override public String toString() { return "UserInfo{" + "id=" + id + ", userName='" + userName + '\'' + ", userPwd='" + userPwd + '\'' + '}'; } }
4、建立dao層使用註解@Mapper
@Mapper public interface UserInfoDao { List<UserInfo> getList(); }
5、建立mybatis對映檔案mapper.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="com.wwc.demo.dao.UserInfoDao"> <!-- 結果集與實體類對映--> <resultMap id="userInfoMap" type="com.wwc.demo.pojo.UserInfo"> <id property="id" column="id" javaType="int" jdbcType="INTEGER"></id> <result property="userName" column="user_name" javaType="String" jdbcType="VARCHAR"></result> <result property="userPwd" column="user_pwd" javaType="String" jdbcType="VARCHAR"></result> </resultMap> <select id="getList" resultMap="userInfoMap"> select * from user_info </select> </mapper>
6、資料庫建立對應的表
7、啟動測試成功