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> |
| |
| |
| |
| |
| |
| |
| |
| <environments default="development"> |
| <environment id="development"> |
| |
| <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> |
| |
| |
| <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"> |
| |
| |
| <context:component-scan base-package="填空"/> |
| |
| |
| <context:property-placeholder location="jdbc.properties"/> |
| |
| |
| |
| <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> |
| |
| |
| <bean class="org.mybatis.spring.SqlSessionFactoryBean"> |
| |
| <property name="configLocation" value="填空"/> |
| |
| <property name="dataSource" ref="dataSource"/> |
| |
| <property name="typeAliasesPackage" value="填空"/> |
| </bean> |
| |
| <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> |
| <property name="basePackage" value="填空"/> |
| </bean> |
| |
| <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= |
| |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?