返回顶部
首页 > 资讯 > 后端开发 > JAVA >快速搭建SSM框架【详细】
  • 285
分享到

快速搭建SSM框架【详细】

mybatisjavaspring 2023-10-09 05:10:46 285人浏览 八月长安
摘要

文章目录 一、开发环境准备二、搭建SSM2.1新建Maven项目2.2项目整体结构2.3spring-config.xml配置2.4jdbc.properties配置2.5mybatis-co

文章目录

一、开发环境准备

二、搭建SSM

2.1新建Maven项目

【File】-> 【new Project】-> 【选择Archetype】
在这里插入图片描述

2.2项目整体结构

项目的整体结构: 包括resources目录下的xml和WEBapp目录下文件。如果不包含某些文件,就自己创建。

mvc结构、spring-config.xml(applicationContext.xml)、jdbc.properties(数据源)、mybatis-config.xml(mybatis配置类)、spring-mvc.xml(springMVC前端控制器配置类)、web.xml(web项目配置类)

在这里插入图片描述

2.3spring-config.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"       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:property-placeholder location="classpath:jdbc.properties"/>        <bean id="myDataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">        <property name="url" value="${database.url}"/>        <property name="username" value="${database.username}"/>        <property name="passWord" value="${database.password}"/>    bean>        <bean id="factory" class="org.mybatis.spring.sqlSessionFactoryBean">                <property name="dataSource" ref="myDataSource"/>                <property name="configLocation" value="classpath:mybatis-config.xml"/>    bean>         <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">                <property name="sqlSessionFactoryBeanName" value="factory"/>                <property name="basePackage" value="com.shenxm.mapper"/>    bean>beans>

2.4jdbc.properties配置

database.driver=com.mysql.cj.jdbc.Driverdatabase.url=jdbc:mysql://localhost:3306/demodatabase.username=rootdatabase.password=123456

2.5mybatis-config.xml配置

DOCTYPE configuration        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"        "http://mybatis.org/dtd/mybatis-3-config.dtd"><configuration>        <properties resource="jdbc.properties"/>    <settings>                <setting name="logImpl" value="STDOUT_LOGGING"/>                <setting name="autoMappingBehavior" value="PARTIAL"/>                <setting name="mapUnderscoreToCamelCase" value="true"/>                <setting name="lazyLoadingEnabled" value="true"/>            settings>        <mappers>                <package name="com.shenxm.mapper"/>    mappers>configuration>

2.6spring-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 https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">        <mvc:annotation-driven />        <context:component-scan base-package="com.shenxm"/>beans>

2.7web.xml配置

<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">        <filter>        <filter-name>CharacterEncodingFilterfilter-name>        <filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>        <init-param>            <param-name>encodingparam-name>            <param-value>UTF-8param-value>        init-param>    filter>    <filter-mapping>        <filter-name>CharacterEncodingFilterfilter-name>        <url-pattern>    private Integer id;        private String name;        private Integer age;}

2.11测试

tomcat8.5配置启动

在这里插入图片描述

访问页面:(成功)

在这里插入图片描述

来源地址:https://blog.csdn.net/love_study1314/article/details/129974446

--结束END--

本文标题: 快速搭建SSM框架【详细】

本文链接: https://www.lsjlt.com/news/426006.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作