使用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的就留在下一篇吧,这 ...
随机推荐
- 什么是webpack?
https://www.webpackjs.com/concepts/ https://webpack.github.io/ 本质上,webpack 是一个现代 JavaScript 应用程序的静态模 ...
- Android系统dimension单位详解
转载请注明出处,谢谢!http://www.cnblogs.com/coding-way/p/3457878.html Android设备种类多样,要想适配好各种屏幕,理解各种屏幕数据是必须的.首先先 ...
- [转][darkbaby]任天堂传——失落的泰坦王朝(下)
即使是日本业界人士也对1999年发生的“口袋妖怪所有权风波”知之甚少,实际上这个事件的结局足以改变游戏产业未来数十年的势力图,山内溥凭借着个人的睿智让任天堂再次渡过了命运的暗礁,而另一颗曾经炙手可热的 ...
- MySQL行列转换拼接
mysql> select TBL_ID,CREATE_TIME,LAST_ACCESS_TIME,TBL_NAME,TBL_TYPE from TBLS; +--------+-------- ...
- opengl学习笔记(二):使用OpenCV来创建OpenGL窗口
通常的增强现实应用需要支持OpenGL的OpenCV来对真实场景进行渲染.从2.4.2版本开始,OpenCV在可视化窗口中支持OpenGL.这意味着在OpenCV中可轻松渲染任何3D内容. 若要在Op ...
- MySQL在windows下的noinstall安装
1.解压mysql zip软件包 2.配置环境变量 3.修改配置文件my_default.ini添加如下: [mysqld] basedir=D:\MySQL\MySQL Server 5.6(mys ...
- iOS耳机等音频输出设备切换的通知
#import "ViewController.h" #import <AVFoundation/AVFoundation.h> @interface ViewCont ...
- 批量转换gbk编码的java代码为utf8
#!/bin/bash echo $1 echo $# if [ ! $# -eq 1 ]; then echo "usage: ./gbk2utf8.sh src" ...
- 使用Intel IPT技术保护您的帐号安全
使用Intel IPT技术保护您的帐号安全
- Django实现微电影网站
主要实现功能: 注册,登陆,播放视频,评论视频,xadmin实现后台提供视频管理,权限管理等等 首页(搜索,筛选) 搜索页面 播放页面 个人中心 后台 源码下载 环境配置:python2.7 pip ...