使用IDEA 搭建SpringMVC +Easyui 实现最简单的数据展示功能
效果图如下:

步骤如下:
1、导入jquery-easyui-1.5.5.6
2、导入相关的SpringMVC 的jar 包

3、编写datagrid.jsp 页面
<%--
Created by IntelliJ IDEA.
User: lenovo
Date: 2019/2/9
Time: 18:08
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/jquery-easyui-1.5.5.6/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/jquery-easyui-1.5.5.6/themes/icon.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/jquery-easyui-1.5.5.6/demo.css">
<script type="text/javascript" src="${pageContext.request.contextPath}/jquery-easyui-1.5.5.6/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/jquery-easyui-1.5.5.6/jquery.easyui.min.js"></script>
</head>
<body> <table class="easyui-datagrid" title="水果列表" style="width:700px;height:250px"
data-options="singleSelect:true,collapsible:true,url:'${pageContext.request.contextPath}/searchByName.action',method:'get'">
<thead>
<tr>
<th data-options="field:'name',width:80">水果名称</th>
<th data-options="field:'price',width:100">单价</th> </tr>
</thead>
</table>
</body>
</html>
4、编写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_4_0.xsd"
version="4.0"> <!--springMVC 前端控制器-->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping> </web-app>
5、编写springmvc.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:mvc="http://www.springframework.org/schema/mvc"
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/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"
>
<!--MVC:annotation-diver: 这个标签的作用是起到:自动注册:
处理器映射器和处理器适配器
-->
<mvc:annotation-driven/> <!-- 返回json 方法一 需要导入 fastjson.jar包 -->
<mvc:annotation-driven>
<mvc:message-converters register-defaults="false">
<!-- 避免IE执行AJAX时,返回JSON出现下载文件 -->
<bean id="fastJsonHttpMessageConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<!-- 这里顺序不能反,一定先写text/html,不然ie下出现下载提示 -->
<value>text/html;charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven> <!--配置视图解析器-->
<!--<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"/>-->
<bean
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
<property name="viewClass" value="org.springframework.web.servlet.view.InternalResourceView"/>
</bean> <!--扫描controlelr 所在的包,这样 处理器映射器才可以找到 handler-->
<context:component-scan base-package="controller"></context:component-scan> </beans>

这段代码的作用是:因为SpringMVC 没有默认的转换器,需要配置,而且使用Easyui 需要的返回类型也是json类型的格式,所以要加上这段,可以参考下面的这个博客
https://my.oschina.net/haopeng/blog/324934

