一、创建一个maven项目
 
1.1建立一个module作为web项目
 
File-》New-》project
选择maven,默认jdk,下面的列表什么都不选,next-》输入项目名,和配置模块的坐标,可以在其他自己的module里集成这个模块。
打开pom.xml 粘贴:
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.5</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>2.0.6</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>5.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.4</version>
</dependency>
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
</dependency>
</dependencies>
 
1.2.创建webapp文件夹
ctrl+shift+alt+s 或者右键自己的项目找到F4标记的那个【Open Module Setting】点击它。
左侧找到Modules 点击顶上的+按钮,找到【web】打开它。
右侧的Deployment Descriptors 里的 Type和Path下的列表选中
右侧 点击 像 的符号,把路径里的【web】改成【src\main\webapp】
紧跟下面的下拉框选择【3.1】
同样的操作改下面的列表,把路径里的【web】改成【src\main\webapp】
 
1.3创建 war exploded
接着点击 【Create Artifact】
再看到了WEB-INF时,选中它,然后点击紧挨的工具条上的文件夹(带+号)输入lib后按下回车。
找到右侧 Available Elements 把这个module下面的所有jar包加入到lib文件夹下,按住shift从首选到末,再右键,就有个选项:add to lib 类似的。
 
做完这些,就有一个maven项目了,如果看到带蓝色圆形的webapp目录,并且 里面的web-inf下有web.xml 说明这里就成功创建了一个web项目。
 
 
二、把项目部署到tomcat
1.关闭所有的idea子窗体,再主窗体右上角找到蓝色锤子图标,点击右侧的 【Add configuration】
点击+ 按钮 找到【Tomcat Server】-》【local】
2.取个名字,配置启动时的url默认http://localhost:8080/,指定 Http port
3.找到【Deployment】-》右侧 +按钮-》artifact-》选择刚才的war exploded。
点击【applay】再点击【ok】
 
这里如果要测试,可以再webapp下创建一个页面,点击启动按钮 然后自己输入地址访问。
 
三、把web项目集成Spring
 
1.再Resources文件夹下创建 applicationContext.xml
右键 Resources文件夹-》new-》XML Configuration File -》找到spring.xml
如果没有,刷新一下maven:右键-》项目名称-》maven-》Reimport
输入:applicationContext.xml
2.同样的方法创建spring-mvc.xml文件
3.配置web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<!-- 配置加载类路径的配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!-- 配置监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 前端控制器(加载classpath:spring-mvc.xml 服务器启动创建servlet) -->
<servlet>
<servlet-name>dispatacherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--配置初始化参数,创建完DispatcherServlet对象,加载spring-mvc.xml配置文件 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<!-- 服务器启动的时候,让DispatcherServlet对象创建-->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatacherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
 
4.配置applicationContext.xml
注意加入context命名空间
<beans xmlns="http://www.springframework.org/schema/beans"

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
"
在beans标签里配置
<context:component-scan base-package="com.ll">
<context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.RestController"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
 
四、集成SpringMvc
1.在web-inf下创建pages文件夹。
2.配置spring-mvc.xml
引入命名空间
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
">

然后

