因为EasyUI会涉及到与后台数据的交互,所以使用Spring MVC作为后台,搭建一个完整的Web环境

使用gradle作为构建工具

build.gradle

 group 'org.zln.lkd'
version '1.0-SNAPSHOT' apply plugin: 'jetty' sourceCompatibility = 1.8 repositories {
mavenLocal()
mavenCentral()
} dependencies {
compile(
"org.slf4j:slf4j-api:1.7.21",
"org.apache.logging.log4j:log4j-slf4j-impl:2.7",
"org.apache.logging.log4j:log4j-core:2.7",
"org.apache.logging.log4j:log4j-api:2.7",
"org.apache.commons:commons-lang3:3.3.2",
"org.springframework:spring-context:4.3.1.RELEASE",
"org.springframework:spring-aop:4.3.1.RELEASE",
"org.springframework:spring-core:4.3.1.RELEASE",
"org.springframework:spring-expression:4.3.1.RELEASE",
"org.springframework:spring-beans:4.3.1.RELEASE",
"org.springframework:spring-webmvc:4.3.1.RELEASE",
"org.springframework:spring-web:4.3.1.RELEASE",
"org.springframework:spring-jdbc:4.3.1.RELEASE",
"org.springframework:spring-tx:4.3.1.RELEASE",
"org.springframework:spring-test:4.3.1.RELEASE",
"org.springframework:spring-aspects:4.3.1.RELEASE",
"mysql:mysql-connector-java:5.1.32",
"com.alibaba:druid:1.0.9",
"org.mybatis:mybatis:3.4.1",
"org.mybatis:mybatis-spring:1.3.0",
"com.github.pagehelper:pagehelper:4.1.6",
"javax.servlet:javax.servlet-api:4.0.0-b01",
"jstl:jstl:1.2",
"com.fasterxml.jackson.core:jackson-databind:2.8.1"
) testCompile(
"junit:junit:4.12"
)
} // 自动创建好src目录 包括源码与测试源码
task mkdirs << {
sourceSets*.java.srcDirs*.each { it.mkdirs() }
sourceSets*.resources.srcDirs*.each { it.mkdirs() }
} // 显示当前项目下所有用于 compile 的 jar.
task listJars(description: 'Display all compile jars.') << {
configurations.compile.each { File file -> println file.name }
}

build.gradle

web.xml

 <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1"> <!--过滤器设置请求编码-->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list> </web-app>

web.xml

Spring初始化

AppInit.java

 package conf.spring;

 import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

 /**
* Spring初始化类
* Created by sherry on 16/11/28.
*/
public class AppInit extends AbstractAnnotationConfigDispatcherServletInitializer { /**
* Spring后台配置类
* @return
*/
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[]{AppRootConf.class};
} /**
* Spring MVC配置类
* @return
*/
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[]{AppServletConf.class};
} /**
* 拦截地址呗Spring MVC处理
* @return
*/
@Override
protected String[] getServletMappings() {
return new String[]{"*.json","*.html","*.do","*.action","*.ajax"};
}
}

AppInit.java

AppRootConf.java

 package conf.spring;

 import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.annotation.ImportResource;
import org.springframework.web.servlet.config.annotation.EnableWebMvc; /**
* Created by sherry on 16/11/28.
*/
@Configuration
//排除Spring MVC注解类
@ComponentScan(basePackages = {"org.zln"}, excludeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, value = EnableWebMvc.class)})
@ImportResource("classpath:applicationContext.xml")
public class AppRootConf {
}

AppRootConf.java

AppServletConf.java

 package conf.spring;

 import org.springframework.context.annotation.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView; /**
* Created by sherry on 16/11/28.
*/
@Configuration
//开启MVC支持,同 <mvc:annotation-driven>
@EnableWebMvc
//仅扫描Controller注解的类
@ComponentScan(value = "org.zln",useDefaultFilters = false,includeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION,value = Controller.class)})
@ImportResource("classpath:applicationContext-mvc.xml")
public class AppServletConf extends WebMvcConfigurerAdapter { /**
* 配置JSP视图解析器
* @return
*/
@Bean
public ViewResolver viewResolver(){
InternalResourceViewResolver resourceViewResolver = new InternalResourceViewResolver();
resourceViewResolver.setPrefix("/WEB-INF/jsp/");
resourceViewResolver.setSuffix(".jsp");
//JstlView表示JSP模板页面需要使用JSTL标签库,classpath中必须包含jstl的相关jar包;
resourceViewResolver.setViewClass(JstlView.class);
resourceViewResolver.setExposeContextBeansAsAttributes(true);
return resourceViewResolver;
} /**
* 配置静态资源的处理:要求DispatcherServlet将对静态资源的请求转发到Servlet容器默认的Servlet上,
* 而不是使用DispatcherServlet本身来处理
* @param configurer
*/
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
} }

AppServletConf.java

配置文件

 <?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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd"> </beans>

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"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">
<!--静态资源-->
<mvc:resources mapping="/css/**" location="/WEB-INF/css/"/> <!--<bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">-->
<!--<property name="supportedMediaTypes">-->
<!--<list>-->
<!--<value>text/html;charset=UTF-8</value>-->
<!--</list>-->
<!--</property>-->
<!--</bean>-->
<!--<bean id="formHttpMessageConverter" class="org.springframework.http.converter.FormHttpMessageConverter"></bean>--> <!--<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">-->
<!--<property name="messageConverters">-->
<!--<list>-->
<!--<ref bean="formHttpMessageConverter"/>-->
<!--<ref bean="mappingJacksonHttpMessageConverter"/>-->
<!--</list>-->
<!--</property>-->
<!--</bean>-->
</beans>

