maven+springmvc+mybatis问题

2025-04-24 15:17:43
推荐回答(3个)
回答1:

spring jdbc.xml 配置:


xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"
default-autowire="byName" default-lazy-init="false">


class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

/WEB-INF/configs/sqlServer.properties




class="org.springframework.jdbc.datasource.DriverManagerDataSource">

${jdbc.driver}


${jdbc.url}


${jdbc.username}


${jdbc.password}



class="org.mybatis.spring.SqlSessionFactoryBean">
value="classpath:mybatis_config.xml" />




class="org.mybatis.spring.SqlSessionTemplate">









-----------------------------------------------------------------------------------------
数据源文件内容:

sqlServer.properties

.properties格式

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/数据库名
jdbc.username=mysql用户名
jdbc.password=mysql密码

配置这两个文件,在dao中
private SqlSession sqlSession;
get/set方法

在方法中 用 sqlSession就可以点出mybatis的方法 selectList、selectOne、、、

--------------------------------------------------------------------------------------------
mybatis xml配置文件:







还有2个总的配置文件,需要把spring和mybatis的xml文件引入
这几个文件配置好了就可以在