搭建一个Web应用
因为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应用的更多相关文章
- 搭建一个web服务下载HDFS的文件
需求描述 为了能方便快速的获取HDFS中的文件,简单的搭建一个web服务提供下载很方便快速,而且在web服务器端不留临时文件,只做stream中转,效率相当高! 使用的框架是SpringMVC+HDF ...
- 搭建一个Web Server站点
题:搭建一个Web Server站点.安装web服务,并在本地创建index.html测试 1.安装http服务 yum -y install httpd 2.进入网站目录 cd /var/www/h ...
- 如何搭建一个WEB服务器项目(二)—— 对数据库表进行基本的增删改查操作
使用HibernateTemplate进行增删改查操作 观前提示:本系列文章有关服务器以及后端程序这些概念,我写的全是自己的理解,并不一定正确,希望不要误人子弟.欢迎各位大佬来评论区提出问题或者是指出 ...
- Spring Boot(一):如何使用Spring Boot搭建一个Web应用
Spring Boot Spring Boot 是Spring团队旗下的一款Web 应用框架 其优势可以更快速的搭建一个Web应用 从根本上上来讲 Spring Boot并不是什么新的框架技术 而是在 ...
- 搭建一个Web API项目(DDD)
传送阵:写在最后 一.创建一个能跑的起来的Web API项目 1.建一个空的 ASP.NET Web应用 (为什么不直接添加一个Web API项目呢,那样会有些多余的内容(如js.css.Areas等 ...
- 用Python手把手教你搭建一个web框架-flask微框架!
在之前的文章当中,小编已经教过大家怎么搭建一个Django框架,今天我们来探索另外的一种框架的搭建,这个框架就是web框架-flask微框架啦!首先我们带着以下的几个问题来阅读本文: 1.flask是 ...
- MyBatis整合Spring+SpringMVC搭建一个web项目(SSM框架)
本文讲解如何搭建一个SSM架构的web站点 [工具] IDEA.SqlYog.Maven [简述] 该项目由3个模块组成:dao(数据访问层).service(业务处理层).web(表现层) dao层 ...
- 使用Maven+ssm框架搭建一个web项目
1,前期准备:Eclipse(Mars.2 Release (4.5.2)).jdk1.7.tomcat7.maven3.2.1 2.使用eclipse中的maven新建一个web项目 点击next: ...
- 1.SpringBoo之Helloword 快速搭建一个web项目
背景: Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配 ...
随机推荐
- SAP技术相关Tcode
ABAP的常用tcode 开发----------------------------------------------- SE51 屏幕制作 SE91 MESSAGE OBJECT SE80 ...
- thinkPHP学习笔记(2)
1.调试模式 设置调试模式部分代码如下: <?php define('APP_DEBUG',TRUE); // 开启调试模式 常量定义代码 require '/ThinkPHP框架所在目录/Th ...
- Sizing and Capacity Planning for SharePoint 2013 - Resources
http://blogs.msdn.com/b/sanjaynarang/archive/2013/04/06/sizing-and-capacity-planning-for-sharepoint- ...
- Opengles 管线编程介绍
OpenGL ES 2.0可编程管道 上图橙色部分(Vertex Shader和Fragment Shader)为此管道的可编程部分.整个管道包含以下两个规范: 1) OpenGL ...
- c++ const用法小结
const用法 1,定义全局变量的内存分配问题 #define Pi_1 3.14 //使用#define宏 const double Pi_2 = 3.14 //使用const ...
- C++pair类型
标准库类型--pair类型定义在utility头文件中定义 本文地址:http://www.cnblogs.com/archimedes/p/cpp-pair.html,转载请注明源地址. 1.pai ...
- android拍照选择图片上传服务器自定义控件
做android项目的时候总免不了遇到图片上传功能,虽然就是调用android系统的拍照和相册选择功能,但是总面部了把一大推代码写在activity里,看上去一大推代码头都昏了.不如把这些功能都集成一 ...
- iOS 中 CAShapeLayer 的使用( 等待删除的博文)
等待删除. 1.CAShapeLayer 简介 1.CAShapeLayer继承至CALayer,可以使用CALayer的所有属性值 2.CAShapeLayer需要与贝塞尔曲线配合使用才有意义 3. ...
- Xcode 文件删除拷贝 出现的问题
当删除一个组的时候,不管是下面的两个选择,是彻底删除还是不彻底: 然后又要往工程里拷贝进去 同名 文件组,最好是选择Creat groups (因为创建groups就不会有import的时候,还需 ...
- XP重装之后蓝屏
最近帮公司的电脑重装XP系统,发现重装之后电脑重启的时候蓝屏 解决方法:开机-->f2-->找到SATA Configration --> 选择ide 重启,就ok了