stripes + spring mvc + mybatis + mysql运行纪实

本文档记录了将mybatis的jpetstore示例从hsqldb迁移到mysql的过程,以及如何结合spring mvc进行操作。主要内容包括在Mysql.properties中配置数据库连接信息,更新spring配置文件以加载该属性文件,确保spring mvc的web.xml中包含stripes的context配置,以便stripes能注入spring bean。同时提到了在pom.xml中添加mybatis-spring依赖,以及运行时需要的mysql驱动jar包。
摘要由CSDN通过智能技术生成

基于mybatis提供的jpetstore6.0.1改造,主要是把数据库从hsqldb改为mysql,并且结合spring mvc使用。

有几个要点:

1:Mysql

在src/main/resources下创建Mysql.properties文件,内容如下:


jdbc.driverClassName=com.mysql.jdbc.Driver  

jdbc.url=jdbc:mysql://localhost:3306/student_manager?user=yourusername&password=yourpassword&useUnicode=true&characterEncoding=UTF-8


修改spring的配置文件:

    <context:property-placeholder location="classpath:Mysql.properties" />
    <beans:bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <beans:property name="driverClassName" value="${jdbc.driverClassName}" />
        <beans:property name="url" value="${jdbc.url}" />
    </beans:bean>

其它部分按照提供的例子文档照做就行了


2:spring mvc结合stripes使用:

关键是要在spring mvc的web.xml加入

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/appServlet/stripes-context.xml</param-value>
    </context-param>

spring mvc提供的context只对mvc有效,而stripes的配置是写在外面的,需要有对应的context配置文件,没有这几行,stripes将无法注入springbean


3:其它注意点:

pom.xml文件加入依赖:

        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.0.1</version>
        </dependency>

运行时加入mysql的jar包

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值