一、创建一个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. 仅需30行代码,轻松集成HMS Core视频编辑服务屏幕录制能力

    现如今,手机录屏是必不可少的能力之一.对于游戏领域作者来说,在平时直播玩游戏.制作攻略.操作集锦时,不方便切屏,这时在游戏内如果有一个录制按钮就可以随时开启,记录下每个精彩瞬间,减少后期剪辑工作量:在 ...

  2. openGauss Sqlines 使用指导

    openGauss Sqlines 使用指导 Sqlines 简介 Sqlines 是一款开源软件,支持多种数据库之间的 SQL 语句语法的的转换,openGauss 将此工具修改适配,新增了 ope ...

  3. 2、androidStudio调用Unity方法

    1.导入Unity的Classes.jar文件 (1).首先找到这个包在哪 Unity版本为5.0之前时,classes.jar的路径: unity的安装路径\Editor\Data\Playback ...

  4. DevEco Device Tool 3.0 Release带来5大能力升级,让智能设备开发更高效

    原文:https://mp.weixin.qq.com/s/QYlHUU05BDlzVxbfZbiKOg,点击链接查看更多技术内容. DevEco Device Tool是面向智能设备开发者提供的一站 ...

  5. k8s集群安装(kubeadm方式)

    一.准备三台虚拟机,系统CentOS7.9: 192.168.1.221 master1 192.168.1.189  node1 192.168.1.60  node2 二..对三台虚拟机初始化 1 ...

  6. 说说你对Node.js 的理解?优缺点?应用场景?

    一.是什么 Node.js 是一个开源与跨平台的 JavaScript 运行时环境 在浏览器外运行 V8 JavaScript 引擎(Google Chrome 的内核),利用事件驱动.非阻塞和异步输 ...

  7. 力扣1098(MySQL)-小众书籍(中等)

    题目: 书籍表 Books: book_id 是这个表的主键 订单表 Orders: order_id 是这个表的主键.book_id 是 Books 表的外键. 问题你需要写一段 SQL 命令,筛选 ...

  8. 力扣153(java&python)-寻找旋转排序数组中的最小值(中等)

    题目: 已知一个长度为 n 的数组,预先按照升序排列,经由 1 到 n 次 旋转 后,得到输入数组.例如,原数组 nums = [0,1,2,4,5,6,7] 在变化后可能得到:若旋转 4 次,则可以 ...

  9. 力扣393(java)-UTF-8编码验证(中等)

    题目: 给定一个表示数据的整数数组 data ,返回它是否为有效的 UTF-8 编码. UTF-8 中的一个字符可能的长度为 1 到 4 字节,遵循以下的规则: 对于 1 字节 的字符,字节的第一位设 ...

  10. HarmonyOS NEXT应用开发之使用AKI轻松实现跨语言调用

    介绍 针对JS与C/C++跨语言访问场景,NAPI使用比较繁琐.而AKI提供了极简语法糖使用方式,一行代码完成JS与C/C++的无障碍跨语言互调,使用方便.本示例将介绍使用AKI编写C++跨线程调用J ...