昨天跟一个小粉丝在聊天的时候,他跟我哭诉说最近好难,我以为他是说找工作好难啊,然后就在我准备各种开导他的时候,他跟我说不是,是我的毕设啊,我的毕设和我的实习期冲突了,没那么多时间准备,并且他说他们学校查得也不严格,但是就是要有这么个破玩意?
哈哈哈哈,想起我当年的毕设,一杯咖啡,一台电脑,一份毕设写一天,改论文的时候坐在宿舍走廊改到凌晨5点的时候,听完他的需求,我翻江倒海啊,找到一份当年毕设那会,整理的一份纯净的ssm框架
所以可能今天的内容对于刚毕业或者刚接触编程的程序员,一套纯净的ssm框架分享给大家,每一个部分都会有详细的注释解释,希望对大家的学习能够有所帮助
关注我,大家一起成长和进步,好了,看正事
开始配置
首先建立以下目录 目录结构 可以自行修改,但一定要同时更改所有配置文件中的路径
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"version="3.0">
<display-name>xssdisplay-name>
<welcome-file-list>
<welcome-file>index.htmlwelcome-file>
welcome-file-list>
<context-param>
<param-name>contextConfigLocationparam-name>
<param-value>classpath:applicationContext.xmlparam-value>
context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
listener>
<filter>
<filter-name>encodingFilterfilter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
<init-param>
<param-name>encodingparam-name>
<param-value>UTF-8param-value>
init-param>
<init-param>
<param-name>forceEncodingparam-name>
<param-value>trueparam-value>
init-param>
<init-param>
<param-name>developmentparam-name>
<param-value>trueparam-value>
init-param>
filter>
<filter-mapping>
<filter-name>encodingFilterfilter-name>
<url-pattern>/*url-pattern>
filter-mapping>
<servlet>
<servlet-name>springmvcservlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
<init-param>
<param-name>contextConfigLocationparam-name>
<param-value>classpath:springmvc.xmlparam-value>
init-param>
<load-on-startup>1load-on-startup>
servlet>
<servlet-mapping>
<servlet-name>springmvcservlet-name>
<url-pattern>/*url-pattern>
servlet-mapping>
<servlet-mapping>
<servlet-name >default servlet-name >
<url-pattern >*.jsurl-pattern>
servlet-mapping >
<servlet-mapping >
<servlet-name >default servlet-name >
<url-pattern >*.cssurl-pattern>
servlet-mapping >
web-app>
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"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/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<context:component-scan base-package="com.*.service">context:component-scan>
<import resource="classpath:applicationContext-mybatis.xml" />
<beanclass="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<value>classpath*:db.propertiesvalue>
list>
property>
bean>
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"init-method="init" destroy-method="close">
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="initialSize" value="${ds.initialSize}" />
<property name="minIdle" value="${ds.minIdle}" />
<property name="maxActive" value="${ds.maxActive}" />
<property name="maxWait" value="${ds.maxWait}" />
<property name="timeBetweenEvictionRunsMillis" value="${ds.timeBetweenEvictionRunsMillis}" />
<property name="minEvictableIdleTimeMillis" value="${ds.minEvictableIdleTimeMillis}" />
<property name="poolPreparedStatements" value="true" />
<property name="maxPoolPreparedStatementPerConnectionSize"value="20" />
<property name="proxyFilters">
<list>
<ref bean="stat-filter" />
list>
property>
bean>
<bean id="stat-filter" class="com.alibaba.druid.filter.stat.StatFilter">
<property name="slowSqlMillis" value="1000" />
<property name="logSlowSql" value="true" />
<property name="mergeSql" value="true" />
bean>
<bean id="txManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
bean>
<tx:annotation-driven proxy-target-class="false"transaction-manager="txManager" />
beans>
applicationContext-mybatis.xml
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"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/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource">property>
<property name="configLocation" value="classpath:mybatis/mybatis-config.xml">property>
<property name="typeAliasesPackage" value="com.xss.pojo">property>
<property name="mapperLocations">
<list>
<value>classpath:mybatis/mapper/*.xmlvalue>
list>
property>
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageInterceptor">
<property name="properties">
<value>
helperDialect=mysql
offsetAsPageNum=true
reasonable=true
value>
property>
bean>
<bean class="com.github.abel533.mapperhelper.MapperInterceptor">
<property name="properties">
<value>
IDENTITY=MYSQL
mappers=com.github.abel533.mapper.Mapper
value>
property>
bean>
array>
property>
bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.*.mapper">property>
bean>
beans>
mybatis-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
span style="box-sizing: border-box;border-width: 0px;border-style: initial;border-color: initial;">configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="cacheEnabled" value="true"/>
<setting name="lazyLoadingEnabled" value="true"/>
<setting name="multipleResultSetsEnabled" value="true"/>
<setting name="useColumnLabel" value="true"/>
<setting name="useGeneratedKeys" value="false"/>
<setting name="autoMappingBehavior" value="PARTIAL"/>
<setting name="safeRowBoundsEnabled" value="false"/>
<setting name="mapUnderscoreToCamelCase" value="true"/>
<setting name="localCacheScope" value="SESSION"/>
<setting name="jdbcTypeForNull" value="OTHER"/>
<setting name="lazyLoadTriggerMethods" value="equals,clone,hashCode,toString"/>
<setting name="aggressiveLazyLoading" value="false"/>
<setting name="logImpl" value="STDOUT_LOGGING"/>
settings>
<typeAliases>
<package name="cn.xss.pojo"/>
typeAliases>
<plugins>
<plugin interceptor="com.github.abel533.mapperhelper.MapperInterceptor">
<property name="IDENTITY" value="MYSQL" />
<property name="mappers" value="com.github.abel533.mapper.Mapper" />
plugin>
plugins>
configuration>
db.properties
jdbc.driver=com.mysql.jdbc.Driver
#\u672C\u5730\u6570\u636E\u5E93
jdbc.url=jdbc:mysql://127.0.0.1:3306/xss?allowMultiQueries=true&useUnicode=true&characterEncoding=utf-8
jdbc.username=root
jdbc.password=root
##DataSource Global Setting
#\u914D\u7F6E\u521D\u59CB\u5316\u5927\u5C0F\u3001\u6700\u5C0F\u3001\u6700\u5927
ds.initialSize=10
ds.minIdle=5
ds.maxActive=12
#\u914D\u7F6E\u83B7\u53D6\u8FDE\u63A5\u7B49\u5F85\u8D85\u65F6\u7684\u65F6\u95F4
ds.maxWait=60000
#\u914D\u7F6E\u95F4\u9694\u591A\u4E45\u624D\u8FDB\u884C\u4E00\u6B21\u68C0\u6D4B\uFF0C\u68C0\u6D4B\u9700\u8981\u5173\u95ED\u7684\u7A7A\u95F2\u8FDE\u63A5\uFF0C\u5355\u4F4D\u662F\u6BEB\u79D2
ds.timeBetweenEvictionRunsMillis=60000
# \u914D\u7F6E\u4E00\u4E2A\u8FDE\u63A5\u5728\u6C60\u4E2D\u6700\u5C0F\u751F\u5B58\u7684\u65F6\u95F4\uFF0C\u5355\u4F4D\u662F\u6BEB\u79D2
ds.minEvictableIdleTimeMillis=300000
springmvc.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
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">
<context:component-scan base-package="com.*.controller">context:component-scan>
<mvc:annotation-driven />
<mvc:default-servlet-handler />
<beanclass="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="mappingJacksonHttpMessageConverter" />
list>
property>
bean>
<bean id="mappingJacksonHttpMessageConverter"class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8value>
<value>application/json;charset=UTF-8value>
list>
property>
bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.freemarker.FreeMarkerView"/>
<property name="contentType" value="text/html; charset=utf-8"/>
<property name="requestContextAttribute" value="rc"/>
<property name="cache" value="false"/>
<property name="viewNames" value="*.html" />
<property name="suffix" value=""/>
<property name="order" value="0"/>
bean>
<bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="/WEB-INF/page/"/>
<property name="defaultEncoding" value ="UTF-8">property>
bean>
<mvc:resources location="/static/" mapping="/static/**">mvc:resources>
beans>
写在最后
其实个人感觉程序员这一行除了努力认真地学习一些知识点之外,整理记录也是相当重要,前期可能没什么效果,越到后面重要性体现的越明显,甚至有时候会影响你的工作升迁
关注我,大家一起努力成长
—
关注作者微信公众号 —《Java架构师联盟》
了解更多java后端架构知识以及最新面试宝典
![ab9bd90d730746229ac61b3411b6a8b2.png](https://i-blog.csdnimg.cn/blog_migrate/f160e410dcdbde465a38949979743bd4.png)
![ac4f23228c08cdc54b6252aa0599e6cf.png](https://i-blog.csdnimg.cn/blog_migrate/327d57fbe6b95dcfbc194b1d0cd33e59.png)
看完本文记得给作者点赞+在看哦~~~大家的支持,是作者源源不断出文的动力。