日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

SSM框架的搭建(idea)

發布時間:2025/5/22 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SSM框架的搭建(idea) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

SSM框架的搭建(idea)

  • 首先建立項目:

    一路下一步即可

  • 導入依賴(context,mysql,mybatis,druid

  • <dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.3.8</version></dependency><!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc --><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>5.3.8</version></dependency><!-- https://mvnrepository.com/artifact/org.mybatis/mybatis --><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.5.7</version></dependency><!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.25</version></dependency><!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --><!-- <dependency>--><!-- <groupId>mysql</groupId>--><!-- <artifactId>mysql-connector-java</artifactId>--><!-- <version>5.1.49</version>--><!-- </dependency>--><!-- https://mvnrepository.com/artifact/com.alibaba/druid --><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.2.6</version></dependency>
  • 設置三個.xml文件
    第一個:config-spring.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: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 https://www.springframework.org/schema/context/spring-context.xsd"><context:component-scan base-package="com.example"></context:component-scan> </beans>

    第二個:config-springmvc.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: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 https://www.springframework.org/schema/context/spring-context.xsd"><!--配置springmvc框架的注解的掃描范圍,在加載時需要掃描的注解范圍擴展:springboot是通過 main方法所在類確定掃描范圍;main方法所在包及其子包作為spring的掃描范圍--><context:component-scan base-package="com.example"></context:component-scan><!-- springmvc框架的內部資源視圖解析器,完成向view層頁面的轉發和解析處理 --><bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/><property name="prefix" value="/WEB-INF/logined/"/><property name="suffix" value=".jsp"/></bean></beans>

    第三個:db.properties

    driverClassName=com.mysql.cj.jdbc.Driver useUnicode=true&characterEncoding=utf8 url=jdbc:mysql://localhost:3306/practical_training?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Hongkong&allowPublicKeyRetrieval=true username=root password=123456 initialSize=2 maxActive=20 minIdle=0 maxWait=60000 validationQuery=SELECT 1 FROM DUAL testOnBorrow=false testOnReturn=false testWhileIdle=true timeBetweenEvictionRunsMillis=60000 minEvictableIdleTimeMillis=25200000 removeAbandoned=true removeAbandonedTimeout=1800 logAbandoned=true filters=mergeStat
  • 最重要的配置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_4_0.xsd"version="4.0"><!--============================spring容器加載器的上下文監聽器加載spring初始配置文件=====================================--><!-- web容器啟動時讀取的初始化參數--><context-param><!-- 參數的名字是固定的,是給web容器加載的spring的監聽器的類使用的--><param-name>contextConfigLocation</param-name><!-- 參數的值:用于指明spring配置文件的路徑地址--><param-value>classpath:config-spring.xml</param-value></context-param><!-- 這里的配置就是spring框架在tomcat等web容器開始的入口,等價于從main方法的調用--><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!--============================springmvc核心轉發控制器的初始配置文件=====================================--><!-- 這里的配置就是springmvc框架在tomcat等web容器開始的入口,等價于從main方法的調用--><servlet><servlet-name>DispatcherServlet</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:config-springmvc.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><!-- 映射路徑是 web項目的根目錄,表示所有的請求全部由DispatcherServlet進行轉發處理--><servlet-mapping><servlet-name>DispatcherServlet</servlet-name><url-pattern>/</url-pattern></servlet-mapping><!-- 亂碼 過濾器--><!-- 配置一個filter,用于設置request和response編碼--><!--=================配置springmvc框架的編碼過濾器,解決中文傳輸亂碼的問題========================--><filter><filter-name>CharsetEncodingFilter</filter-name><filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class><!--初始化參數,設置CharacterEncodingFilter類在創建時的初始化參數的值--><init-param><param-name>encoding</param-name><param-value>utf-8</param-value></init-param></filter><!--filter的映射路徑--><filter-mapping><filter-name>CharsetEncodingFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping></web-app>

    詳見代碼參考搭建gitee地址:

    gitee倉庫

    總結

    以上是生活随笔為你收集整理的SSM框架的搭建(idea)的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。