Springmvc+Mybatis+Velocity实现小demo(Maven项目)

本文介绍了如何使用Springmvc、Mybatis和Velocity搭建一个小的Maven项目。首先配置pom文件,添加所需依赖,接着配置spring的applicationContext.xml,包括springmvc、velocity和mybatis的配置。接着创建DAO接口和mapping.xml文件,Service接口及ServiceImpl,然后编写Controller。Velocity作为展示层,用于显示从数据库中查询的数据。文中还提到可以通过在DAO接口上添加注解来替代mapping.xml文件,简化配置。

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

  Velocity只是充当一个展示层,和JSP的功能类似,利用mybatis从数据库中取出数据,然后进行数据处理,最后通过Velocity在页面上展示出来。
  环境搭建主要分为几个过程,第一步是配置pom文件依赖,第二步是配置spring配置文件:applicationContext.xml,第三步就是开始写DAO接口和对应的mapping.xml文件,然后是Service接口和ServiceImpl类,最后就是写controller。需要注意的是里面用到一些spring的autowire,这个关系要缕清。
目录
目录

1.pom文件依赖:

1.添加Velocity依赖:

       <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity-tools</artifactId>
            <version>2.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity</artifactId>
            <version>1.7</version>
        </dependency>

注意要是apache下的velocity,而不是以下这种

<dependency>
    <groupId>velocity</groupId>
    <artifactId>velocity</artifactId>
    <version>1.5</version>
    <type>pom</type>
</dependency>

2.添加springmvc依赖:

    <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>4.2.5.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.2.5.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>4.2.5.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.2.5.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>4.2.5.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>4.2.5.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.2.5.RELEASE</version>
        </dependency>

3.添加mybatis,c3p0数据源等依赖

<dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.18</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/c3p0/c3p0 -->
        <dependency>
            <groupId>c3p0</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.1.2</version>
        </
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值