mybatis+mysql8.0.7配置文件mybatis_config.xml

项目的pom.xml配置文件

<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.0modelVersion>
 
	<groupId>com.jCuckoogroupId>
	<artifactId>MybatisTestartifactId>
	<version>0.0.1-SNAPSHOTversion>
	<packaging>jarpackaging>
 
	<name>MybatisTestname>
	<url>http://maven.apache.orgurl>
 
	<properties>
		<project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
	properties>
 
	<dependencies>
		<dependency>
			<groupId>junitgroupId>
			<artifactId>junitartifactId>
			<version>3.8.1version>
			<scope>testscope>
		dependency>
		
		<dependency>
			<groupId>org.mybatisgroupId>
			<artifactId>mybatisartifactId>
			<version>3.4.5version>
		dependency>
		
		<dependency>
			<groupId>mysqlgroupId>
			<artifactId>mysql-connector-javaartifactId>
			<version>8.0.7-dmrversion>
		dependency>
		
		<dependency>
			<groupId>log4jgroupId>
			<artifactId>log4jartifactId>
			<version>1.2.17version>
		dependency>
 
	dependencies>
project>

mybatis_config.xml文件配置方式一:



<configuration>
	<typeAliases>
		
		<typeAlias alias="role" type="com.jCuckoo.chapter02.pojo.Role"/>
		
		
	typeAliases>
	<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/mybatis?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT" />
				<property name="username" value="root" />
				<property name="password" value="" />
			dataSource>
		environment>
	environments>
	<mappers>
		
		<mapper resource="com\jCuckoo\chapter02\mapper\RoleMapper.xml" />
		
		
		
		
	mappers>
configuration> 

mybatis_config.xml文件配置方式二:



<configuration>
	<properties>
		<property name="driver" value="com.mysql.cj.jdbc.Driver" />
		<property name="url" value="jdbc:mysql://localhost:3306/mybatis?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT" />
		<property name="username" value="root" />
		<property name="password" value="" />
	properties>
	<typeAliases>
		<typeAlias alias="role" type="com.jCuckoo.chapter02.pojo.Role" />
	typeAliases>
	<environments default="development">
		<environment id="development">
			<transactionManager type="JDBC" />
			<dataSource type="POOLED">
				<property name="driver" value="${driver}" />
				<property name="url" value="${url}" />
				<property name="username" value="${username}" />
				<property name="password" value="${password}" />
			dataSource>
		environment>
	environments>
	<mappers>
		<mapper resource="com\jCuckoo\chapter02\mapper\RoleMapper.xml" />
	mappers>
configuration> 

方式一和方式二中的URL被CSDN自动转换,应该是以下格式:

<property name="url" value="jdbc:mysql://localhost:3306/mybatis?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT" />

mybatis_config.xml文件配置方式三:

1)jdbc.properties配置数据库连接信息

driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/mybatis?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT
username=root
password=

2)mybatis_config.xml配置文件



<configuration>
	<properties resource="jdbc.properties">properties>
	<typeAliases>
		<typeAlias alias="role" type="com.jCuckoo.chapter02.pojo.Role" />
	typeAliases>
	<environments default="development">
		<environment id="development">
			<transactionManager type="JDBC" />
			<dataSource type="POOLED">
				<property name="driver" value="${driver}" />
				<property name="url" value="${url}" />
				<property name="username" value="${username}" />
				<property name="password" value="${password}" />
			dataSource>
		environment>
	environments>
	<mappers>
		<mapper resource="com\jCuckoo\chapter02\mapper\RoleMapper.xml" />
	mappers>
configuration> 

转载地址:https://blog.csdn.net/guoquanyou/article/details/78039985

你可能感兴趣的:(ssm,mysql)