网站首页 > 博客文章 正文
IDEA搭建项目所需准备:idea开发工具、jdk1.7、mysql、Navicat、maven
一、创建maven项目
1、 file -----> new -----> project
2、点击 next
3、点击 next
4、点击 next
5、点击 finish ,静静的等待项目的创建,控制台出现夏天标志,则创建maven项目成功
二、创建对应的文件夹
1、在main下创建java、resources文件夹并且设置为Sources Root 和Resources Root
2、在java下建常用的包,如下图所示:
3、在resources 下建文件夹,如下图所示
4、创建jsp文件存放的文件夹
三、编写对应的配置文件
1、pom.xml,里面包含了所需要的jar包
版本控制,方便修改
<?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:c="http://www.springframework.org/schema/c" xmlns:cache="http://www.springframework.org/schema/cache" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" xmlns:task="http://www.springframework.org/schema/task" 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.3.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.3.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.3.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-4.3.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.3.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.3.xsd"> <!--使用注解驱动--> <mvc:annotation-driven /> <!--配置视图解析器--> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <!--重定向时,是否加上上下文路径--> <property name="redirectContextRelative" value="true"/> <!--配置解析前后缀--> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean> <!--扫描所有controller--> <context:component-scan base-package="cn.doyoulove.controller"/></beans>
2、编写spring-mvc.xml
driver=com.mysql.jdbc.Driver#driver=com.mysql.cj.jdbc.Driver#mytest为我本地的数据库名url=jdbc:mysql://localhost:3306/test#url=jdbc:mysql://192.168.220.139:3306/teaching_manageusername=root#下面输入自己数据库的密码password=123456#定义初始连接数initialSize=1#定义最大连接数maxActive=20#定义最大空闲maxIdle=20#定义最小空闲minIdle=1#定义最长等待时间maxWait=60000
3、编写spring-mybatis.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:p="http://www.springframework.org/schema/p" 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-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"> <!--自动扫描--> <context:component-scan base-package="cn.doyoulove"/> <!--引入properties文件--> <bean id="placeholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="classpath:jdbc.properties"></property> </bean> <!--配置数据源--> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <!--数据库连接池--> <property name="driverClassName" value="${driver}"/> <property name="url" value="${url}"/> <property name="username" value="${username}"/> <property name="password" value="${password}"/> <!-- 初始化连接大小 --> <property name="initialSize" value="${initialSize}"></property> <!-- 连接池最大数量 --> <property name="maxActive" value="${maxActive}"></property> <!-- 连接池最大空闲 --> <property name="maxIdle" value="${maxIdle}"></property> <!-- 连接池最小空闲 --> <property name="minIdle" value="${minIdle}"></property> <!-- 获取连接最大等待时间 --> <property name="maxWait" value="${maxWait}"></property> </bean> <!--配置sqlsession工厂--> <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <!-- 自动扫描mapping.xml文件 --> <property name="mapperLocations" value="classpath:mapper/*.xml"/> </bean> <!--配置DAO所在spring会自动查找下面的类--> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="cn.doyoulove.dao"/> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/> </bean></beans>
4、方便管理数据库的相关配置,所有会单独的用一个文件来存放。jdbc.properties文件
driver=com.mysql.jdbc.Driver#driver=com.mysql.cj.jdbc.Driver#mytest为我本地的数据库名url=jdbc:mysql://localhost:3306/test#url=jdbc:mysql://192.168.220.139:3306/teaching_manageusername=root#下面输入自己数据库的密码password=123456#定义初始连接数initialSize=1#定义最大连接数maxActive=20#定义最大空闲maxIdle=20#定义最小空闲minIdle=1#定义最长等待时间maxWait=60000
5、由于编写spring-mybatis.xml时,扫描mapper下的所有xml会报错,因为下面没有xml文件,所有建一个xml文件。
在dao下新建一个接口
6、编写wen.xml
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" ><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0" metadata-complete="true"> <display-name>Archetype Created Web Application</display-name> <!--设置默认的字符集--> <filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!--启动spring容器--> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/spring-mybatis.xml</param-value> </context-param> <!--初始化spring-mvc容器--> <servlet> <servlet-name>springDispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/spring-mvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springDispatcherServlet</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping></web-app>
到此为止,所有的配置文件编写完成
四、配置tomcat,启动项目
1、
2、
3、
4、
5、
6、
7、
8、启动成功
9、访问成功
自此,ssm整合完成,下一篇开始编写案例
猜你喜欢
- 2024-10-20 从零开发一个WEB应用(一)搭建后端开发环境
- 2024-10-20 SpringBoot教程:Maven方式创建SpringBoot项目
- 2024-10-20 学Maven,这篇万余字的教程,真的够用了
- 2024-10-20 javaEE技术分享之如何使用Spring Boot快速创建Web应用
- 2024-10-20 Maven项目改为spring boot项目的方法
- 2024-10-20 「干货」带你走进Spring Boot 项目实战:Maven 多模块项目搭建
- 2024-10-20 Eclipse + Ant / Maven + Java 8 开发环境搭建一文穿透
- 2024-10-20 idea新建springboot项目(idea新建一个springboot项目)
- 2024-10-20 Maven+Jetty/Tomcat进行web部署开发
- 2024-10-20 IDEA下从零开始搭建SpringBoot工程
你 发表评论:
欢迎- 367℃用AI Agent治理微服务的复杂性问题|QCon
- 358℃初次使用IntelliJ IDEA新建Maven项目
- 356℃手把手教程「JavaWeb」优雅的SpringMvc+Mybatis整合之路
- 351℃Maven技术方案最全手册(mavena)
- 348℃安利Touch Bar 专属应用,让闲置的Touch Bar活跃起来!
- 346℃InfoQ 2024 年趋势报告:架构篇(infoq+2024+年趋势报告:架构篇分析)
- 345℃IntelliJ IDEA 2018版本和2022版本创建 Maven 项目对比
- 342℃从头搭建 IntelliJ IDEA 环境(intellij idea建包)
- 最近发表
- 标签列表
-
- powershellfor (55)
- messagesource (56)
- aspose.pdf破解版 (56)
- promise.race (63)
- 2019cad序列号和密钥激活码 (62)
- window.performance (66)
- qt删除文件夹 (72)
- mysqlcaching_sha2_password (64)
- ubuntu升级gcc (58)
- nacos启动失败 (64)
- ssh-add (70)
- jwt漏洞 (58)
- macos14下载 (58)
- yarnnode (62)
- abstractqueuedsynchronizer (64)
- source~/.bashrc没有那个文件或目录 (65)
- springboot整合activiti工作流 (70)
- jmeter插件下载 (61)
- 抓包分析 (60)
- idea创建mavenweb项目 (65)
- vue回到顶部 (57)
- qcombobox样式表 (68)
- vue数组concat (56)
- tomcatundertow (58)
- pastemac (61)
本文暂时没有评论,来添加一个吧(●'◡'●)