applicationContext-mvc.xml

 <?xml version="1.0" encoding="UTF-8"?>
<configuration status="OFF">
<!--appenders配置输出到什么地方-->
<appenders>
<!--Console:控制台-->
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</appenders> <loggers>
<!--建立一个默认的root的logger-->
<root level="trace">
<appender-ref ref="Console"/>
</root>
</loggers>
</configuration>

log4j2.xml

搭建一个Web应用的更多相关文章

  1. 搭建一个web服务下载HDFS的文件

    需求描述 为了能方便快速的获取HDFS中的文件,简单的搭建一个web服务提供下载很方便快速,而且在web服务器端不留临时文件,只做stream中转,效率相当高! 使用的框架是SpringMVC+HDF ...

  2. 搭建一个Web Server站点

    题:搭建一个Web Server站点.安装web服务,并在本地创建index.html测试 1.安装http服务 yum -y install httpd 2.进入网站目录 cd /var/www/h ...

  3. 如何搭建一个WEB服务器项目(二)—— 对数据库表进行基本的增删改查操作

    使用HibernateTemplate进行增删改查操作 观前提示:本系列文章有关服务器以及后端程序这些概念,我写的全是自己的理解,并不一定正确,希望不要误人子弟.欢迎各位大佬来评论区提出问题或者是指出 ...

  4. Spring Boot(一):如何使用Spring Boot搭建一个Web应用

    Spring Boot Spring Boot 是Spring团队旗下的一款Web 应用框架 其优势可以更快速的搭建一个Web应用 从根本上上来讲 Spring Boot并不是什么新的框架技术 而是在 ...

  5. 搭建一个Web API项目(DDD)

    传送阵:写在最后 一.创建一个能跑的起来的Web API项目 1.建一个空的 ASP.NET Web应用 (为什么不直接添加一个Web API项目呢,那样会有些多余的内容(如js.css.Areas等 ...

  6. 用Python手把手教你搭建一个web框架-flask微框架!

    在之前的文章当中,小编已经教过大家怎么搭建一个Django框架,今天我们来探索另外的一种框架的搭建,这个框架就是web框架-flask微框架啦!首先我们带着以下的几个问题来阅读本文: 1.flask是 ...

  7. MyBatis整合Spring+SpringMVC搭建一个web项目(SSM框架)

    本文讲解如何搭建一个SSM架构的web站点 [工具] IDEA.SqlYog.Maven [简述] 该项目由3个模块组成:dao(数据访问层).service(业务处理层).web(表现层) dao层 ...

  8. 使用Maven+ssm框架搭建一个web项目

    1,前期准备:Eclipse(Mars.2 Release (4.5.2)).jdk1.7.tomcat7.maven3.2.1 2.使用eclipse中的maven新建一个web项目 点击next: ...

  9. 1.SpringBoo之Helloword 快速搭建一个web项目

    背景: Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配 ...

随机推荐

  1. MySQL到MsSQL的迁移工具——SSMA

    SQL Server迁移助手(SSMA)团队开发了针对MySQL的迁移助手Microsoft SQL Server Migration Assistant 2008 for MySQL.微软同时发布了 ...

  2. ubuntu下安装程序的三种方法

    引言 在ubuntu当中,安装应用程序我所知道的有三种方法,分别是apt-get,dpkg安装deb和make install安装源码包三种.下面针对每一种方法各举例来说明. apt-get方法 使用 ...

  3. iOS 视频播放 - YVideoPlayer - UIView

    这是一个使用简便的视频播放框架,它基于UIView,它可以是一个小窗口,也可以是一个全屏的窗口 简单的方式加载Video框架: 一行代码加载! 一行代码更新! 下载链接 : https://githu ...

  4. UITabBarItem的selectedImage

    TabBar使用频率很高的一个组件,TabBar的TabBarItem有两个属性一个是image(未选中图片),另一个是selectedImage(选中时图片) 但是运行时发现,选中时的图片变成了蓝色 ...

  5. 【读书笔记】iOS-内存管理

    Cocoa的内存管理:retain,release和autorelease. 每个对象都维护一个保留计数器.对象被创建时,其保留计数器值为1:对象被保留时,保留计数器值加1:对象被释放时,保留计数器值 ...

  6. iOS--开发之手势解锁

    本文主要介绍通过手势识别实现手势解锁功能,这个方法被广泛用于手机解锁,密码验证,快捷支付等功能实现.事例效果如下所示. 首先,我们先分析功能的实现过程,首先我们需要先看大致的实现过程: 1.加载九宫格 ...

  7. Web应用程序系统的多用户权限控制设计及实现-登录模块【4】

    通过前三个模块的介绍,把web权限系统开发所需要的基本类,Css文件,EasyUI框架等准备好后,就可以着手开始系统的编码了. 登陆模块是权限处理系统的关键,根据输入用户的的信息,可自动从数据库中加载 ...

  8. jquery miniui , 普加甘特图,流程管理

    http://www.miniui.com/docs/quickstart/index.html 普加 甘特图 流程管理 http://www.plusgantt.com/project/demo/P ...

  9. Maven&&Ant使用

    “使用操作系统环境为CentOS-6.5” Ant使用 Maven使用 “Maven是一个项目管理和综合工具.Maven提供了开发人员构建一个完整的生命周期框架.开发团队可以自动完成项目的基础工具建设 ...

  10. PHP读写XML文件的四种方法

    PHP对XML文件进行读写操作的方法一共有四种,分别是:字符串方式直接读写.DOMDocument读写. XMLWrite写和XMLReader读.SimpleXML读写,本文将依次对这四种方法进行介 ...