搭建spring MVC项目

 首先,是要放入spring mvc所需要的包:


如果不用json功能就不需要json和gson包,还有数据库驱动包,我这里是用的postgresql数据库,其他数据库需替换掉这个包

然后就是配置文件:

先是web.xml中需要加入以下内容:

<servlet>
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                classpath:applicationContext.xml
            </param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

然后是spring的配置文件applicationContext.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"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">

    
    <import resource="dao.xml"/>
    <import resource="service.xml"/>
    
    <!-- AOP注解 -->
    <aop:aspectj-autoproxy />
    <!-- 自动扫描注解  加入所需扫描的包名-->
    <context:component-scan base-package="**" />
    
    <bean id="viewNameTranslator"
            class="org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator"/>
   <!-- 开启注解功能-->

<mvc:annotation-driven/>
    
    <!-- 静态资源使用默认servlet处理 -->
    <mvc:default-servlet-handler/>

    <!--访问路径映射-->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!-- 映射前缀 如请求一个controller 且返回的结果页面为demo.jsp,该页面所放路径为:a/b/,则只需在这里配a/b/,controller中返回页面就不需要加路径-->
        <property name="prefix" value="**"/>

      <!-- 映射访问后缀 如:请求一个jsp在spring 的controller中就不需要写.jsp 直接写名字即可访问到-->
        <property name="suffix" value=".jsp"/>
        <property name="order" value="1"/>
    </bean>
   
</beans>

dao.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" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">

    <!-- 导入jdbc.properties文件 数据库连接所有的数据 -->
    <context:property-placeholder
        location="classpath:/com/unitedus/redant/salesorder/report/config/jdbc.properties" />
    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${jdbc.driver}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.user}" />
        <property name="password" value="${jdbc.password}" />
    </bean>

    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"
        p:dataSource-ref="dataSource" />
</beans>

service.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" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">

    <!-- spring对jdbc事物管理器 -->
    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
        p:dataSource-ref="dataSource" />
    <!-- 自动扫描事物注解 -->
    <tx:annotation-driven />

</beans>

这样配置就差不多了,然后就可以写业务逻辑代码,和显示界面了。

未完待续。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/419433.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

换行的css属性

//正常换行word-break:keep-all;word-wrap:normal;//下面这行是自动换行word-break:break-all;word-wrap:break-word;word-wrap:normal | break-word; (内容换行)normal:默认的属性值.&#xff08;允许内容顶开指定的容器边界&#xff09;.break-word:内容将在边界内换行(不截断…

基于jquery.ajax的进一步封装

这是最近写项目用到的一个小功能&#xff0c;给大家分享下&#xff0c;希望对大家有帮助。 直接上代码&#xff1a; % page language"java" contentType"text/html; charsetUTF-8" pageEncoding"UTF-8"%> <!DOCTYPE html PUBLIC &quo…

Serena Dimensions 介绍

Serena Dimensions是配置管理工具&#xff0c;基于进程的软件更改和配置管理解决方案。 官方网址&#xff1a;http://www.serena.com/index.php/en/products/application-development/dimensions-cm/overview/ eclipse与Dimensions的集成 转载于:https://www.cnblogs.com/seabi…

pigeon服务

点击打开链接

使用jquery图表插件jqplot之折线图

首先一个简单的折线图&#xff1a; 直接上代码&#xff1a; <html> <head> <meta http-equiv"Content-Type" content"text/html; charsetutf-8"> <script type"text/javascript" src"js/jquery.min.js"></…

JQ调用后台方法

首先&#xff0c;先在页面上创建一个asp按钮&#xff0c;添加点击事件&#xff0c;把要在前台调用的后台方法写在这个按钮的点击事件中&#xff1a; <span style"display:none;"><asp:Button ID"btnSelectCategory" runat"server" type…

如何理解HTTP协议的 “无连接,无状态” 特点?

转载自&#xff1a;点击打开链接http://blog.csdn.net/tennysonsky/article/details/44562435 HTTP 是一个属于应用层的面向对象的协议&#xff0c;HTTP 协议一共有五大特点&#xff1a;1、支持客户/服务器模式&#xff1b;2、简单快速&#xff1b;3、灵活&#xff1b;4、无连接…

jqgrid使用

1.准备工作 首先&#xff0c;要引入基本的jquery文件&#xff0c;然后是下载jqgrid插件&#xff0c;我这里引入的有jquery.jqGrid.src.js,grid.setcolumns.js,grid.locale-en.js,jqgrid.css,ui.multiselect.css. 2.创建用来承载jqgrid的标签 <table id"gridTable"…

