前言 接触SSM框架到现在也有很长时间了,之前也搭建过几个简单的项目,但是没有进行过记录学习和搭建的过程。网上关于ssm框架整合的资料也不少,不过说句实话,单看某一篇文章能够不踩坑的配置并跑起来的也不太多,在学习过程中筛选甄别这些就浪费了相当一部分时间。
相关文章
本文内容 本文理论+实践的方式,分享ssm的相关概念以及采用实践操作的方式搭建整套系统。把搭建过程中踩过的坑、笔记记录整理一下,用以和感兴趣的朋友分享下。
demo下载地址 该项目持续更新中,会在代码以及该文档里面详细注释和介绍。 项目托管在码云
开源平台上,链接:
https://gitee.com/nelucifer/ssm-note ,点击克隆/下载
获取该项目。
前置技能
环境
Spring:4.2.5.RELEASE
Spring MVC
Mybatis:3.3.1
MySQL:5.6
IntelliJ IDEA: 2018.2.3
cxf webservice: webservice接口
pagehelper: 分页
Interceptor:拦截器配置
数据结构:powerdesigner16.5
实践步骤 一、创建项目
打开IDEA,选择New->Projects,按照下面的步骤选择: 选择Maven,然后勾选Create from archetype,选择webapp这一个
完成之后填入相应的maven项目组信息,GroupId是项目组织的标识符,对应java的包结构;ArtifactId是项目的标识符,对应项目的名称,即项目根目录的名称。groupId和artifactId统称为“坐标”。
填写完成之后点击Next,选择setting.xml和repository路径,如下图:
点击Finish后,maven会根据原型自动创建需要的一些配置信息以及目录结构,等待配置完成,初始项目结构如下:
在main文件夹下创建文件夹java、resources,src文件夹下创建test,test文件夹下创建java文件夹; 在java文件夹上右键 -> Mark Directory as
,java文件夹选择Sources Root
,resources文件夹上选择Resources Root
,test文件夹下的java文件夹上选择Test Resources Root
, 操作如下: 完成后的项目结构如下:
二、配置pom.xml和spring 详细的解释直接在代码里面注释了。开始贴代码:
1. pom.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 <?xml version="1.0" encoding="UTF-8" ?> <project xmlns ="http://maven.apache.org/POM/4.0.0" xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation ="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > <modelVersion > 4.0.0</modelVersion > <groupId > com.weyoung</groupId > <artifactId > ssm-note</artifactId > <version > 1.0-SNAPSHOT</version > <packaging > war</packaging > <name > ssm-note Maven Webapp</name > <url > http://www.example.com</url > <description > maven+ssm项目整合笔记</description > <issueManagement > <system > jira</system > <url > </url > </issueManagement > <developers > <developer > <id > coder_lixia</id > <name > lixia</name > <email > ne_lucifer@163.com</email > <url > http://www.wanglixia.top/</url > <roles > <role > Project Manager</role > </roles > <organization > </organization > <organizationUrl > </organizationUrl > </developer > </developers > <properties > <project.build.sourceEncoding > UTF-8</project.build.sourceEncoding > <maven.compiler.source > 1.7</maven.compiler.source > <maven.compiler.target > 1.7</maven.compiler.target > <plugin.maven-compiler > 3.1</plugin.maven-compiler > <javac.target.version > 1.8</javac.target.version > <spring.version > 4.2.5.RELEASE</spring.version > <jstl.version > 1.2</jstl.version > <commons-logging.version > 1.1.1</commons-logging.version > <mybatis.version > 3.3.1</mybatis.version > <mybatis-spring.version > 1.2.4</mybatis-spring.version > <mysql-connector-java.version > 5.1.26</mysql-connector-java.version > <log4j.version > 1.2.14</log4j.version > <slf4j.log4j12.version > 1.7.12</slf4j.log4j12.version > <servlet-api.version > 2.5</servlet-api.version > <commons-io.version > 2.4</commons-io.version > <commons-fileupload.version > 1.3</commons-fileupload.version > <gson.version > 2.2.2</gson.version > <druid.version > 1.0.25</druid.version > <cxf.version > 3.1.6</cxf.version > <fastjson.version > 1.2.32</fastjson.version > <pagehelper.version > 5.1.2</pagehelper.version > <jackson.version > 2.7.4</jackson.version > </properties > <repositories > <repository > <id > public</id > <name > aliyun nexus</name > <url > http://maven.aliyun.com/nexus/content/groups/public/</url > <releases > <enabled > true</enabled > <updatePolicy > never</updatePolicy > <checksumPolicy > ignore</checksumPolicy > </releases > <snapshots > <enabled > false</enabled > <updatePolicy > never</updatePolicy > <checksumPolicy > ignore</checksumPolicy > </snapshots > <layout > default</layout > </repository > </repositories > <pluginRepositories > <pluginRepository > <id > public</id > <name > aliyun nexus</name > <url > http://maven.aliyun.com/nexus/content/groups/public/</url > <releases > <enabled > true</enabled > </releases > <snapshots > <enabled > false</enabled > </snapshots > </pluginRepository > </pluginRepositories > <dependencies > <dependency > <groupId > junit</groupId > <artifactId > junit</artifactId > <version > 4.12</version > <type > jar</type > <scope > test</scope > <optional > true</optional > </dependency > <dependency > <groupId > org.springframework</groupId > <artifactId > spring-aop</artifactId > <version > ${spring.version}</version > <type > jar</type > <scope > compile</scope > </dependency > <dependency > <groupId > org.springframework</groupId > <artifactId > spring-aspects</artifactId > <version > ${spring.version}</version > <type > jar</type > <scope > compile</scope > </dependency > <dependency > <groupId > org.springframework</groupId > <artifactId > spring-beans</artifactId > <version > ${spring.version}</version > <type > jar</type > <scope > compile</scope > </dependency > <dependency > <groupId > org.springframework</groupId > <artifactId > spring-context</artifactId > <version > ${spring.version}</version > <type > jar</type > <scope > compile</scope > </dependency > <dependency > <groupId > org.springframework</groupId > <artifactId > spring-context-support</artifactId > <version > ${spring.version}</version > <type > jar</type > <scope > compile</scope > </dependency > <dependency > <groupId > org.springframework</groupId > <artifactId > spring-core</artifactId > <version > ${spring.version}</version > <exclusions > <exclusion > <groupId > commons-logging</groupId > <artifactId > commons-logging</artifactId > </exclusion > </exclusions > <type > jar</type > <scope > compile</scope > </dependency > <dependency > <groupId > org.springframework</groupId > <artifactId > spring-expression</artifactId > <version > ${spring.version}</version > <type > jar</type > <scope > compile</scope > </dependency > <dependency > <groupId > org.springframework</groupId > <artifactId > spring-jdbc</artifactId > <version > ${spring.version}</version > <type > jar</type > <scope > compile</scope > </dependency > <dependency > <groupId > org.springframework</groupId > <artifactId > spring-tx</artifactId > <version > ${spring.version}</version > <type > jar</type > <scope > compile</scope > </dependency > <dependency > <groupId > org.springframework</groupId > <artifactId > spring-jms</artifactId > <version > ${spring.version}</version > <type > jar</type > <scope > compile</scope > </dependency > <dependency > <groupId > org.springframework</groupId > <artifactId > spring-orm</artifactId > <version > ${spring.version}</version > <type > jar</type > <scope > compile</scope > </dependency > <dependency > <groupId > org.springframework</groupId > <artifactId > spring-oxm</artifactId > <version > ${spring.version}</version > <type > jar</type > <scope > compile</scope > </dependency > <dependency > <groupId > org.springframework</groupId > <artifactId > spring-web</artifactId > <version > ${spring.version}</version > <type > jar</type > <scope > compile</scope > </dependency > <dependency > <groupId > org.springframework</groupId > <artifactId > spring-webmvc</artifactId > <version > ${spring.version}</version > <type > jar</type > <scope > compile</scope > </dependency > <dependency > <groupId > org.springframework</groupId > <artifactId > spring-test</artifactId > <version > ${spring.version}</version > <type > jar</type > <scope > compile</scope > </dependency > <dependency > <groupId > commons-logging</groupId > <artifactId > commons-logging</artifactId > <version > ${commons-logging.version}</version > </dependency > <dependency > <groupId > org.mybatis</groupId > <artifactId > mybatis</artifactId > <version > ${mybatis.version}</version > </dependency > <dependency > <groupId > org.mybatis</groupId > <artifactId > mybatis-spring</artifactId > <version > ${mybatis-spring.version}</version > </dependency > <dependency > <groupId > mysql</groupId > <artifactId > mysql-connector-java</artifactId > <version > ${mysql-connector-java.version}</version > </dependency > <dependency > <groupId > com.alibaba</groupId > <artifactId > druid</artifactId > <version > ${druid.version}</version > </dependency > <dependency > <groupId > log4j</groupId > <artifactId > log4j</artifactId > <version > ${log4j.version}</version > </dependency > <dependency > <groupId > org.slf4j</groupId > <artifactId > slf4j-log4j12</artifactId > <version > ${slf4j.log4j12.version}</version > </dependency > <dependency > <groupId > javax.servlet</groupId > <artifactId > servlet-api</artifactId > <version > ${servlet-api.version}</version > </dependency > <dependency > <groupId > javax.servlet</groupId > <artifactId > jstl</artifactId > <version > ${jstl.version}</version > </dependency > <dependency > <groupId > commons-io</groupId > <artifactId > commons-io</artifactId > <version > ${commons-io.version}</version > </dependency > <dependency > <groupId > commons-fileupload</groupId > <artifactId > commons-fileupload</artifactId > <version > ${commons-fileupload.version}</version > </dependency > <dependency > <groupId > com.google.code.gson</groupId > <artifactId > gson</artifactId > <version > ${gson.version}</version > </dependency > <dependency > <groupId > com.fasterxml.jackson.core</groupId > <artifactId > jackson-core</artifactId > <version > ${jackson.version}</version > </dependency > <dependency > <groupId > com.fasterxml.jackson.core</groupId > <artifactId > jackson-databind</artifactId > <version > ${jackson.version}</version > </dependency > <dependency > <groupId > com.fasterxml.jackson.core</groupId > <artifactId > jackson-annotations</artifactId > <version > ${jackson.version}</version > </dependency > <dependency > <groupId > com.alibaba</groupId > <artifactId > fastjson</artifactId > <version > ${fastjson.version}</version > </dependency > <dependency > <groupId > com.github.pagehelper</groupId > <artifactId > pagehelper</artifactId > <version > ${pagehelper.version}</version > </dependency > <dependency > <groupId > org.apache.cxf</groupId > <artifactId > cxf-rt-frontend-jaxws</artifactId > <version > ${cxf.version}</version > </dependency > <dependency > <groupId > org.apache.cxf</groupId > <artifactId > cxf-core</artifactId > <version > ${cxf.version}</version > </dependency > <dependency > <groupId > org.apache.cxf</groupId > <artifactId > cxf-rt-transports-http</artifactId > <version > ${cxf.version}</version > </dependency > </dependencies > <build > <finalName > ssm-note</finalName > <pluginManagement > <plugins > <plugin > <artifactId > maven-clean-plugin</artifactId > <version > 3.1.0</version > </plugin > <plugin > <artifactId > maven-resources-plugin</artifactId > <version > 3.0.2</version > </plugin > <plugin > <artifactId > maven-compiler-plugin</artifactId > <version > 3.8.0</version > </plugin > <plugin > <artifactId > maven-surefire-plugin</artifactId > <version > 2.22.1</version > </plugin > <plugin > <artifactId > maven-war-plugin</artifactId > <version > 3.2.2</version > </plugin > <plugin > <artifactId > maven-install-plugin</artifactId > <version > 2.5.2</version > </plugin > <plugin > <artifactId > maven-deploy-plugin</artifactId > <version > 2.8.2</version > </plugin > </plugins > </pluginManagement > </build > </project >
2. spring-config.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 <?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" xmlns:tx ="http://www.springframework.org/schema/tx" xmlns:aop ="http://www.springframework.org/schema/aop" 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/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd" > <context:component-scan base-package ="com.weyoung.service" /> <context:component-scan base-package ="com.weyoung.dao" /> <bean id ="sqlSessionFactory" class ="org.mybatis.spring.SqlSessionFactoryBean" > <property name ="dataSource" ref ="MySQLDataSource" /> <property name ="mapperLocations" value ="classpath:/mappers/*.xml" /> <property name ="configLocation" value ="classpath:config/mybatis-config.xml" /> </bean > <bean id ="transactionManager" class ="org.springframework.jdbc.datasource.DataSourceTransactionManager" > <property name ="dataSource" ref ="MySQLDataSource" /> </bean > <bean class ="org.mybatis.spring.mapper.MapperScannerConfigurer" > <property name ="basePackage" value ="com.weyoung.dao" /> <property name ="sqlSessionFactoryBeanName" value ="sqlSessionFactory" /> </bean > <bean id ="dataSourceConfig" class ="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" > <property name ="location" value ="classpath:config/jdbc.properties" /> </bean > <bean class ="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" /> <bean class ="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" > <property name ="messageConverters" > <list > <bean class ="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" /> </list > </property > </bean > <tx:advice id ="txAdvice" transaction-manager ="transactionManager" > <tx:attributes > <tx:method name ="insert*" propagation ="REQUIRED" /> <tx:method name ="update*" propagation ="REQUIRED" /> <tx:method name ="edit*" propagation ="REQUIRED" /> <tx:method name ="save*" propagation ="REQUIRED" /> <tx:method name ="add*" propagation ="REQUIRED" /> <tx:method name ="new*" propagation ="REQUIRED" /> <tx:method name ="set*" propagation ="REQUIRED" /> <tx:method name ="remove*" propagation ="REQUIRED" /> <tx:method name ="delete*" propagation ="REQUIRED" /> <tx:method name ="change*" propagation ="REQUIRED" /> <tx:method name ="get*" propagation ="REQUIRED" read-only ="true" /> <tx:method name ="find*" propagation ="REQUIRED" read-only ="true" /> <tx:method name ="load*" propagation ="REQUIRED" read-only ="true" /> <tx:method name ="*" propagation ="REQUIRED" read-only ="true" /> </tx:attributes > </tx:advice > <aop:config > <aop:pointcut id ="serviceOperation" expression ="execution(* com.weyoung.service.*.*Impl.*(..))" /> <aop:advisor advice-ref ="txAdvice" pointcut-ref ="serviceOperation" /> </aop:config > <bean id ="MySQLDataSource" class ="com.alibaba.druid.pool.DruidDataSource" init-method ="init" destroy-method ="close" > <property name ="driverClassName" value ="${jdbc.mysql.driver}" /> <property name ="url" value ="${jdbc.mysql.url}" /> <property name ="username" value ="${jdbc.mysql.username}" /> <property name ="password" value ="${jdbc.mysql.password}" /> <property name ="initialSize" value ="${jdbc.initialSize}" /> <property name ="minIdle" value ="${jdbc.minIdle}" /> <property name ="maxActive" value ="${jdbc.maxActive}" /> <property name ="maxWait" value ="${jdbc.maxWait}" /> <property name ="timeBetweenEvictionRunsMillis" value ="${jdbc.timeBetweenEvictionRunsMillis}" /> <property name ="testWhileIdle" value ="${jdbc.testWhileIdle}" /> <property name ="testOnBorrow" value ="true" /> <property name ="testOnReturn" value ="false" /> <property name ="poolPreparedStatements" value ="true" /> <property name ="maxPoolPreparedStatementPerConnectionSize" value ="20" /> <property name ="defaultAutoCommit" value ="${jdbc.defaultAutoCommit}" /> <property name ="filters" value ="stat" /> <property name ="proxyFilters" > <list > <ref bean ="logFilter" /> </list > </property > </bean > <bean id ="logFilter" class ="com.alibaba.druid.filter.logging.Slf4jLogFilter" > <property name ="statementExecutableSqlLogEnable" value ="false" /> </bean > </beans >
3. spring-mvc.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 <?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:mvc ="http://www.springframework.org/schema/mvc" xmlns:context ="http://www.springframework.org/schema/context" xsi:schemaLocation =" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd" > <context:component-scan base-package ="com.weyoung.controller" /> <context:annotation-config /> <mvc:annotation-driven > <mvc:message-converters > <ref bean ="stringHttpMessageConverter" /> </mvc:message-converters > </mvc:annotation-driven > <mvc:resources mapping ="/plugins/**" location ="/plugins/" /> <mvc:resources mapping ="/layouts/**" location ="/layouts/" /> <mvc:resources mapping ="/statics/**" location ="/statics/" /> <mvc:interceptors > <mvc:interceptor > <mvc:mapping path ="/**" /> <bean class ="com.weyoung.system.LoginInterceptor" > </bean > </mvc:interceptor > </mvc:interceptors > <bean id ="multipartResolver" class ="org.springframework.web.multipart.commons.CommonsMultipartResolver" > <property name ="defaultEncoding" value ="UTF-8" /> <property name ="maxUploadSize" value ="10485760000" /> <property name ="maxInMemorySize" value ="40960" /> </bean > <bean id ="exceptionResolver" class ="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver" > <property name ="exceptionMappings" > <props > <prop key ="org.springframework.web.multipart.MaxUploadSizeExceededException" > /error/upload_error.jsp </prop > </props > </property > </bean > <bean id ="beanNameViewResolver" class ="org.springframework.web.servlet.view.BeanNameViewResolver" > <property name ="order" value ="1" > </property > </bean > <bean class ="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" /> <bean class ="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" /> <bean id ="contentNegotiationManager" class ="org.springframework.web.accept.ContentNegotiationManagerFactoryBean" > <property name ="favorParameter" value ="false" /> <property name ="parameterName" value ="format" /> <property name ="ignoreAcceptHeader" value ="true" /> <property name ="mediaTypes" > <value > json=application/json xml=application/xml </value > </property > <property name ="defaultContentType" value ="text/html" /> </bean > <bean id ="stringHttpMessageConverter" class ="org.springframework.http.converter.StringHttpMessageConverter" > <constructor-arg value ="UTF-8" index ="0" /> <property name ="supportedMediaTypes" > <list > <value > text/plain;charset=UTF-8</value > </list > </property > </bean > <bean id ="viewResolver" class ="org.springframework.web.servlet.view.InternalResourceViewResolver" > <property name ="viewClass" value ="org.springframework.web.servlet.view.JstlView" /> <property name ="prefix" value ="/front-end/" /> <property name ="suffix" value =".jsp" /> <property name ="order" value ="1" /> </bean > <bean class ="org.springframework.web.servlet.view.ContentNegotiatingViewResolver" > <property name ="contentNegotiationManager" ref ="contentNegotiationManager" /> <property name ="defaultViews" > <bean class ="org.springframework.web.servlet.view.json.MappingJackson2JsonView" /> </property > </bean > </beans >
4. jdbc.properties
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 jdbc.mysql.driver =com.mysql.jdbc.Driver jdbc.mysql.url =jdbc:mysql://localhost:3306/SSM_NOTE?useUnicode=true&characterEncoding=utf8 jdbc.mysql.username =root jdbc.mysql.password =lucifer jdbc.initialSize =5 jdbc.minIdle =5 jdbc.maxActive =100 jdbc.maxWait =100000 jdbc.defaultAutoCommit =false jdbc.removeAbandoned =true jdbc.removeAbandonedTimeout =600 jdbc.testWhileIdle =true jdbc.timeBetweenEvictionRunsMillis =60000 jdbc.minEvictableIdleTimeMillis =300000
5. log4j.properties
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 ConversionPattern =%d %-5p [%t] %c - %m%n log4j.rootLogger =debug,Console,D log4j.logger.com.cnblogs.lzrabbit =DEBUG log4j.logger.org.springframework =ERROR log4j.logger.org.mybatis =DEBUG log4j.logger.org.apache.ibatis =DEBUG log4j.logger.org.quartz =ERROR log4j.logger.org.apache.axis2 =ERROR log4j.logger.org.apache.axiom =ERROR log4j.logger.org.apache =ERROR log4j.logger.httpclient =ERROR log4j.appender.Console =org.apache.log4j.ConsoleAppender log4j.appender.Console.Target =System.out log4j.appender.Console.layout =org.apache.log4j.PatternLayout log4j.appender.Console.layout.ConversionPattern =${ConversionPattern} log4j.appender.D =org.apache.log4j.DailyRollingFileAppender log4j.appender.D.DatePattern ='.'yyyy-MM-dd'.log' log4j.appender.D.File =logs/ssm-note.log log4j.appender.D.Append =true log4j.appender.D.Threshold =DEBUG log4j.appender.D.layout =org.apache.log4j.PatternLayout log4j.appender.D.encoding =UTF-8 log4j.appender.E =org.apache.log4j.DailyRollingFileAppender log4j.appender.E.DatePattern ='.'yyyy-MM-dd'.log' log4j.appender.E.File =logs/daily.log log4j.appender.E.Append =true log4j.appender.E.Threshold =ERROR log4j.appender.E.layout =org.apache.log4j.PatternLayout log4j.appender.E.encoding =UTF-8 log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [%t:%r]-[%p] %m%n
6. 其他 登录业务实现代码:LoginController.java
,LoginDao.java
,User.java
,LoginService.java
,LoginServiceImpl.java
,LoginMapper.xml.xml
的具体实现请下载源码。
三、数据结构 1. 登录表结构
2. 登录表语句 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 drop database if exists ssm_note;create database ssm_note;use ssm_note; drop table if exists USER_LOGIN;create table USER_LOGIN( id int not null , USER_NAME varchar (30 ) not null , PASSWORD varchar (20 ) not null , REG_TIME datetime not null default CURRENT_TIMESTAMP , primary key (id) );
项目预览 一、登录页:
二、欢迎页:
资料推荐
概念整理 1. Spring 创建Spring的主要目的是用来替代更加重量级的企业级Java技术,尤其是EJB。Spring提供了更加轻量级和简单的编程模型。增强了简单老式Java对象(Plain Old Java Object,POJO)的功能。
为了降低Java开发的复杂性,Spring采取了以下四种关键策略:
基于POJO(Plain Old Java Object)的轻量级和最小侵入性编程;
通过依赖注入和面向接口实现松耦合;
基于切面和管理进行声明式编程;
通过切面和模板减少样板式代码。
2. Spring MVC Spring MVC
基于模型-视图-控制器(Model-View-Controller,MVC)模式实现,能够构建像Spring
框架那样灵活和松耦合的Web应用程序。Spring MVC
是一个基于mvc
的web
框架。Spring MVC
是Spring
框架的一个模块,Spring MVC
和Spring
无需通过中间整合层进行整合。
3. Mybatis Mybatis是一款优秀的持久层框架,支持定制化SQL、存储过程以及高级映射。可以使用简单的XML或注解来配置和映射原生信息,将接口和Java的Pojo映射成数据库中的记录。
分享 欢迎扫描下方二维码,关注weyoung公众号,一起交流学习~~
更多联系方式