<!-- 扫描controller的注解,别的不扫描 -->
<context:component-scan base-package="com.ll.controller"></context:component-scan> <!-- 配置视图解析器 -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/pages/"/>
<property name="suffix" value=".jsp"/>
</bean> <!-- 开启对SpringMVC注解的支持 -->
<mvc:annotation-driven/>
五、测试一下(以免后面配置多了,出问题,不好找原因)
创建jar包:右键java-》new class-》输入com.ll.controller.UserController 回车
编写控制器的代码,随便返回一个jsp视图,要在pages文件夹下建立同名称的jsp文件。
启动对应配置的tomcat,输入url访问,如果能访问到页面就可以下一步集成Mybaits
六、集成MyBaits
1.在Resources文件夹下创建 mappers文件夹
2.在Resources下新建File jdbc.properties,粘贴下面的内容
jdbc.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc.url=jdbc:sqlserver://localhost:1433;DatabaseName=Learnning
jdbc.username=sa
jdbc.password=111
3.创建 com.ll.entity.user类,这时可以根据你数据库的字段来写字段。
4.在applicationContext.xml下粘贴
<context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder>
<context:component-scan base-package="com.ll">
<context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.RestController"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="driverClassName" value="${jdbc.driver}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="typeAliasesPackage" value="com.ll.entity"/>
<property name="mapperLocations" value="classpath:mappers/*.xml"/>
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageHelper">
<property name="properties">
<props>
<prop key="helperDialect">sqlserver</prop>
</props>
</property>
</bean>
</array>
</property>
</bean>
<!-- 扫描dao接口 接口代理 -->
<bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.ll.dao"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>
5.编写userMapper.xml文件
右键mappers->new File-》输入userMapper.xml 粘贴
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ll.dao.UserDao"> <select id="findUserById" parameterType="String" resultType="User">
select * from sys_user where id = #{id};
</select> </mapper>
七、编写测试案例并进行测试
如果没有sqlserver可以网上找一找mysql或者oracle的url配置,该jdbc.properties里的url。
改数据库用户名和密码。
 
主要是在数据库创建 sys_user表,创建Dao层接口 、创建Services层、最后编写controller代码,测试。
 
项目下载:
链接:https://pan.baidu.com/s/1Wj84eQiFAJYUDngrq9cmhA
提取码:wjx3
复制这段内容后打开百度网盘手机App,操作更方便哦--来自百度网盘超级会员V3的分享


win10 使用idea 构建一个ssm的模板maven项目的更多相关文章

  1. 搭建一个ssm框架的maven项目需要配置的文件

    单独功能需要的配置文件: 1,mybatis配置文件      mybatis-config.xml2,spring配置文件        spring-context.xml  ......3,we ...

  2. 构建一个简单的Spring Boot项目

    11 构建一个简单的Spring Boot项目 这个章节描述如何通过Spring Boot构建一个"Hello Word"web应用,侧重介绍Spring Boot的一些重要功能. ...

  3. 用Java构建一个简单的WebSocket聊天项目之新增HTTP接口调度

    采用框架 我们整个Demo基本不需要大家花费太多时间,就可以实现以下的功能. 用户token登录校验 自我聊天 点对点聊天 群聊 获取在线用户数与用户标签列表 发送系统通知 首先,我们需要介绍一下我们 ...

  4. 从零开始构建一个的asp.net Core 项目

    最近突发奇想,想从零开始构建一个Core的MVC项目,于是开始了构建过程. 首先我们添加一个空的CORE下的MVC项目,创建完成之后我们运行一下(Ctrl +F5).我们会在页面上看到"He ...

  5. 从零开始构建一个的asp.net Core 项目(一)

    最近突发奇想,想从零开始构建一个Core的MVC项目,于是开始了构建过程. 首先我们添加一个空的CORE下的MVC项目,创建完成之后我们运行一下(Ctrl +F5).我们会在页面上看到“Hello W ...

  6. ssm框架整合+maven项目创建

    在引入外部maven插件后就可以创建一个maven项目了,这篇文章主要介绍ssm框架的整合和如何创建一个maven项目 1.在开发工具的项目空白区单击右键,依次选择New.Other,会出现如下界面, ...

  7. 构建 struts2 spring3 mybatis 的maven项目 构建 pom.xml

    学习maven项目时 搭建个ssm项目 算是给自己留个备份吧 环境说明: MyEclipse10 Maven   3.2.3 框架: struts2    2.3.24.1 spring3    3. ...

  8. JDK7+EclipseIDE+Tomcat7.0.55++mybatis3+Maven3.2.2 构建webapp 的java 的maven项目

    构建Maven项目 工具 JDK7+EclipseIDE+Tomcat7.0.55++mybatis3+Maven3.2.2 JDK 下载地址 http://www.oracle.com/techne ...

  9. 【2】构建一个SSM项目结构

    初步思考一下这个项目的结构,由于是给一个比较老的公司做这个外包项目,服务器是搭建在windows操作系统上的Tomcat6.0,系统的JDK版本也是JDK1.6,都是比较旧. 数据库方面有专人负责,所 ...

  10. 从零开始构建一个的asp.net Core 项目(二)

    接着上一篇博客继续进行.上一篇博客只是显示了简单的MVC视图页,这篇博客接着进行,连接上数据库,进行简单的CRUD. 首先我在Controllers文件夹点击右键,添加->控制器 弹出的对话框中 ...

