好好编程-物流项目05【Dao层整合】,华为外包java面试

本文介绍了在Spring和Mybatis集成项目中,如何将配置文件分别放在src/main/resource的mybatis和spring文件夹下,以及为何建议将配置文件放在logistics-manager-web工程中,以便于war包的整合。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2.添加配置文件


spring和mybatis的整合我们有两个配置文件要添加,分别是spring的配置文件和mybatis的配置文件。但是这两个配置文件放在哪儿呢?因为logistics-manager-dao和logistics-manager-service都是jar工程,最终会被打成jar包,配置文件也会被打包在jar包里面,我们调用起来比较麻烦,建议放到logistics-manager-web工程中,因为logistics-manager-web是war工程,logistics-manager聚合工程最终会打包成一个war包,war包整合了聚合工程的所有内容。因此更适合进行框架整合。

在这里插入图片描述

2.1mybatis的配置文件

在src/main/resource目录下新建一个mybatis文件夹,然后在该文件夹下新建一个Mybatis的配置文件SqlMapConfig.xml,如下图所示

在这里插入图片描述

schema代码

<?xml version="1.0" encoding="UTF-8"?>

2.2Spring的配置文件

在src/main/resource目录下新建一个spring文件夹,然后在该文件夹下新建一个Mybatis的配置文件applicationContext-dao.xml,如下图所示

在这里插入图片描述

我们在applicationContext-dao.xml文件当中配置数据库连接池、SqlSessionFactory(Mybatis的连接工厂)、Mybatis映射文件的包扫描器,配置内容如下

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns=“http://www.springframework.org/schema/beans”

xmlns:context=“http://www.springframework.org/schema/context” xmlns:p=“http://www.springframework.org/schema/p”

xmlns:aop=“http://www.springframework.org/schema/aop” xmlns:tx=“http://www.springframework.org/schema/tx”

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-4.2.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd

http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd

http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">

<context:property-placeholder location=“classpath:properties/db.properties” />

<bean id=“dataSource” class=“com.alibaba.druid.pool.DruidDataSource”

destroy-method=“close”>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值