效果图如下:

步骤如下:

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. 盘古分词修改支持mono和lucene.net3.03

    盘古分词平台兼容性 在使用Lucece.net,需要一个中文的分词组件,比较好的是盘古分词,但是我希望能够在mono的环境下运行,就使用moma检查了一下盘古分词 Assembly Version M ...

  2. Android Popup Window 居于控件上方突出显示

    public class TestPopupWindowActivity extends PopupWindow { Activity context; public TestPopupWindowA ...

  3. 在sublime中安装使用TortoiseSVN-sublime使用心得(4)

    通过sublime text 2.0 安装 TortoiseSVN 插件. 和其它插件不同的是,安装成功后,重启sublime text 2.0 ,在Preferences->Package S ...

  4. php base64转图片

    1.解析base64数据成图片 The problem is that data:image/bmp;base64, is included in the encoded contents. This ...

  5. JavaEE Cookie HttpSession 学习笔记

    1. 会话管理概述 1.1 什么是会话 好比一次通话.打开浏览器,点击多次链接(发出多次请求和收到多次的响应),关闭浏览器,这个过程就是一次会话. 有功能 可以  文件 新建会话 1.2 解决的问题是 ...

  6. 【vue】---项目接口管理---【巷子】

    一.前言 在vue开发中,会涉及到很多接口的处理,当项目足够大时,就需要定义规范统一的接口 假设后端的文档分成了以下几个模块 1.发现模块 2.个人信息模块 3.商品模块 4.评论模块 ...... ...

  7. POJ-1926 Pollution

    Pollution Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 4049 Accepted: 1076 Description ...

  8. HDU 6441 - Find Integer - [费马大定理][2018CCPC网络选拔赛第4题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6441 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

  9. oracle union 用法

    [sql] view plaincopyprint?众所周知的几个结果集集合操作命令,今天详细地测试了一下,发现一些问题,记录备考. 假设我们有一个表Student,包括以下字段与数据: drop t ...

  10. Linux:获取当前进程的执行文件的绝对路径

    摘要:本文介绍Linux的应用程序和内核模块获取当前进程执行文件绝对路径的实现方法. 注意:使用此方法时,如果执行一个指向执行文件的链接文件,则获得的不是链接文件的绝对路径,而是执行文件的绝对路径. ...