说几句:
这几天在忙春招的东西,看了很多东西,但是都没有总结,感觉很急躁。年轻人,从小听到大的一句话就是戒骄戒躁,然而最近,真的开始有点怀疑自己,有点燥。
没能做到爱其所司,脚踏实地,才发现这两个这么难,人总会不自觉地希望少走弯路,甚至是直接达到目的。能投机取巧也是聪明,但这不和脚踏实地相悖。
还有发现之前的选择有错误,学了很多可以看到效果的东西,比如框架,开发辅助工具。但是最有问题的就是,这些东西都太“简单”了。这个简单的意思是想达到可以用来做项目的水平,做到优化的水平,没有什么大的难度,网上的视频,文章一找一大堆。Crtl+C,Crtl+V谁不会。
而且最急躁的一件事,就是学框架的时候还是通过学习视频学的,没能静下心看官方文档,加上之前学习基础的时候没能总结,没做知识点的梳理。这造成了之前政治上的一个东西:下层基础不好,上层结构出问题。所以现在就是虚于表面,有点难受。好好学习吧,人生就是学到老的。
背景:之前在团队部署的一个展示性网页要加后台,然后之前开发东西都是直接自己把包放进去的,现在用maven来试下,说干就干。
环境
Fedora23 + MySQL5.7+Maven3.3.3+Eclipse
框架选择
Spring4.3.7+Hibernate4.1.7+SpringMVC4.3.7
新建webapp项目
命令:
mvn archetype:generate -DgroupId=com.ycTime.XXX -DartifactId=XXX -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false -DarchetypeCatalog=local
在项目工程目录下执行,然后用eclipse打开maven项目就行了。
写pom.xml文件
4.0.0
org.SKT
SKT
war
1.0-SNAPSHOT
SKT Maven Webapp
http://maven.apache.org
UTF-8
junit
junit
4.11
test
org.springframework
spring-core
4.3.7.RELEASE
org.springframework
spring-beans
4.3.7.RELEASE
org.springframework
spring-context
4.3.7.RELEASE
org.springframework
spring-jdbc
4.3.7.RELEASE
org.springframework
spring-tx
4.3.7.RELEASE
org.springframework
spring-web
4.3.7.RELEASE
org.springframework
spring-webmvc
4.3.7.RELEASE
org.springframework
spring-orm
4.3.7.RELEASE
org.hibernate
hibernate-core
4.1.7.Final
mysql
mysql-connector-java
5.1.21
c3p0
c3p0
0.9.1.2
javax.servlet
jstl
1.2
javax.servlet.jsp
jsp-api
2.2.1-b03
provided
com.alibaba
fastjson
1.1.24
javax.servlet
servlet-api
2.5
provided
commons-fileupload
commons-fileupload
1.3.2
SKT
写配置文件
在resources目录下新建文件夹configs,放入所有的配置文件
db.properties(发现用配置文件写不用做转义处理,比如&不用转成& amp;)
user=root
password=root
driverClass=com.mysql.jdbc.Driver
jdbcUrl=jdbc:mysql://localhost:3306/XXX?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8
maxPoolSize=20
minPoolSize=5
maxStatements=100
acquireIncrement=2
hibernate.cfg.xml
/p>
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
org.hibernate.dialect.MySQL5InnoDBDialect
update
true
10
100
1800
3
1000
10
60
30
true
false
20
5
120
100
120
2
true
ApplicationContext.xml
xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-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-3.2.xsd">
true
60
2
true
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
写web.xml
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"
id="WebApp_ID" version="3.0">
SKT
skt.jsp
contextConfigLocation
classpath*:/configs/ApplicationContext.xml
org.springframework.web.context.ContextLoaderListener
Dispatcher
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath*:/configs/ApplicationContext.xml
1
Dispatcher
*.action
encoding
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
encoding
/*
上面的contextConfigLocation那里用了一个classpath*,用classpath的时候会报没找到ApplicationContext.xml的错误。
至此,SpringMVC+Hibernate+Spring的整合已经完成,剩下的就是基于注解的各个模块的开发,也没什么特殊的。