21-spring学习-springMVC实现CRUD
结合业务层实现一共完成CRUD操作
1,定义一共IMessageServese接口
package com.SpringMVC.Service; import java.util.Map;
import java.util.Set;
import com.SpringMVC.vo.Message; public interface IMessageService { public boolean insert(Message vo) throws Exception;
public boolean update(Message vo) throws Exception;
public boolean delete(Set<Integer> ids) throws Exception;
public Message get(int id) throws Exception;
public Map<String,Object> list(String column,String keyword,int currentPage,int lineSize)
throws Exception;
}
本业务层充分考虑到几乎所有可能出现的情况,而且也要涉及到参数传递问题。
2,定义这个接口实现类,所有的操作方法都是假实现;
package com.SpringMVC.Service.Impl;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.springframework.stereotype.Service;
import com.SpringMVC.Service.IMessageService;
import com.SpringMVC.vo.Message;
import com.SpringMVC.vo.Type; @Service
public class MessageServiceImpl implements IMessageService { @Override
public boolean insert(Message vo) throws Exception {
System.out.println("增加新消息"+vo);
return true;
} @Override
public boolean update(Message vo) throws Exception {
System.out.println("修改新消息"+vo);
return true;
} @Override
public boolean delete(Set<Integer> ids) throws Exception {
System.out.println("删除新消息"+ids);
return true;
} @Override
public Message get(int id) throws Exception {
System.out.println("根据ID查询数据");
Message ms=new Message();
ms.setMid(123);
ms.setTitle("测试查询");
ms.setPrice(88.00);
ms.setPubdate(new Date());
Type type=new Type();
type.setTitle("教育新闻");
ms.setType(type);
return ms;
} @Override
public Map<String, Object> list(String column, String keyword, int currentPage, int lineSize) throws Exception { System.out.println("分页查询数据");
Map<String,Object> map=new HashMap<String, Object>();
List<Message> all=new ArrayList<Message>();
for(int i=(currentPage-1)*lineSize;i<currentPage*lineSize;i++)
{
Message ms=new Message();
ms.setMid(123+i);
ms.setTitle("测试查询-"+i);
ms.setPrice(88.00+i);
ms.setPubdate(new Date());
Type type=new Type();
type.setTitle("教育新闻-"+i);
ms.setType(type);
all.add(ms);
}
map.put("allMessage", all);
map.put("messageCount", 888);
return map;
}
}
3,既然整个代码都在Spring的控制中,那么可以利用依赖注入的方式在Action里面注入服务层接口。
4,随后为了更好的模拟,编写一共增加数据的表单。
范例:定义message_insert.jsp页面。
<form action="Pages/back/message/message_insert.action" method="post"> 消息编号:<input type="text" id="mid" name="mid" value="99"/><br>
消息标题:<input type="text" id="mid" name="title" value="大家好啊"/><br>
消息价格:<input type="text" id="mid" name="price" value="9.99"/><br>
消息日期:<input type="text" id="mid" name="pubdate" value="2018-01-10"/><br>
消息类型:<input type="text" id="mid" name="type.title" value="标题类型"/><br>
<input type="submit" value="提交"/>
<input type="reset" value="重置"/>
</form>
未完待续。。。
21-spring学习-springMVC实现CRUD的更多相关文章
- Java 系列之spring学习--springmvc搭建(四)
一.建立java web 项目 二.添加jar包 spring jar包下载地址http://repo.spring.io/release/org/springframework/spring/ 2. ...
- Java 系列之spring学习--springmvc注解方式(五)
一.springmvc注解方式 注解方式使用的更多,更加灵活.在上一篇的博客的基础上修改springmvc-servlet.xml配置文件. <?xml version="1.0&qu ...
- Java 系列之spring学习--springmvc注解参数传递(六)
一.绑定参数注解如下 @RequestParam 绑定单个请求数据,既可以是URL中的参数,也可以是表单提交的参数或上传的文件. 它有三个属性: value 用于设置参数名. defa ...
- MyEclipse Spring 学习总结三 SpringMVC
MyEclipse Spring 学习总结三 SpringMVC 一.SpringMVC原理 1.Springmvc 框架介绍 1)Spring 框架停工了构建Web应用程序的全功能MVC模块.Spr ...
- 【Spring学习笔记-MVC-3.1】SpringMVC返回Json数据-方式1-扩展
<Spring学习笔记-MVC>系列文章,讲解返回json数据的文章共有3篇,分别为: [Spring学习笔记-MVC-3]SpringMVC返回Json数据-方式1:http://www ...
- Spring学习之SpringMVC框架快速搭建实现用户登录功能
引用自:http://blog.csdn.net/qqhjqs/article/details/41683099?utm_source=tuicool&utm_medium=referral ...
- 【转】Spring学习---为什么要用spring,springMVC
[原文]https://www.toutiao.com/i6593182323095634445/ 首先,软件里有很多优秀的框架,有一种类型的框架,它的特点是建立在一个现有技术的基础上,提供和现有技术 ...
- 【Spring学习笔记-MVC-9】SpringMVC数据格式化之日期转换@DateTimeFormat
作者:ssslinppp 1. 摘要 本文主要讲解Spring mvc数据格式化的具体步骤: 并讲解前台日期格式如何转换为java对象: 在之前的文章<[Spring学习笔记-MVC ...
- 【Spring学习笔记-MVC-4】SpringMVC返回Json数据-方式2
<Spring学习笔记-MVC>系列文章,讲解返回json数据的文章共有3篇,分别为: [Spring学习笔记-MVC-3]SpringMVC返回Json数据-方式1:http://www ...
随机推荐
- PHP -- 页面传值的6种获取方法
1.PHP4以后获取传值的方法 一般在页面中传值常见的是POST.GET和COOKIE几种,所以下面我也主要介绍这几种.PHP4以后都采用的是$_POST.$_GET等数组来获取网页传值.在PHP3. ...
- ROS知识(4)----初级教程之常见问题汇总
一.开机启动ROS的工作空间的路径设置失败 现象:在教程:http://wiki.ros.org/cn/ROS/Tutorials/CreatingPackage中的第5.1小节,运行以下命令失败: ...
- JS 判断PC、android、ios、微信浏览器
1.通过js userAgent来判断 <h1>判断访问此链接的操作系统</h1> <script> var Agents = new Array("An ...
- 蓝屏代码详解(更新WIN7蓝屏代码)
6位代码含意 0 0x0000 作业完成. 1 0x0001 不正确的函数. 2 0x0002 系统找不到指定的档案. 3 0x0003 系统找不到指定的路径. 4 0x0004 系统无法开启 ...
- 关于warning: Clock skew detected. Your build may be incomplete. 的解决方法
今天发现电脑的系统时间不对,因此将时钟进行了改动,回头编译Linux kernel的时候,提演示样例如以下的warning: warning: Clock skew detected. Your ...
- End of Life check fails with NullPointerException
Checks if the running version of JIRA is approaching, or has reached End of Life. Details Type: Bug ...
- #include <NOIP2010 Junior> 三国游戏 ——using namespace wxl;
题目描述 小涵很喜欢电脑游戏,这些天他正在玩一个叫做<三国>的游戏. 在游戏中,小涵和计算机各执一方,组建各自的军队进行对战.游戏中共有 N 位武将(N为偶数且不小于 4),任意两个武将之 ...
- Python 爬虫(1)基础知识和简单爬虫
Python上手很容易,免费开源,跨平台不受限制,面向对象,框架和库很丰富. Python :Monty Python's Flying Circus (Python的名字来源,和蟒蛇其实无关). 通 ...
- python 下载安装setuptools及pip应用
1.首先下载python安装程序,下载地址:https://www.python.org/download/releases/2.7.8/ 如下图: 因为我的机器是32位的就选择了Windows x8 ...
- 【云计算】使用docker搭建nfs实现容器间共享文件
首先介绍下今天的两个主角:nfs和docker nfs 是什么 NFS(Network File System)即网络文件系统,是FreeBSD支持的文件系统中的一种,它允许网络中的计算机之间通过TC ...