流程 :
首先写出一个简单的前端页面。
之后写配置文件、dao、domain等等,注意这里可以使用generator进行自动配置
实验室这边配置文件如下:
其实主要的配置文件就分为6“个”。
applicationContext.xml与app-biz.xml、app-data.xml、esconnect.properties是一个。
generatorConfig是一个。
log4j.properties是一个。
sqlMapConfig是一个。
web.xml是一个。
com.cfWeb.mapping下面的全部xml文件都可以算一个。
先做好前端,现在它的配置文件都是空的。
出现页面后,修改pom文件,maven install
<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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.spring</groupId> <artifactId>LoginTest</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>LoginTest Maven Webapp</name> <url>http://maven.apache.org</url> <properties> <spring.version>3.2.2.RELEASE</spring.version> <resteasy.version>3.0.5.Final</resteasy.version> <log4j.version>1.2.17</log4j.version> <mybatis.spring.version>1.2.0</mybatis.spring.version> <mybatis.version>3.2.2</mybatis.version> </properties> <dependencies> <!-- log begin --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>${log4j.version}</version> </dependency> <!-- log end --> <!-- mybatis begin --> <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> <exclusions> <exclusion> <artifactId>spring-jdbc</artifactId> <groupId>org.springframework</groupId> </exclusion> <exclusion> <artifactId>spring-tx</artifactId> <groupId>org.springframework</groupId> </exclusion> </exclusions> </dependency> <!-- mybatis end --> <!-- spring begin --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> </dependency> <!-- spring end --> <!--resteasy begin --> <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-spring</artifactId> <version>${resteasy.version}</version> <exclusions> <exclusion> <artifactId>resteasy-jettison-provider</artifactId> <groupId>org.jboss.resteasy</groupId> </exclusion> <exclusion> <artifactId>jsr250-api</artifactId> <groupId>javax.annotation</groupId> </exclusion> <exclusion> <artifactId>jaxrs-api</artifactId> <groupId>org.jboss.resteasy</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-multipart-provider</artifactId> <version>${resteasy.version}</version> </dependency> <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-jackson-provider</artifactId> <version>${resteasy.version}</version> </dependency> <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-jaxrs</artifactId> <version>${resteasy.version}</version> <exclusions> <exclusion> <artifactId>httpclient</artifactId> <groupId>org.apache.httpcomponents</groupId> </exclusion> </exclusions> </dependency> <!-- <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-spring</artifactId> <version>${resteasy.version}</version> </dependency> <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-multipart-provider</artifactId> <version>${resteasy.version}</version> </dependency> --> <!--resteasy end --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.19</version> </dependency> <dependency> <groupId>c3p0</groupId> <artifactId>c3p0</artifactId> <version>0.9.1.1</version> </dependency> <dependency> <groupId>cglib</groupId> <artifactId>cglib</artifactId> <version>2.2</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjtools</artifactId> <version>1.7.2</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.9</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <scope>provided</scope> </dependency> <!-- json begin--> <dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib</artifactId> <version>2.4</version> <classifier>jdk15</classifier> </dependency> <!-- json end --> <!--test begin --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> <scope>test</scope> </dependency> </dependencies> <build> <finalName>LoginTest</finalName> </build> </project>
之后首先修改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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <context-param> <param-name>resteasy.servlet.mapping.prefix</param-name> <param-value>/rest</param-value> </context-param> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>classpath:log4j.properties</param-value> </context-param> <listener> <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class> </listener> <listener> <listener-class>org.jboss.resteasy.plugins.spring.SpringContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>RestEasy</servlet-name> <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class> </servlet> <servlet-mapping> <servlet-name>RestEasy</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> <!-- 编码 --> <filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
之后修改applicationContext.xml文件,将其改为
<?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" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"> <context:component-scan base-package="com.LoginTest" /> </beans>
顺便将log4j.properties修改为
log4j.rootLogger=INFO,infoLog,errorLog,console
log4j.appender.errorLog = org.apache.log4j.DailyRollingFileAppender
log4j.appender.errorLog.File = ../appLogs/cfWeb_error.log
log4j.appender.errorLog.Append = true
log4j.appender.errorLog.Threshold = ERROR
log4j.appender.errorLog.DatePattern='.'yyyy-MM-dd
log4j.appender.errorLog.layout=org.apache.log4j.PatternLayout
log4j.appender.errorLog.layout.ConversionPattern=[%d{yyyy-MM-dd HH:mm:ss}] %c{1}.%t - %-5p - method:%l%n%m%n
log4j.appender.infoLog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.infoLog.File= ../appLogs/cfWeb_info.log
log4j.appender.infoLog.Threshold = INFO
log4j.appender.infoLog.DatePattern='.'yyyy-MM-dd
log4j.appender.infoLog.layout=org.apache.log4j.PatternLayout
log4j.appender.infoLog.layout.ConversionPattern=[%d{yyyy-MM-dd HH:mm:ss}] %c{1}.%t - %-5p - method:%l%n%m%n
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%5p [%t] (%F:%L) %d{HH:mm:ss,SSS} -- %m%n
剩下的配置文件都是为空。
在这个过程中会遇到很多常见问题,看看properties 的deployment Assembly是否添加了maven包,java buildpath是否添加了maven包,等等。
于是run on server会出现下面这样的结果
之后就存在两个需要解决的问题(顺序需要考虑):
1、如何使用mybatis自动加入数据
2、前端与后台如何进行交互