效果图如下:

步骤如下:

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 实现最简单的数据展示功能的更多相关文章

  1. 零配置文件搭建SpringMVC实践纪录

    本篇记录使用纯java代码搭建SpringMVC工程的实践,只是一个demo.再开始之前先热身下,给出SpringMVC调用流程图,讲解的是一个http request请求到达SpringMVC框架后 ...

  2. 零配置简单搭建SpringMVC 项目

    SpringMVC是比较常用的JavaWeb框架,非常轻便强悍,能简化Web开发,大大提高开发效率,在各种Web程序中广泛应用.本文采用Java Config的方式搭建SpringMVC项目,并对Sp ...

  3. 手把手Maven搭建SpringMVC+Spring+MyBatis框架(超级详细版)

    手把手Maven搭建SpringMVC+Spring+MyBatis框架(超级详细版) SSM(Spring+SpringMVC+Mybatis),目前较为主流的企业级架构方案.标准的MVC设计模式, ...

  4. 脚手架快速搭建springMVC框架项目

    apid-framework脚手架快速搭建springMVC框架项目   rapid-framework介绍:   一个类似ruby on rails的java web快速开发脚手架,本着不重复发明轮 ...

  5. Maven 搭建SpringMvc+Spring+Mybatis详细记录

    总觉得,看比人写的总是那么好,每次搭建框架时都会找博客,找教程来跟着一步一步走,虽然很快搭建成功了,但是经常情况是我并不知道我干了什么,也不记得具体步骤,到底为什么要这么做,今天我详细记录了一下自己搭 ...

  6. Idea搭建SpringMVC框架(初次接触)

    公司转Java开发,做的第一个项目是SpringMVC框架,因为底层是同事封装,等完成整个项目,对SpringMVC框架的搭建还不是很了解,所以抽时间不忙的时候自己搭建了一个SpringMVC框架. ...

  7. 零配置文件搭建SpringMvc

    零配置文件搭建SpringMvc SpringMvc 流程原理 (1)用户发送请求至前端控制器DispatcherServlet:(2) DispatcherServlet收到请求后,调用Handle ...

  8. Maven搭建SpringMVC + SpringJDBC项目详解

    前言 上一次复习搭建了SpringMVC+Mybatis,这次搭建一下SpringMVC,采用的是SpringJDBC,没有采用任何其他的ORM框架,SpringMVC提供了一整套的WEB框架,所以如 ...

  9. Maven搭建SpringMVC+Hibernate项目详解 【转】

    前言 今天复习一下SpringMVC+Hibernate的搭建,本来想着将Spring-Security权限控制框架也映入其中的,但是发现内容太多了,Spring-Security的就留在下一篇吧,这 ...

随机推荐

  1. 【CF865C】Gotta Go Fast 二分+期望DP

    [CF865C]Gotta Go Fast 题意:有n个关卡需要依次通过,第i关有pi的概率要花ai时间通过,有1-pi的概率要花bi时间通过,你的目标是花费不超过m的时间通关,每一关开始时你都可以选 ...

  2. Unity性能优化之Draw Call(转)

    Unity(或者说基本所有图形引擎)生成一帧画面的处理过程大致可以这样简化描述:引擎首先经过简单的可见性测试,确定摄像机可以看到的物体,然后把这些物体的顶点(包括本地位置.法线.UV等),索引(顶点如 ...

  3. Unity3D笔记 愤怒的小鸟<二> 实现Play界面

    创建Play界面.能个把各个图片组合成一个场景,场景组成后背景能够不停的滚动,当鼠标单击时显示图片手型鼠标 一.GUI Texture 1.创建背景.地面.树木.草 ,这里注意Z轴的排序,一层一层则第 ...

  4. 利用bat批处理做启动mongodb脚本

    文章开始,我们先回顾一下,如何用cmd命令窗口开启mongodb数据库,命令如下: 开启mongodb数据库 cd D:\Program Files\MongoDB\bin mongod --depa ...

  5. vue--拖动排序

    https://blog.csdn.net/jx950915/article/details/79803485?from=singlemessage

  6. Flask详解

    Flask是一个基于Python开发并且依赖jinja2模板和Werkzeug WSGI服务的一个微型框架,对于Werkzeug本质是Socket服务端,其用于接收http请求并对请求进行预处理,然后 ...

  7. PHP中有丰富的运算符集,它们中大部分直接来自于C语言

    PHP中有丰富的运算符集,它们中大部分直接来自于C语言.按照不同功能区分,运算符可以分为:算术运算符.字符串运算符.赋值运算符.位运算符.条件运算符,以及逻辑运算符等.当各种运算符在同一个表达式中时, ...

  8. 从UE(用户体验)到道家誓学再到李小龙

    公司大Boss经常会给我做技术培训,感觉他什么都知道,也挺喜欢听他的课. 本文记录可能比较天马行空,我的语文比较差,很难把自己想表达的说出来,为此我就是记录一样关键字,可能这样还会更好些 背景是讲用户 ...

  9. Freemarker 基本数据类型

    一 数据类型简介 freemarker 模板中的数据类型由如下几种: 1. 布尔型:等价于java中的boolean类型, 不同的是不能直接输出,可以转换成字符串再输出 2. 日期型:等价于java中 ...

  10. CCCC训练赛一些模板 struct sstream

    重载与构造 struct node { friend bool operator< (node n1, node n2) { return n1.priority > n2.priorit ...