标签:
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 3 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4 <modelVersion>4.0.0</modelVersion> 5 <groupId>SpringMavenStudy</groupId> 6 <artifactId>SpringMavenStudy</artifactId> 7 <name>SpringMavenStudy</name> 8 <version>0.0.1-SNAPSHOT</version> 9 <packaging>war</packaging> 10 11 <properties> 12 <!-- jdk版本号 --> 13 <jdk.version>1.7</jdk.version> 14 <!-- spring版本号 --> 15 <!-- <spring.version>4.2.5.RELEASE</spring.version> --> 16 <spring.version>3.2.16.RELEASE</spring.version> 17 <!-- mybatis版本号 --> 18 <mybatis.version>3.2.4</mybatis.version> 19 <!-- log4j日志文件管理包版本 --> 20 <slf4j.version>1.7.12</slf4j.version> 21 <log4j.version>1.2.17</log4j.version> 22 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 23 </properties> 24 <dependencies> 25 <dependency> 26 <groupId>junit</groupId> 27 <artifactId>junit</artifactId> 28 <version>4.12</version> 29 <!-- 表示开发的时候引入,发布的时候不会加载此包 --> 30 <scope>test</scope> 31 </dependency> 32 <!-- 支持servlet的jar包 --> 33 <dependency> 34 <groupId>javax.servlet</groupId> 35 <artifactId>servlet-api</artifactId> 36 <version>2.5</version> 37 <scope>provided</scope> 38 </dependency> 39 <!-- spring jar --> 40 <dependency> 41 <groupId>org.springframework</groupId> 42 <artifactId>spring-core</artifactId> 43 <version>${spring.version}</version> 44 </dependency> 45 <dependency> 46 <groupId>org.springframework</groupId> 47 <artifactId>spring-beans</artifactId> 48 <version>${spring.version}</version> 49 </dependency> 50 <dependency> 51 <groupId>org.springframework</groupId> 52 <artifactId>spring-context</artifactId> 53 <version>${spring.version}</version> 54 </dependency> 55 <dependency> 56 <groupId>org.springframework</groupId> 57 <artifactId>spring-context-support</artifactId> 58 <version>${spring.version}</version> 59 </dependency> 60 <dependency> 61 <groupId>org.springframework</groupId> 62 <artifactId>spring-tx</artifactId> 63 <version>${spring.version}</version> 64 </dependency> 65 <dependency> 66 <groupId>org.springframework</groupId> 67 <artifactId>spring-aop</artifactId> 68 <version>${spring.version}</version> 69 </dependency> 70 <dependency> 71 <groupId>org.springframework</groupId> 72 <artifactId>spring-jdbc</artifactId> 73 <version>${spring.version}</version> 74 </dependency> 75 <dependency> 76 <groupId>org.springframework</groupId> 77 <artifactId>spring-test</artifactId> 78 <version>${spring.version}</version> 79 </dependency> 80 <!-- <dependency> --> 81 <!-- <groupId>aopalliance</groupId> --> 82 <!-- <artifactId>aopalliance</artifactId> --> 83 <!-- <version>1.0</version> --> 84 <!-- </dependency> --> 85 <!-- <dependency> --> 86 <!-- <groupId>org.springframework</groupId> --> 87 <!-- <artifactId>spring-expression</artifactId> --> 88 <!-- <version>${spring.version}</version> --> 89 <!-- </dependency> --> 90 <!-- spring-remoting包含支持EJB、JMS、远程调用Remoting(RMI、Hessian、Burlap、Http Invoker、JAX-RPC)方面的类 --> 91 <!-- <dependency> --> 92 <!-- <groupId>org.springframework</groupId> --> 93 <!-- <artifactId>spring-remoting</artifactId> --> 94 <!-- <version>${spring.version}</version> --> 95 <!-- </dependency> --> 96 <!-- spring-support包含支持缓存Cache(ehcache)、JCA、JMX、邮件服务(Java Mail、COS Mail)、任务计划Scheduling(Timer、Quartz)方面的类 --> 97 <!-- <dependency> --> 98 <!-- <groupId>org.springframework</groupId> --> 99 <!-- <artifactId>spring-support</artifactId> --> 100 <!-- <version>${spring.version}</version> --> 101 <!-- </dependency> --> 102 103 104 <!-- spring mvc jar --> 105 <!-- 包含Web应用开发时,用到Spring框架时所需的核心类,包括自动载入WebApplicationContext特性的类、Struts与JSF集成类、文件上传的支持类、Filter类和大量工具辅助类 --> 106 <dependency> 107 <groupId>org.springframework</groupId> 108 <artifactId>spring-web</artifactId> 109 <version>${spring.version}</version> 110 </dependency> 111 <!-- webmvc包含国际化、标签、Theme、视图展现FreeMarker、JasperReports、Tiles、Velocity、 XSLT相关类 --> 112 <dependency> 113 <groupId>org.springframework</groupId> 114 <artifactId>spring-webmvc</artifactId> 115 <version>${spring.version}</version> 116 </dependency> 117 <!-- mybatis核心包 --> 118 <dependency> 119 <groupId>org.mybatis</groupId> 120 <artifactId>mybatis</artifactId> 121 <version>${mybatis.version}</version> 122 <!-- <type>jar</type> --> 123 <!-- <scope>compile</scope> --> 124 </dependency> 125 <!-- mybatis spring 插件 --> 126 <dependency> 127 <groupId>org.mybatis</groupId> 128 <artifactId>mybatis-spring</artifactId> 129 <version>1.2.2</version> 130 <!-- <type>jar</type> --> 131 <!-- <scope>compile</scope> --> 132 </dependency> 133 <!-- json转换 ,springmvc 返回json格式必须加入 --> 134 <dependency> 135 <groupId>org.codehaus.jackson</groupId> 136 <artifactId>jackson-mapper-asl</artifactId> 137 <version>1.9.13</version> 138 </dependency> 139 <!-- 集成redis --> 140 <dependency> 141 <groupId>org.springframework.data</groupId> 142 <artifactId>spring-data-redis</artifactId> 143 <version>1.6.4.RELEASE</version> 144 </dependency> 145 <dependency> 146 <groupId>redis.clients</groupId> 147 <artifactId>jedis</artifactId> 148 <version>2.8.1</version> 149 </dependency> 150 <!-- freemarker --> 151 <dependency> 152 <groupId>org.freemarker</groupId> 153 <artifactId>freemarker</artifactId> 154 <version>2.3.23</version> 155 </dependency> 156 <!-- excel报表文件处理 --> 157 <dependency> 158 <groupId>org.apache.poi</groupId> 159 <artifactId>poi</artifactId> 160 <version>3.9</version> 161 </dependency> 162 <!-- 支持xlsx格式的excel --> 163 <dependency> 164 <groupId>org.apache.poi</groupId> 165 <artifactId>poi-ooxml</artifactId> 166 <version>3.9</version> 167 </dependency> 168 <!-- BeanUtils主要提供对JavaBean进行各种操作,提供对Java反射和自省API的包装,Spring的AOP用到 --> 169 <dependency> 170 <groupId>commons-beanutils</groupId> 171 <artifactId>commons-beanutils</artifactId> 172 <version>1.9.2</version> 173 </dependency> 174 <!-- Digester基于规则的XML文档解析,主要用于XML到Java对象的映射. --> 175 <dependency> 176 <groupId>commons-digester</groupId> 177 <artifactId>commons-digester</artifactId> 178 <version>2.0</version> 179 </dependency> 180 <!-- AspectJ使用Java的注解,将切面AOP声明为普通的Java类 --> 181 <dependency> 182 <groupId>org.aspectj</groupId> 183 <artifactId>aspectjrt</artifactId> 184 <version>1.6.9</version> 185 </dependency> 186 <!-- aspectjweaver用于在Spring中集成AspectJ LTW织入器 --> 187 <dependency> 188 <groupId>org.aspectj</groupId> 189 <artifactId>aspectjweaver</artifactId> 190 <version>1.6.9</version> 191 </dependency> 192 <!-- cglib代理 实现AOP的一种方式 ,和它对应的是DynaProxy(java动态代理) --> 193 <dependency> 194 <groupId>cglib</groupId> 195 <artifactId>cglib-nodep</artifactId> 196 <version>2.2</version> 197 </dependency> 198 199 <!-- 导入java ee jar 包 --> 200 <!-- <dependency> --> 201 <!-- <groupId>javax</groupId> --> 202 <!-- <artifactId>javaee-api</artifactId> --> 203 <!-- <version>7.0</version> --> 204 <!-- </dependency> --> 205 <!--sqlserver驱动包 --> 206 <!-- <dependency> --> 207 <!-- <groupId>com.microsoft.sqlserver</groupId> --> 208 <!-- <artifactId>sqljdbc4</artifactId> --> 209 <!-- <version>3.0</version> --> 210 <!-- </dependency> --> 211 212 <!-- 导入Mysql数据库驱动jar包 --> 213 <dependency> 214 <groupId>mysql</groupId> 215 <artifactId>mysql-connector-java</artifactId> 216 <version>5.1.28</version> 217 <!-- <type>jar</type> <scope>compile</scope> --> 218 </dependency> 219 <!-- 导入sqlite数据库驱动jar包 --> 220 <!-- <dependency> --> 221 <!-- <groupId>org.xerial</groupId> --> 222 <!-- <artifactId>sqlite-jdbc</artifactId> --> 223 <!-- <version>3.8.11.2</version> --> 224 <!-- </dependency> --> 225 <!-- 导入dbcp的jar包,用来在applicationContext.xml中配置数据库 --> 226 <!-- <dependency> --> 227 <!-- <groupId>commons-dbcp</groupId> --> 228 <!-- <artifactId>commons-dbcp</artifactId> --> 229 <!-- <version>1.4</version> --> 230 <!-- </dependency> --> 231 <dependency> 232 <groupId>commons-pool</groupId> 233 <artifactId>commons-pool</artifactId> 234 <version>1.6</version> 235 </dependency> 236 <!-- 导入c3p0的jar包,数据库连接池 --> 237 <!-- <dependency> --> 238 <!-- <groupId>com.mchange</groupId> --> 239 <!-- <artifactId>c3p0</artifactId> --> 240 <!-- <version>0.9.5.2</version> --> 241 <!-- </dependency> --> 242 243 <!-- Tomcat jdbc 数据库连接池 --> 244 <dependency> 245 <groupId>org.apache.tomcat</groupId> 246 <artifactId>tomcat-jdbc</artifactId> 247 <version>8.0.32</version> 248 </dependency> 249 <dependency> 250 <groupId>org.apache.commons</groupId> 251 <artifactId>commons-pool2</artifactId> 252 <version>2.4.2</version> 253 </dependency> 254 <!-- JSTL标签类 --> 255 <!-- <dependency> --> 256 <!-- <groupId>jstl</groupId> --> 257 <!-- <artifactId>jstl</artifactId> --> 258 <!-- <version>1.2</version> --> 259 <!-- </dependency> --> 260 261 <!-- 日志文件管理包 --> 262 <!-- log start --> 263 <dependency> 264 <groupId>log4j</groupId> 265 <artifactId>log4j</artifactId> 266 <version>${log4j.version}</version> 267 </dependency> 268 <dependency> 269 <groupId>commons-logging</groupId> 270 <artifactId>commons-logging</artifactId> 271 <version>1.2</version> 272 </dependency> 273 274 <!-- 格式化对象,方便输出日志 --> 275 <dependency> 276 <groupId>com.alibaba</groupId> 277 <artifactId>fastjson</artifactId> 278 <version>1.1.41</version> 279 </dependency> 280 <dependency> 281 <groupId>org.slf4j</groupId> 282 <artifactId>slf4j-api</artifactId> 283 <version>${slf4j.version}</version> 284 </dependency> 285 <dependency> 286 <groupId>org.slf4j</groupId> 287 <artifactId>slf4j-log4j12</artifactId> 288 <version>${slf4j.version}</version> 289 </dependency> 290 <!-- log end --> 291 <dependency> 292 <groupId>commons-configuration</groupId> 293 <artifactId>commons-configuration</artifactId> 294 <version>1.6</version> 295 </dependency> 296 <!-- commons-lang包含了一些数据类型工具类,是java.lang.*的扩展,必须使用的jar包。 --> 297 <dependency> 298 <groupId>org.apache.commons</groupId> 299 <artifactId>commons-lang3</artifactId> 300 <version>3.3.2</version> 301 </dependency> 302 <!-- 上传组件包 --> 303 <dependency> 304 <groupId>commons-fileupload</groupId> 305 <artifactId>commons-fileupload</artifactId> 306 <version>1.3.1</version> 307 </dependency> 308 <dependency> 309 <groupId>commons-io</groupId> 310 <artifactId>commons-io</artifactId> 311 <version>2.4</version> 312 </dependency> 313 <dependency> 314 <groupId>commons-codec</groupId> 315 <artifactId>commons-codec</artifactId> 316 <version>1.9</version> 317 </dependency> 318 319 <!-- commons-httpclient是一个遗留版本,现在官方已经不推荐使用了。https站点中需要加载SSLContext的类。httpclient是官方现在还在开发的,还在维护的,功能也比较强大的组件,提供更好的性能和更大的灵活性。 --> 320 <!-- <dependency> --> 321 <!-- <groupId>commons-httpclient</groupId> --> 322 <!-- <artifactId>commons-httpclient</artifactId> --> 323 <!-- <version>3.1</version> --> 324 <!-- </dependency> --> 325 <dependency> 326 <groupId>org.apache.httpcomponents</groupId> 327 <artifactId>httpclient</artifactId> 328 <version>4.5.2</version> 329 </dependency> 330 <!-- 分页插件 --> 331 <dependency> 332 <groupId>com.github.pagehelper</groupId> 333 <artifactId>pagehelper</artifactId> 334 <version>3.6.0</version> 335 </dependency> 336 <!-- 定时调度 --> 337 <dependency> 338 <groupId>org.quartz-scheduler</groupId> 339 <artifactId>quartz-jobs</artifactId> 340 <version>2.2.1</version> 341 </dependency> 342 <dependency> 343 <groupId>org.quartz-scheduler</groupId> 344 <artifactId>quartz</artifactId> 345 <version>2.2.1</version> 346 </dependency> 347 </dependencies> 348 <!-- 配置文件 --> 349 <profiles> 350 <profile> 351 <id>dev</id> 352 <properties> 353 <package.environment>dev</package.environment> 354 </properties> 355 <activation> 356 <activeByDefault>true</activeByDefault> 357 </activation> 358 <build> 359 <resources> 360 <resource> 361 <directory>src/main/config</directory> 362 </resource> 363 </resources> 364 </build> 365 </profile> 366 <!-- <profile> --> 367 <!-- <id>test</id> --> 368 <!-- <properties> --> 369 <!-- <package.environment>test</package.environment> --> 370 <!-- </properties> --> 371 <!-- <build> --> 372 <!-- <resources> --> 373 <!-- <resource> --> 374 <!-- <directory>src/main/testConfig</directory> --> 375 <!-- </resource> --> 376 <!-- </resources> --> 377 <!-- </build> --> 378 <!-- </profile> --> 379 </profiles> 380 <!-- 打包部署 --> 381 <build> 382 <finalName>SpringMavenStudy</finalName> 383 <resources> 384 <resource> 385 <directory>src/main</directory> 386 </resource> 387 <resource> 388 <directory>src/main/java</directory> 389 <includes> 390 <include>**/*.xml</include> 391 </includes> 392 <filtering>false</filtering> 393 </resource> 394 </resources> 395 396 <plugins> 397 <plugin> 398 <artifactId>maven-compiler-plugin</artifactId> 399 <version>3.3</version> 400 <configuration> 401 <source>${jdk.version}</source> 402 <target>${jdk.version}</target> 403 </configuration> 404 </plugin> 405 <plugin> 406 <groupId>org.codehaus.mojo</groupId> 407 <artifactId>tomcat-maven-plugin</artifactId> 408 <version>1.1</version> 409 </plugin> 410 <plugin> 411 <artifactId>maven-war-plugin</artifactId> 412 <version>2.6</version> 413 <configuration> 414 </configuration> 415 </plugin> 416 </plugins> 417 </build> 418 <repositories> 419 <repository> 420 <id>nexus</id> 421 <name>nexus</name> 422 <url>http://maven.oschina.net/content/groups/public</url> 423 </repository> 424 </repositories> 425 <pluginRepositories> 426 <pluginRepository> 427 <id>nexus</id> 428 <name>nexus</name> 429 <url>http://maven.oschina.net/content/groups/public</url> 430 </pluginRepository> 431 </pluginRepositories> 432 </project>
1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 5 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 6 <display-name>WebTest</display-name> 7 <!-- 设置由Sprng载入的Log4j配置文件位置 --> 8 <context-param> 9 <param-name>log4jConfigLocation</param-name> 10 <param-value>classpath:config/log4j.properties</param-value> 11 </context-param> 12 <!-- Spring刷新Log4j配置文件变动的间隔,单位为毫秒 --> 13 <context-param> 14 <param-name>log4jRefreshInterval</param-name> 15 <param-value>100000</param-value> 16 </context-param> 17 <!-- Spring 配置文件路径,此处可将Spring MVC的相关配置内容配置到Spring的配置文件applicationContext.xml中,共享同一个配置文件即可 --> 18 <context-param> 19 <param-name>contextConfigLocation</param-name> 20 <param-value>classpath*:config/applicationContext.xml</param-value> 21 </context-param> 22 23 <!-- Spring 监听器 配置 --> 24 <!-- <listener> --> 25 <!-- <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> --> 26 <!-- </listener> --> 27 <!-- <listener> --> 28 <!-- <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> --> 29 <!-- </listener> --> 30 <!--spring 环境准备 --> 31 <listener> 32 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 33 </listener> 34 <!-- <listener> --> 35 <!-- <listener-class>org.springframework.web.util.WebAppRootListener</listener-class> --> 36 <!-- </listener> --> 37 <!-- <listener> --> 38 <!-- <listener-class>com.pingan.haofang.service.cache.CacheListener</listener-class> --> 39 <!-- </listener> --> 40 41 <!-- 字符集 过滤器 --> 42 <filter> 43 <filter-name>encodingFilter</filter-name> 44 <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 45 <init-param> 46 <param-name>encoding</param-name> 47 <param-value>UTF-8</param-value> 48 </init-param> 49 <init-param> 50 <param-name>forceEncoding</param-name> 51 <param-value>true</param-value> 52 </init-param> 53 </filter> 54 <filter-mapping> 55 <filter-name>encodingFilter</filter-name> 56 <url-pattern>/*</url-pattern> 57 </filter-mapping> 58 59 <!-- tomcat关闭前先关闭quartz --> 60 <!-- <listener> --> 61 <!-- <listener-class>com.pingan.haofang.web.listener.ShutdownQuartzListener</listener-class> --> 62 <!-- </listener> --> 63 <!-- Spring view分发器 --> 64 <!-- Spring mvc 配置,配置文件名称默认为{servlet-name}-servlet.xml,路径默认在/WEB-INF/下 --> 65 <servlet> 66 <servlet-name>springmvc</servlet-name> 67 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 68 <init-param> 69 <param-name>contextConfigLocation</param-name> 70 <param-value>classpath*:config/springmvc-servlet.xml</param-value> 71 </init-param> 72 <load-on-startup>1</load-on-startup> 73 </servlet> 74 <servlet-mapping> 75 <servlet-name>springmvc</servlet-name> 76 <url-pattern>/</url-pattern> 77 </servlet-mapping> 78 <!-- <servlet-mapping> --> 79 <!-- <servlet-name>dispatcher</servlet-name> --> 80 <!-- <url-pattern>*.xls</url-pattern> --> 81 <!-- </servlet-mapping> --> 82 <!-- 配置session超时时间,单位分钟 --> 83 <session-config> 84 <session-timeout>15</session-timeout> 85 </session-config> 86 87 <welcome-file-list> 88 <welcome-file>index.html</welcome-file> 89 </welcome-file-list> 90 <error-page> 91 <error-code>400</error-code> 92 <location>/error/400.jsp</location> 93 </error-page> 94 <error-page> 95 <error-code>403</error-code> 96 <location>/error/403.jsp</location> 97 </error-page> 98 <error-page> 99 <error-code>404</error-code> 100 <location>/error/404.jsp</location> 101 </error-page> 102 <error-page> 103 <error-code>405</error-code> 104 <location>/error/405.jsp</location> 105 </error-page> 106 <error-page> 107 <error-code>406</error-code> 108 <location>/error/406.jsp</location> 109 </error-page> 110 <error-page> 111 <error-code>412</error-code> 112 <location>/error/412.jsp</location> 113 </error-page> 114 <error-page> 115 <error-code>500</error-code> 116 <location>/error/500.jsp</location> 117 </error-page> 118 <error-page> 119 <error-code>501</error-code> 120 <location>/error/501.jsp</location> 121 </error-page> 122 <error-page> 123 <error-code>502</error-code> 124 <location>/error/502.jsp</location> 125 </error-page> 126 <error-page> 127 <error-code>503</error-code> 128 <location>/error/503.jsp</location> 129 </error-page> 130 </web-app>
1 <?xml version="1.0" encoding="UTF-8" ?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" 4 xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc" 5 xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 6 xsi:schemaLocation="http://www.springframework.org/schema/aop 7 http://www.springframework.org/schema/aop/spring-aop-3.2.xsd 8 http://www.springframework.org/schema/beans 9 http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 10 http://www.springframework.org/schema/context 11 http://www.springframework.org/schema/context/spring-context-3.2.xsd 12 http://www.springframework.org/schema/mvc 13 http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd 14 http://www.springframework.org/schema/tx 15 http://www.springframework.org/schema/tx/spring-tx-3.2.xsd"> 16 <!-- 对所有类进行扫描,以完成Bean创建和自动依赖注入的功能 --> 17 <context:component-scan base-package="com.test.*" /> 18 <!-- 启动基于Spring MVC的注解功能,激活@Controller,将控制器与方法映射加入到容器中 --> 19 <mvc:annotation-driven /> 20 <mvc:view-controller path="/" view-name="forward:/index" /> 21 22 <!--避免IE执行AJAX时,返回JSON出现下载文件 --> 23 <!-- <bean id="mappingJacksonHttpMessageConverter" --> 24 <!-- class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"> --> 25 <!-- <property name="supportedMediaTypes"> --> 26 <!-- <list> --> 27 <!-- <value>text/html;charset=UTF-8</value> --> 28 <!-- </list> --> 29 <!-- </property> --> 30 <!-- </bean> --> 31 32 <!-- 定义跳转的文件的前后缀 ,视图模式配置 --> 33 <!-- HandlerMapping --> 34 <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" /> 35 <!-- HandlerAdapter --> 36 <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" /> 37 38 <!-- 配置试图解析器 --> 39 <!-- <bean id="viewResolver" --> 40 <!-- class="org.springframework.web.servlet.view.InternalResourceViewResolver"> --> 41 <!-- <property name="prefix" value="/WEB-INF/views/" /> --> 42 <!-- <property name="suffix" value=".jsp" /> --> 43 <!-- </bean> --> 44 <bean id="viewResolver" 45 class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"> 46 <!-- 模板后缀,指定html页面为模板 --> 47 <property name="prefix" value="/WEB-INF/views/*" /> 48 <property name="suffix" value=".ftl" /> 49 <property name="order" value="0" /> 50 <property name="cache" value="true" /> 51 <!-- 使用这个模板类来解析视图 --> 52 <!-- <property name="viewClass" value="com.pingan.haofang.util.CommonFreeMarkerView" /> --> 53 <property name="viewClass" value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" /> 54 <property name="exposeSpringMacroHelpers" value="true" /> 55 <!-- 允许访问请求属性,默认为false --> 56 <property name="exposeRequestAttributes" value="true" /> 57 <!-- 允许访问会话属性,默认为false --> 58 <property name="exposeSessionAttributes" value="true" /> 59 <!-- 页面上下文,类似于request.contextPath --> 60 <property name="requestContextAttribute" value="rc" /> 61 <!-- 模板输出内容编码,此处应与defaultEncoding保持一致 --> 62 <property name="contentType" value="text/html;charset=UTF-8"></property> 63 </bean> 64 <bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"> 65 <!-- 模板文件所在目录 --> 66 <property name="templateLoaderPath" value="/WEB-INF/views/*" /> 67 <!-- FreeMarker环境属性配置 --> 68 <property name="freemarkerSettings"> 69 <props> 70 <prop key="template_update_delay">5</prop><!--刷新模板的周期,单位为秒,每隔30秒检查模板是否更新,单位为秒如果不经常更新模板可将更新的延迟时间设定长一点 --> 71 <prop key="default_encoding">UTF-8</prop><!--指定FreeMarker模板文件的编码格式 --> 72 <prop key="locale">UTF-8</prop><!-- 本地化设置,指定地区语言环境,我们的语言是中文 --> 73 <prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop> 74 <prop key="date_format">yyyy-MM-dd</prop> 75 <prop key="time_format">HH:mm:ss</prop> 76 <prop key="number_format">#.##########</prop> 77 <prop key="boolean_format">true,false</prop> 78 <prop key="whitespace_stripping">true</prop> 79 <prop key="tag_syntax">auto_detect</prop> 80 <prop key="url_escaping_charset">UTF-8</prop> 81 <prop key="classic_compatible">true</prop> 82 <prop key="template_exception_handler">ignore</prop> 83 </props> 84 </property> 85 </bean> 86 87 <!-- 对某些静态资源,如css,js,图片等进行过滤 ,有引用 "/resources/**" 的路径引用转到工程的/resources/目录取资源,cache-period启用浏览器缓存,上传的图片缓存1个月,其他js,css,img资源缓存一年 --> 88 <mvc:resources mapping="/resources/**" location="/resources/" cache-period="31536000" /> 89 90 <!-- 文件上传解析器 id 必须为multipartResolver,SpringMVC在超出上传文件限制时, 91 会抛出org.springframework.web.multipart.MaxUploadSizeExceededException, 92 该异常是SpringMVC在检查上传的文件信息时抛出来的,而且此时还没有进入到Controller方法中, 93 配置文件上传,如果没有使用文件上传可以不用配置,当然如果不配,那么配置文件中也不必引入上传组件包 --> 94 <bean id="multipartResolver" 95 class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> 96 <!-- 默认编码 --> 97 <property name="defaultEncoding" value="utf-8" /> 98 <!-- 文件大小最大值 --> 99 <property name="maxUploadSize" value="10485760000" /> 100 <!-- 内存中的最大值 --> 101 <property name="maxInMemorySize" value="40960" /> 102 </bean> 103 <!-- <mvc:interceptors> --> 104 <!-- <mvc:interceptor> --> 105 <!-- <mvc:mapping path="/**"></mvc:mapping> --> 106 <!-- <mvc:exclude-mapping path="/user/*" /> --> 107 <!-- <bean class="com.pingan.haofang.web.interceptor.PermissionInterceptor" /> --> 108 <!-- </mvc:interceptor> --> 109 <!-- </mvc:interceptors> --> 110 <!-- <bean id="viewResolverExcel" --> 111 <!-- class="org.springframework.web.servlet.view.ResourceBundleViewResolver"> --> 112 <!-- <property name="order" value="1" /> --> 113 <!-- <property name="basename" value="views" /> --> 114 <!-- </bean> --> 115 116 <!-- HttpMessageConverter用于将对象输出到客户端 --> 117 <bean id="jsonmessageConverter" 118 class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"> 119 </bean> 120 <!-- 全局异常处理器 --> 121 <!-- <bean id="handlerExceptionResolver" --> 122 <!-- class="com.pingan.haofang.process.exception.ExceptionResolverCustom"> --> 123 <!-- <property name="jsonmessageConverter" ref="jsonmessageConverter" /> --> 124 <!-- </bean> --> 125 <!--定义异常处理页面 --> 126 <bean id="exceptionResolver" 127 class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> 128 <property name="exceptionMappings"> 129 <props> 130 <prop key="java.sql.SQLException">exception</prop> 131 <prop key="java.io.IOException">exception</prop> 132 <prop key="java.lang.IOException">exception</prop> 133 <prop key="java.lang.NullPointerException">exception</prop> 134 </props> 135 </property> 136 </bean> 137 </beans>
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" 4 xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:task="http://www.springframework.org/schema/task" 5 xmlns:tx="http://www.springframework.org/schema/tx" 6 xsi:schemaLocation="http://www.springframework.org/schema/beans 7 http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 8 http://www.springframework.org/schema/context 9 http://www.springframework.org/schema/context/spring-context-3.2.xsd 10 http://www.springframework.org/schema/mvc 11 http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd 12 http://www.springframework.org/schema/tx 13 http://www.springframework.org/schema/tx/spring-tx-3.2.xsd 14 http://www.springframework.org/schema/task 15 http://www.springframework.org/schema/task/spring-task-3.2.xsd"> 16 <description>Spring-web MVC配置</description> 17 <!-- 引入配置文件 --> 18 <bean id="propertyConfigurer" 19 class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 20 <property name="locations"> 21 <list> 22 <value>classpath*:config/jdbc.properties</value> 23 <!-- <value>classpath*:config/redis.properties</value> --> 24 <value>classpath*:config/quartz.properties</value> 25 <value>classpath*:config/log4j.properties</value> 26 </list> 27 </property> 28 <property name="ignoreUnresolvablePlaceholders" value="true" /> 29 </bean> 30 <!-- <bean class="com.pingan.haofang.util.WebAppContextUtil" /> --> 31 <!-- <import resource="classpath*:config/spring-applicationContext-quartz.xml" /> --> 32 <!-- redis --> 33 <!-- <import resource="classpath*:config/spring-redis.xml" /> --> 34 <!--创建jdbc数据源 --> 35 <!-- tomcat jdbc pool +sqlite数据库连接池 --> 36 <bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" 37 destroy-method="close"> 38 <property name="driverClassName" value="${jdbc.driver}" /> 39 <property name="url" value="${jdbc.url}" /> 40 <property name="username" value="${jdbc.username}" /> 41 <property name="password" value="${jdbc.password}" /> 42 <property name="maxIdle" value="${jdbc.maxIdle}" /> 43 <property name="minIdle" value="${jdbc.minIdle}" /> 44 <property name="maxActive" value="${jdbc.maxActive}" /> 45 <property name="maxWait" value="${jdbc.maxWait}" /> 46 <property name="initialSize" value="10" /> 47 <property name="removeAbandoned" value="${jdbc.removeAbandoned}" /> 48 <property name="removeAbandonedTimeout" value="${jdbc.removeAbandonedTimeout}" /> 49 <property name="validationQuery" value="select 1" /> 50 <property name="validationInterval" value="30000" /> 51 <property name="defaultAutoCommit" value="true" /> 52 <property name="testWhileIdle" value="true" /> 53 <property name="timeBetweenEvictionRunsMillis" value="1200000" /> 54 <property name="minEvictableIdleTimeMillis" value="1800000" /> 55 <property name="numTestsPerEvictionRun" value="5" /> 56 </bean> 57 58 <!-- 创建SqlSessionFactory,并指定数据源 --> 59 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> 60 <!-- 自动扫描entity目录 xml文件 --> 61 <!-- <property name="mapperLocations" value="classpath*:com/test/mappers/*.xml"></property> --> 62 <property name="mapperLocations" value="classpath*:com/test/mappers/UsersDao.xml" /> 63 <property name="dataSource" ref="dataSource" /> 64 </bean> 65 <!-- Mapper文件扫描配置工具,Spring会自动扫描basePackage下所有dao接口 --> 66 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" > 67 <!-- 自动扫描 mybatis的接口 --> 68 <property name="basePackage" value="com.test.dao"></property> 69 <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property> 70 </bean> 71 72 <!-- MapperFactoryBean 创建的代理类实现了IUserDAO接口,并且注入到应用程序中,这样不用写实现类 --> 73 <bean class="org.mybatis.spring.mapper.MapperFactoryBean"> 74 <property name="mapperInterface" value="com.test.dao" /> 75 <property name="sqlSessionFactory" ref="sqlSessionFactory" /> 76 </bean> 77 78 <!-- 配置事务管理 --> 79 <bean id="txManager" 80 class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 81 <property name="dataSource" ref="dataSource" /> 82 </bean> 83 84 <!-- 事务注解驱动,标注@Transactional的类和方法将具有事务性 --> 85 <tx:annotation-driven transaction-manager="txManager" /> 86 </beans>
jdbc.driver=com.mysql.jdbc.Driver #jdbc.driver=org.sqlite.JDBC jdbc.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8 #jdbc.url=jdbc:sqlite:D:/test.db jdbc.username=root jdbc.password=root #\u5B9A\u4E49\u521D\u59CB\u8FDE\u63A5\u6570 jdbc.initialSize=1 #\u5B9A\u4E49\u6700\u5927\u8FDE\u63A5\u6570 jdbc.maxActive=20 #\u5B9A\u4E49\u6700\u5927\u7A7A\u95F2 jdbc.maxIdle=20 #\u5B9A\u4E49\u6700\u5C0F\u7A7A\u95F2 jdbc.minIdle=3 #\u5B9A\u4E49\u6700\u957F\u7B49\u5F85\u65F6\u95F4 jdbc.maxWait=60000 #\u81EA\u52A8\u6E05\u9664\u65E0\u7528\u8FDE\u63A5 jdbc.removeAbandoned=true #\u6E05\u9664\u65E0\u7528\u8FDE\u63A5\u7684\u7B49\u5F85\u65F6\u95F4 jdbc.removeAbandonedTimeout=180 #\u8FDE\u63A5\u5C5E\u6027 jdbc.connectionProperties="clientEncoding\=utf-8"
# Redis settings # server IP redis.host=127.0.0.1 # server port redis.port=6379 # server password redis.password=myredis # use dbIndex redis.pool.database=0 # \u63A7\u5236\u4E00\u4E2Apool\u6700\u591A\u6709\u591A\u5C11\u4E2A\u72B6\u6001\u4E3Aidle(\u7A7A\u95F2\u7684)\u7684jedis\u5B9E\u4F8B redis.pool.maxIdle=300 # \u8868\u793A\u5F53borrow(\u5F15\u5165)\u4E00\u4E2Ajedis\u5B9E\u4F8B\u65F6\uFF0C\u6700\u5927\u7684\u7B49\u5F85\u65F6\u95F4\uFF0C\u5982\u679C\u8D85\u8FC7\u7B49\u5F85\u65F6\u95F4(\u6BEB\u79D2)\uFF0C\u5219\u76F4\u63A5\u629B\u51FAJedisConnectionException\uFF1B redis.pool.maxWait=3000 redis.pool.maxTotal=600 # \u5728borrow\u4E00\u4E2Ajedis\u5B9E\u4F8B\u65F6\uFF0C\u662F\u5426\u63D0\u524D\u8FDB\u884Cvalidate\u64CD\u4F5C\uFF1B\u5982\u679C\u4E3Atrue\uFF0C\u5219\u5F97\u5230\u7684jedis\u5B9E\u4F8B\u5747\u662F\u53EF\u7528\u7684 redis.pool.testOnBorrow=true #\u6700\u5927\u5206\u914d\u7684\u5bf9\u8c61\u6570 redis.pool.maxActive=1024 #\u5f53\u8c03\u7528return Object\u65b9\u6cd5\u65f6\uff0c\u662f\u5426\u8fdb\u884c\u6709\u6548\u6027\u68c0\u67e5 redis.pool.testOnReturn=true
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" 4 xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" 5 xmlns:cache="http://www.springframework.org/schema/cache" 6 xsi:schemaLocation="http://www.springframework.org/schema/beans 7 http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 8 http://www.springframework.org/schema/context 9 http://www.springframework.org/schema/context/spring-context-3.2.xsd 10 http://www.springframework.org/schema/aop 11 http://www.springframework.org/schema/aop/spring-aop-3.2.xsd 12 http://www.springframework.org/schema/cache 13 http://www.springframework.org/schema/cache/spring-cache-3.2.xsd 14 http://www.springframework.org/schema/tx 15 http://www.springframework.org/schema/tx/spring-tx-3.2.xsd"> 16 <!-- 引入配置文件 --> 17 <context:property-placeholder location="classpath*:config/redis.properties" /> 18 <!-- 启用缓存注解功能,这个是必须的,否则注解不会生效,另外,该注解一定要声明在spring主配置文件中才会生效 --> 19 <!-- <cache:annotation-driven cache-manager="cacheManager" /> --> 20 <!-- spring自己的缓存管理器,这里定义了两个缓存位置名称 ,既注解中的value --> 21 <!-- <bean id="redisManager" class="org.springframework.cache.support.SimpleCacheManager"> --> 22 <!-- <property name="caches"> --> 23 <!-- <set> --> 24 <!-- <bean class="org.cpframework.cache.redis.RedisCache"> --> 25 <!-- <property name="redisTemplate" ref="redisTemplate" /> --> 26 <!-- <property name="name" value="default"/> --> 27 <!-- </bean> --> 28 <!-- <bean class="org.cpframework.cache.redis.RedisCache"> --> 29 <!-- <property name="redisTemplate" ref="redisTemplate02" /> --> 30 <!-- <property name="name" value="commonCache"/> --> 31 <!-- </bean> --> 32 <!-- </set> --> 33 <!-- </property> --> 34 <!-- </bean> --> 35 36 <!-- <bean id="redisCacheManager" class="com.pingan.haofang.service.impl.RedisCacheManger"> --> 37 <!-- <property name="pool" ref="shardedJedisPool" /> --> 38 <!-- </bean> --> 39 <!-- jedis 连接池配置 --> 40 <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig"> 41 <!-- <property name="maxActive" value="${redis.pool.maxActive}" /> --> 42 <!-- <property name="maxWait" value="${redis.pool.maxWait}" /> --> 43 <property name="maxTotal" value="${redis.pool.maxTotal}" /> 44 <property name="maxIdle" value="${redis.pool.maxIdle}" /> 45 <property name="maxWaitMillis" value="${redis.pool.maxWait}" /> 46 <property name="testOnBorrow" value="${redis.pool.testOnBorrow}" /> 47 </bean> 48 <!-- jedis 多个服务器配置 --> 49 <bean id="jedisShardInfo" class="redis.clients.jedis.JedisShardInfo"> 50 <constructor-arg index="0" value="${redis.host}" /> 51 <constructor-arg index="1" value="${redis.port}" type="int" /> 52 </bean> 53 <bean id="shardedJedisPool" class="redis.clients.jedis.ShardedJedisPool"> 54 <constructor-arg index="0" ref="jedisPoolConfig" /> 55 <constructor-arg index="1"> 56 <list> 57 <ref bean="jedisShardInfo" /> 58 </list> 59 </constructor-arg> 60 </bean> 61 62 <bean id="connectionFactory" 63 class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"> 64 <property name="hostName" value="${redis.host}" /> 65 <property name="port" value="${redis.port}" /> 66 <property name="password" value="${redis.password}" /> 67 <property name="poolConfig" ref="jedisPoolConfig" /> 68 <property name="shardInfo" ref="shardedJedisPool"></property> 69 </bean> 70 <!-- redis template definition --> 71 <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate" 72 p:connectionFactory-ref="connectionFactory" 73 p:keySerializer-ref="redisTemplateKeySerializer" 74 p:valueSerializer-ref="redisTemplateValueSerializer" 75 p:hashKeySerializer-ref="redisTemplateHashKeySerializer" 76 p:hashValueSerializer-ref="redisTemplateHashValueSerializer"/> 77 <bean id="redisTemplateKeySerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer" /> 78 <bean id="redisTemplateValueSerializer" class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" /> 79 <bean id="redisTemplateHashKeySerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer" /> 80 <bean id="redisTemplateHashValueSerializer" class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" /> 81 </beans>
1 package com.test.controller; 2 3 import org.springframework.beans.factory.annotation.Autowired; 4 import org.springframework.stereotype.Controller; 5 import org.springframework.web.bind.annotation.RequestMapping; 6 import org.springframework.web.bind.annotation.RequestMethod; 7 import com.test.service.impl.UsersServiceImpl; 8 import org.springframework.web.servlet.ModelAndView; 9 @Controller 10 public class IndexController { 11 @Autowired 12 UsersServiceImpl serv; 13 14 @RequestMapping(value="/index",method=RequestMethod.GET) 15 public ModelAndView getFirstPage() { 16 ModelAndView mv = new ModelAndView(); 17 mv.setViewName("index.ftl"); 18 mv.addObject("name", "王大锤"); 19 return mv; 20 } 21 22 }
1 package com.test.controller; 2 3 import java.util.List; 4 import org.springframework.beans.factory.annotation.Autowired; 5 import org.springframework.stereotype.Controller; 6 import org.springframework.ui.ModelMap; 7 import org.springframework.web.bind.annotation.RequestMapping; 8 import com.test.model.Users; 9 import com.test.service.IUsersService; 10 11 @Controller 12 public class UsersController { 13 14 @Autowired 15 private IUsersService usersService ; 16 17 @RequestMapping("/User/helloUser") 18 public String helloUser(ModelMap modelMap) { 19 List<Users> list = this.usersService.findAllUser(1); 20 modelMap.addAttribute("users", list) ; 21 return "/users_list"; 22 } 23 }
1 package com.test.dao; 2 3 import java.util.List; 4 import com.test.model.Users; 5 6 public interface UsersDao { 7 8 public List<Users> findAllUser(int id); 9 }
1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> 3 <mapper namespace="com.test.mappers.UsersDaoMapping"> 4 <resultMap type="UsersDao" id="com.test.model.Users" autoMapping="true"> 5 <result property="id" column="id" /> 6 <result property="username" column="account" /> 7 <result property="password" column="passwd" /> 8 </resultMap> 9 <select id="findAllUser" parameterType="int" resultType="UsersDao"> 10 SELECT * FROM Users WHERE id = #{id}; 11 </select> 12 </mapper> 13 /SpringMavenStudy/src/main/java/com/test/mappers/UsersDao.xml
1 package com.test.service.impl; 2 3 import java.util.List; 4 5 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.stereotype.Service; 7 import com.test.dao.UsersDao; 8 import com.test.model.Users; 9 import com.test.service.IUsersService; 10 11 @Service("UsersService") 12 public class UsersServiceImpl implements IUsersService{ 13 @Autowired 14 UsersDao userDao; 15 16 @Override 17 public List<Users> findAllUser(int id) { 18 return userDao.findAllUser(id); 19 } 20 21 22 }
<#setting classic_compatible=true> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>User List</title> <style type="text/css"> <!-- .STYLE1 { font-family: Arial, Helvetica, sans-serif; font-weight: bold; font-size: 36px; color: #FF0000; } .STYLE13 {font-size: 24} .STYLE15 {font-family: Arial, Helvetica, sans-serif; font-size: 24px; } --> </style> </head> <body> <table width="1500" height="600" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="500" height="200"> </td> <td width="500" height="200" align="center" valign="middle"><div align="center"><span class="STYLE1">User List </span></div></td> <td width="500" height="200"> </td> </tr> <tr> <td width="500" height="200"> </td> <td width="500" height="200"><table width="500" height="200" border="1" cellpadding="0" cellspacing="0"> <tr> <td width="160" height="65" align="center" valign="middle"><span class="STYLE15">ID</span></td> <td width="160" height="65" align="center" valign="middle"><span class="STYLE15">Username</span></td> <td width="160" height="65" align="center" valign="middle"><span class="STYLE15">Password</span></td> </tr> <#list users as user> <tr> <td width="160" height="65" align="center" valign="middle"><span class="STYLE15">${user.id}</span></td> <td width="160" height="65" align="center" valign="middle"><span class="STYLE15">${user.username}</span></td> <td width="160" height="65" align="center" valign="middle"><span class="STYLE15">${user.password}</span></td> </tr> </#list> </table></td> <td width="500" height="200"> </td> </tr> <tr> <td width="500" height="200"> </td> <td width="500" height="200"> </td> <td width="500" height="200"> </td> </tr> </table> </body> </html>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>模板页标题</title> </head> <body> 名字: ${name} </body> </html>
drop DATABASE test; CREATE DATABASE IF NOT EXISTS test DEFAULT CHARSET utf8 COLLATE utf8_general_ci; use test; -- mysql drop table if exists users; create table users -- ‘用户表‘ ( id integer primary key auto_increment comment ‘序号‘, -- ‘序号‘ account varchar(20) not null comment ‘姓名‘, -- ‘姓名‘ passwd varchar(20) not null comment ‘密码‘ -- ‘密码‘ )comment =‘用户表‘; insert into users(account,passwd) values ("张三", "警察"); insert into users(account,passwd) values ("李四", "销售"); insert into users(account,passwd) values ("王武", "工程师"); select * from users; /** -- 修改表的注释 alter table mytest.users comment ‘修改后的表的注释‘; -- 修改字段的注释 alter table mytest.users modify column id int comment ‘修改后的字段注释‘; -- ‘序号‘ alter table mytest.users modify column account varchar(20) not null comment ‘修改后的字段注释‘; -- ‘姓名‘ alter table mytest.users modify column passwd varchar(20) not null comment ‘修改后的字段注释‘; -- ‘密码‘ --注意:字段名和字段类型照写就行 **/
标签:
原文地址:http://www.cnblogs.com/asoks/p/5339456.html