Web
index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
</body>
</html>
jdbc.properties
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:端口号/数据库
jdbc.username=root
jdbc.password=root
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee
https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"
version="5.0"
metadata-complete="true">
</web-app>
mybatis
mybatis-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>
<!--开启mybatis对标准日志的实现。-->
<!--<settings>-->
<!--<setting name="logImpl" value="STDOUT_LOGGING"/>-->
<!--<setting name="logImpl" value="SLF4J"/>-->
<!--</settings>-->
<environments default="development">
<environment id="development">
<!--<transactionManager type="MANAGED"/>-->
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:端口号/数据库"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</dataSource>
</environment>
</environments>
<mappers>
<!--执行XxxMapper.xml文件的路径-->
<!--resource属性自动会从类的根路径下开始查找资源。-->
<mapper resource=""/>
</mappers>
</configuration>
_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="">
</mapper>
spring
spring-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
</beans>
spring集成mybatis
<?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"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<!--1、组件扫描-->
<context:component-scan base-package="填空"/>
<!--2、引入JDBC属性文件-->
<context:property-placeholder location="jdbc.properties"/>
<!--3、数据源-->
<!--此处对应的Bean不用我们写,阿里巴巴写好了,我们直接用就行-->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="url" value="${jdbc.url}"/>
<property name="driverClassName" value="${jdbc.driver}"/>
</bean>
<!--4、SqlSessionFactoryBean配置-->
<bean class="org.mybatis.spring.SqlSessionFactoryBean">
<!--注入mybatis核心配置文件路径-->
<property name="configLocation" value="填空"/>
<!--数据源-->
<property name="dataSource" ref="dataSource"/>
<!--指定别名-->
<property name="typeAliasesPackage" value="填空"/>
</bean>
<!--5、Mapper扫描mapper包,生成代理类-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="填空"/>
</bean>
<!--6、事务管理器-->
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!--开启事务-->
<tx:annotation-driven transaction-manager="txManager"/>
</beans>
springboot
application.properties
# 配置前缀prefix和后缀.jsp
spring.mvc.view.prefix=/
spring.mvc.view.suffix=.jsp
# 修改内嵌服务器端口号,默认8080,可以不修改
server.port=8989
# 启用jsp页面热部署
server.servlet.jsp.init-parameters.development=true
#数据源配置
#连接池
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
#驱动类
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/dd?CharacterEncoding=UFT-8
spring.datasource.username=root
spring.datasource.password=
#mybatis配置
#mapper文件位置
mybatis.mapper-locations=classpath:
#这个包里的类会自动成为别名
mybatis.type-aliases-package=
标签:jdbc,--,spring,jsp,datasource,mybatis,模板
From: https://www.cnblogs.com/nanfengjinhe/p/17138191.html