“睡服”面试官系列第一篇之let和const命令(建议收藏学习)

目录 1let命令 1.1基本用法 1.2for循环小案例 1.3不存在变量提升 1.4暂时性死区 1.5不允许重复声明 2块级作用域 2.1为什么需要块级作用域&#xff1f; 2.2ES6 的块级作用域 2.3块级作用域和函数声明 3const 3.1本质 4顶层对象的属性 5global对象 6总结 1let命令…

Java命名规范和代码风格

Java命名规范和代码风格 基本命名规范 包命名 包名按照域名的范围从大到小逐步列出&#xff0c;恰好和Internet上的域名命名规则相反。 由一组以“.”连接的标识符构成&#xff0c;通常第一个标识符为符合网络域名的两个或者三个英文小写字母。 例:cn.edu.xupt.JavaTest 类&…

jqgrid多选和禁止某行记录选择

在对一些特殊数据&#xff0c;我们总是要做一些防范手段。 在jqgrid中添加了多选属性后&#xff0c;默认是每一行都能自由选择。有时候&#xff0c;一些数据不满足某些情况是不让选中处理的。 怎么实现&#xff1f; 直接上代码&#xff1a; onSelectAll:function(rowid, status…

SYN 攻击原理以及防范技术

转载自&#xff1a;http://netsecurity.51cto.com/art/200608/30428.htm 据统计&#xff0c;在所有黑客攻击事件中&#xff0c;SYN攻击是最常见又最容易被利用的一种攻击手法。相信很多人还记得2000年YAHOO网站遭受的攻击事例&#xff0c;当时黑客利用的就是简单而有效的SYN攻击…

使用adb调试android

原来以为真机调试android应用只能用数据线连接手机&#xff0c;后来在公司经前辈推荐&#xff0c;发现adb wireless这个工具不错&#xff0c;只需要将该apk安装到设备上&#xff0c;然后和电脑连同一无线网&#xff0c;打开该工具&#xff0c;看到为设备分配了Ip地址就代表可以…

总结css中单位px和em,rem的区别

国内的设计师大都喜欢用px&#xff0c;而国外的网站大都喜欢用em和rem&#xff0c;那么三者有什么区别&#xff0c;又各自有什么优劣呢&#xff1f; PX特点 1. IE无法调整那些使用px作为单位的字体大小&#xff1b; 2. 国外的大部分网站能够调整的原因在于其使用了em或rem作为字…

计算机网络协议包头赏析-TCP

转载自博客地址为http://roclinux.cn。 仍然先把TCP报文段的格式放在这里&#xff0c;然后我们看图说话&#xff1a; TCP报文段也分为首部和数据两部分&#xff0c;首部默认情况下一般是20字节长度&#xff0c;但在一些需求情况下&#xff0c;会使用“可选字段”&#xff0c;这…

使用adb查看数据库的一些命令

1.需要配置adb环境变量。 2.打开命令窗口&#xff0c;输入&#xff1a;adb shell 3.进入该数据库所在目录&#xff1a;cd data/,,,, 4.然后打开该数据库&#xff1a;sqlite3 数据库名称.db 5.现在可以操作该数据库中的表。 a.使用.tables命令可以查看该数据库下的所有表。…

String 类的重要方法与字段

Length():获取字串长度 《空格也算他的长度》得到一个字串的长度的实现&#xff1a;zichuan.length() charAt():获取指定位置的字符实现方法&#xff1a;zichuan.charAt() getChars():获取从指定位置起的子串复制到字符数组中&#xff08;它有四个参数&#xff0c;在示例中有介…

Android使用webview控件加载本地html,通过Js与后台Java实现数据的传递

1.在布局文件中加WebView控件&#xff0c;在java中获取WebView对象。 2.加载本地html文件。 webView.loadUrl("file:///android_asset/android.html"); 3.开启js功能。 webView.getSettings().setJavaScriptEnabled(true); 4.添加一个js交互接口&#xff…

TreeMap的讲解

本文转载自&#xff1a;http://blog.csdn.net/chenssy/article/details/26668941点击打开链接 原文出自&#xff1a;http://cmsblogs.com/?p1013。尊重作者的成果&#xff0c;转载请注明出处&#xff01; 个人站点&#xff1a;http://cmsblogs.com ----------------------…