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 ...
随机推荐
- java爬虫爬取资源,小白必须会的入门代码块
java作为目前最火的语言之一,他的实用性也在被无数的java语言爱好者逐渐的开发,目前比较流行的爬取资源,用java来做也更简单一些,下面是爬取网页上所有手机型号,参数等极为简便的数据 packag ...
- [转]Android:Activity+Fragment及它们之间的数据交换(一)
2014-05-18 来源:Android:Activity+Fragment及它们之间的数据交换(一) 简介: 为什么要用Fragment?使用Fragment可以在一个Acti ...
- Codeforces Round #302 (Div. 1) C. Remembering Strings DP
C. Remembering Strings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- BZOJ 2243: [SDOI2011]染色 树链剖分 倍增lca 线段树
2243: [SDOI2011]染色 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/pr ...
- PAT甲级1107. Social Clusters
PAT甲级1107. Social Clusters 题意: 当在社交网络上注册时,您总是被要求指定您的爱好,以便找到一些具有相同兴趣的潜在朋友.一个"社会群体"是一群拥有一些共同 ...
- busdog is a filter driver for MS Windows (XP and above) to sniff USB traffic.
https://code.google.com/p/busdog/ busdog is a filter driver for MS Windows (XP and above) to sniff U ...
- Windows Embedded Compact 7网络编程概述(上)
如今,不论是嵌入式设备.PDA还是智能手机,网络都是必不可少的模块.网络使人们更方便地共享设备上的信息和资源.而且,利用智能手机浏览互联网,也逐渐成为生活中的常见手段.物联网所倡导的物物相联,也离不开 ...
- bionase
BIONASE BIONASE是一个革命性的新设备,针对过敏性鼻炎(花粉病或枯草热)以及大多其他类型的鼻炎.BIONASE能够缓解以及有效阻止与过敏性鼻炎相关的临床症状,例如:鼻塞,打喷嚏,头疼以及流 ...
- Unity3D如何减少安装包大小
译官方文档:http://docs.unity3d.com/Manual/ReducingFilesize.html PDF文档:http://www.rukawa.cn/Uploads/Attach ...
- 海思hi3518 opencv测试
2.4.9的opencv 安装好交叉编译后,用Cmake 配置opencv 修改CMakeCache.txtCMAKE_EXE_LINKER_FLAGS:STRING=-lpthread -lrt - ...