6、编写:oneController.java
package controller; import net.sf.json.JSON;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import po.FruitEntity;
import service.FruitService; import java.util.HashMap;
import java.util.List;
import java.util.Map; /**
* @author 王立朝
* @version 1.0
* @description controller
* @date 2019/2/2
**/ @Controller
public class oneController {
//根据水果名称查询
@RequestMapping("/searchByName")
@ResponseBody
public Map<String, Object> searchByName(ModelAndView modelAndView) {
Map<String, Object> result = new HashMap<String, Object>();
List<FruitEntity> fruitEntityList = fruitService.getFruit();
result.put("total", fruitEntityList.size());
result.put("rows", fruitEntityList);return result;
} }
7、编写实体类FruitEntity.java
package po; /**
* @author 王立朝
* @version 1.0
* @description 水果实体类
* @date 2019/2/2
**/
public class FruitEntity {
//水果名称
private String name ;
//单价
private String price ; public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getPrice() {
return price;
} public void setPrice(String price) {
this.price = price;
} public FruitEntity(String name, String price) { this.name = name;
this.price = price;
} public FruitEntity() {
}
}
8、编写FruitService.java
package service; import po.FruitEntity; import java.util.ArrayList;
import java.util.List; /**
* @author 王立朝
* @version 1.0
* @description service
* @date 2019/2/2
**/
public class FruitService { public List<FruitEntity> getFruit(){
List<FruitEntity> fruitEntityList = new ArrayList<FruitEntity>();
FruitEntity fruitEntity = new FruitEntity();
fruitEntity.setName("苹果");
fruitEntity.setPrice("20");
FruitEntity fruitEntity2 = new FruitEntity();
fruitEntity2.setName("香蕉");
fruitEntity2.setPrice("20");
FruitEntity fruitEntity3 = new FruitEntity();
fruitEntity3.setName("柠檬");
fruitEntity3.setPrice("20");
FruitEntity fruitEntity4 = new FruitEntity();
fruitEntity4.setName("葡萄");
fruitEntity4.setPrice("20");
FruitEntity fruitEntity5 = new FruitEntity();
fruitEntity5.setName("橘子");
fruitEntity5.setPrice("20"); fruitEntityList.add(fruitEntity);
fruitEntityList.add(fruitEntity2);
fruitEntityList.add(fruitEntity3);
fruitEntityList.add(fruitEntity4);
fruitEntityList.add(fruitEntity5);
return fruitEntityList;
}
}
这个项目的完整下载地址
网盘地址:
链接:https://pan.baidu.com/s/1M29uJP-sGFpso41OVYdfKw
提取码:wyo0
使用IDEA 搭建SpringMVC +Easyui 实现最简单的数据展示功能的更多相关文章
- 零配置文件搭建SpringMVC实践纪录
本篇记录使用纯java代码搭建SpringMVC工程的实践,只是一个demo.再开始之前先热身下,给出SpringMVC调用流程图,讲解的是一个http request请求到达SpringMVC框架后 ...
- 零配置简单搭建SpringMVC 项目
SpringMVC是比较常用的JavaWeb框架,非常轻便强悍,能简化Web开发,大大提高开发效率,在各种Web程序中广泛应用.本文采用Java Config的方式搭建SpringMVC项目,并对Sp ...
- 手把手Maven搭建SpringMVC+Spring+MyBatis框架(超级详细版)
手把手Maven搭建SpringMVC+Spring+MyBatis框架(超级详细版) SSM(Spring+SpringMVC+Mybatis),目前较为主流的企业级架构方案.标准的MVC设计模式, ...
- 脚手架快速搭建springMVC框架项目
apid-framework脚手架快速搭建springMVC框架项目 rapid-framework介绍: 一个类似ruby on rails的java web快速开发脚手架,本着不重复发明轮 ...
- Maven 搭建SpringMvc+Spring+Mybatis详细记录
总觉得,看比人写的总是那么好,每次搭建框架时都会找博客,找教程来跟着一步一步走,虽然很快搭建成功了,但是经常情况是我并不知道我干了什么,也不记得具体步骤,到底为什么要这么做,今天我详细记录了一下自己搭 ...
- Idea搭建SpringMVC框架(初次接触)
公司转Java开发,做的第一个项目是SpringMVC框架,因为底层是同事封装,等完成整个项目,对SpringMVC框架的搭建还不是很了解,所以抽时间不忙的时候自己搭建了一个SpringMVC框架. ...
- 零配置文件搭建SpringMvc
零配置文件搭建SpringMvc SpringMvc 流程原理 (1)用户发送请求至前端控制器DispatcherServlet:(2) DispatcherServlet收到请求后,调用Handle ...
- Maven搭建SpringMVC + SpringJDBC项目详解
前言 上一次复习搭建了SpringMVC+Mybatis,这次搭建一下SpringMVC,采用的是SpringJDBC,没有采用任何其他的ORM框架,SpringMVC提供了一整套的WEB框架,所以如 ...
- Maven搭建SpringMVC+Hibernate项目详解 【转】
前言 今天复习一下SpringMVC+Hibernate的搭建,本来想着将Spring-Security权限控制框架也映入其中的,但是发现内容太多了,Spring-Security的就留在下一篇吧,这 ...
随机推荐
- 语音AT命令参考
不知道 这AT指令是不是通用的,尝试过的给我个回复 语音命令 命令 描述 +FCLASS=8 进入语音模式.AT+FCLASS=8 将调制解调器置入语音模式.扩音电话和TAM模式包括在通用语音模式中, ...
- npm publish 发布
前言 我们npm publish发布的时候,一定是本地文件发布到远程仓库,并且登录到http://registry.npmjs.org(即npm adduser或npmlogin)之后,才可以进行发布 ...
- R子集subset
> x<-c(6,1,2,3,NA,12) > x[x>5] #x[5]是未知的,因此其值是否大于5也是未知的 [1] 6 NA 12 > subset(x,x& ...
- 8.22js前端!
2018-8-22 19:15:19 前端还有一部分就学完了预计这一星期赶一下就可以结束 然后愉快地进行Django框架!!!! 今天中午和呆呆一块吃的大盘鸡,下午和老表我们三个去了日月湖狼了一下午! ...
- 7.22 python线程(3)
2018-7-22 10:28:29 回来啦! 6.条件 # !/usr/bin/env python # !--*--coding:utf-8 --*-- # !@Time :2018/7/20 1 ...
- ELK之nginx日志使用json格式输出
json Nginx默认日志输出格式为文本非json格式,修改配置文件即可输出json格式便于收集以及绘图 修改nginx配置文件添加配置,增加一个json输出格式的日志格式 log_format a ...
- hdu 6395Sequence【矩阵快速幂】【分块】
Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total ...
- 用纯css实现下拉菜单的几种方式
第一种:display:none和display:block切换 <!DOCTYPE html> <html lang="en"> <head> ...
- Linux执行Cron Job失败,在Shell sh下执行却能成功 - 环境变量?
博客分类: Linux linuxcrontabpermissionetc/profile环境变量 一.我们常常碰到在shell下执行某个命令能够成功,比如执行一个java程序: java -jar ...
- 用SCSS需要小心IE对css的几个限制
IE对CSS的限制主要有两个: 一个页面中引用的CSS只读前32个 一个CSS文件中只读前4095个选择器 关于这个问题的文章有很多,我就不细讲了. 我想讲的是在用SCSS写CSS的时候非常容易超过这 ...