随机推荐

  1. CondeseNetV2:清华与华为出品,保持特征的新鲜是特征复用的关键 | CVPR 2021

    论文提出SFR模块,直接重新激活一组浅层特征来提升其在后续层的复用效率,而且整个重激活模式可端到端学习.由于重激活的稀疏性,额外引入的计算量非常小.从实验结果来看,基于SFR模块提出的CondeseN ...

  2. HMS Core上新啦!

    HMS Core上新啦!分析服务营销分析报告全新上线:运动健康服务支持目标场景事件订阅:音频编辑服务提供专业的三维声音频编辑与渲染能力,更多HMS Core能力可点击网页链接了解. 了解更多详情> ...

  3. 《深入理解Java虚拟机》读书笔记:运行时栈帧结构

    代码编译的结果从本地机器码转变为字节码,是存储格式发展的一小步,却是编程语言发展的一大步. 一.概述 在Java虚拟机规范中制定了虚拟机字节码执行引擎的概念模型,这个概念模型成为各种虚拟机执行引擎的统 ...

  4. 支持API 9的Sample已上新,速来拿走

    原文:https://mp.weixin.qq.com/s/sPDG5sG5F_gTp0cE1VV3gQ,点击链接查看更多技术内容.   今年的华为开发者大会上我们发布了HarmonyOS 3.1 D ...

  5. 第一篇:Python入门基础

    主要内容 1.Python简介 2.变量 3.字符编码 4.用户交互 5.if 流程判断 6.while循环 7.for循环 一.Python简介 1.python的创始人为吉多·范罗苏姆(Guido ...

  6. Centos8安装docker-ce

    一.安装步骤 1.安装yum-utils yum install -y yum-utils 2.配置阿里源 yum-config-manager --add-repo http://mirrors.a ...

  7. 重新整理数据结构与算法(c#)—— 平衡二叉树[二十三]

    前言 因为有些树是这样子的: 这样子的树有个坏处就是查询效率低,因为左边只有一层,而右边有3层,这就说明如果查找一个数字大于根元素的数字,那么查询判断就更多. 解决方法就是降低两边的层数差距: 变成这 ...

  8. 【Nano Framework ESP32篇】WS2812 彩色灯带实验

    地球人皆知,许多物联网教程作者的心中都深爱着一灯大师,所以第一个例程总喜欢点灯,高级一点的会来个"一闪一闪亮晶晶".老周今天要扯的也是和灯有关的,但不单纯地点个灯,那样实在不好玩, ...

  9. Java实现学生投票系统

    "感谢您阅读本篇博客!如果您觉得本文对您有所帮助或启发,请不吝点赞和分享给更多的朋友.您的支持是我持续创作的动力,也欢迎留言交流,让我们一起探讨技术,共同成长!谢谢!" 代码 im ...

  10. dotnet 警惕 C# 的 is var 写法

    本文将和大家介绍 C# 语言设计里面,我认为比较坑的一个语法.通过 is var 的写法,会让开发者误以为 null 是不被包含的,然而事实是在这里的 var 是被赋予含义的,将被允许 null 通过 ...