结合业务层实现一共完成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的更多相关文章

  1. Java 系列之spring学习--springmvc搭建(四)

    一.建立java web 项目 二.添加jar包 spring jar包下载地址http://repo.spring.io/release/org/springframework/spring/ 2. ...

  2. Java 系列之spring学习--springmvc注解方式(五)

    一.springmvc注解方式 注解方式使用的更多,更加灵活.在上一篇的博客的基础上修改springmvc-servlet.xml配置文件. <?xml version="1.0&qu ...

  3. Java 系列之spring学习--springmvc注解参数传递(六)

    一.绑定参数注解如下 @RequestParam     绑定单个请求数据,既可以是URL中的参数,也可以是表单提交的参数或上传的文件. 它有三个属性:  value    用于设置参数名. defa ...

  4. MyEclipse Spring 学习总结三 SpringMVC

    MyEclipse Spring 学习总结三 SpringMVC 一.SpringMVC原理 1.Springmvc 框架介绍 1)Spring 框架停工了构建Web应用程序的全功能MVC模块.Spr ...

  5. 【Spring学习笔记-MVC-3.1】SpringMVC返回Json数据-方式1-扩展

    <Spring学习笔记-MVC>系列文章,讲解返回json数据的文章共有3篇,分别为: [Spring学习笔记-MVC-3]SpringMVC返回Json数据-方式1:http://www ...

  6. Spring学习之SpringMVC框架快速搭建实现用户登录功能

    引用自:http://blog.csdn.net/qqhjqs/article/details/41683099?utm_source=tuicool&utm_medium=referral  ...

  7. 【转】Spring学习---为什么要用spring,springMVC

    [原文]https://www.toutiao.com/i6593182323095634445/ 首先,软件里有很多优秀的框架,有一种类型的框架,它的特点是建立在一个现有技术的基础上,提供和现有技术 ...

  8. 【Spring学习笔记-MVC-9】SpringMVC数据格式化之日期转换@DateTimeFormat

    作者:ssslinppp       1. 摘要 本文主要讲解Spring mvc数据格式化的具体步骤: 并讲解前台日期格式如何转换为java对象: 在之前的文章<[Spring学习笔记-MVC ...

  9. 【Spring学习笔记-MVC-4】SpringMVC返回Json数据-方式2

    <Spring学习笔记-MVC>系列文章,讲解返回json数据的文章共有3篇,分别为: [Spring学习笔记-MVC-3]SpringMVC返回Json数据-方式1:http://www ...

随机推荐

  1. bzoj 2733 Splay 启发式合并,名次树

    题意:给定一个带点权的无向图,有两种操作: 1.将两个连通分量合并. 2.查询某个连通分量里的第K大点. 题解: 用并查集维护连通关系,一开始建立n棵splay树,然后不断合并,查询. 处理技巧: 1 ...

  2. MySQL order by的一个优化思路

    最近遇到一条SQL线上执行超过5s,这显然无法忍受了,必须要优化了. 首先看眼库表结构和SQL语句. CREATE TABLE `xxxxx` ( `id` ) NOT NULL AUTO_INCRE ...

  3. 关于GCC Cygwin MinGW MSYS

    [转载]关于Gcc/MinGW/Cygwin/Msys http://blog.sciencenet.cn/blog-778757-616920.html 一.GCC的历史 GCC是一个原本用于Uni ...

  4. Druid如何自动根据URL自动识别DriverClass的

    Druid是根据url前缀来识别DriverClass的,这样使得配置更方便简洁. 前缀 DriverCLass 描述信息 jdbc:odps com.aliyun.odps.jdbc.OdpsDri ...

  5. 修改Linux默认启动级别或模式

    在Linux中有7种启动级别,默认是X-Window,像是Windows的窗口模式,而Linux的操作和配置一般我们都采用输入命令的方式来完成,像DOS操作系统一样,如何让Linux一启动就进入这种模 ...

  6. 安装VS组件提示“所选驱动不再有效。继续安装之前,请先检查安装路径的设置。”要怎么办?

    电脑里面原来装了VS2010,包括的组件有VB和C++,现在想添加C#,结果安装的时候就提示“所选驱动不再有效.继续安装之前,请先检查安装路径的设置”,安装路径在C盘,还有40个G,不知道该怎么办? ...

  7. pytest文档9-参数化parametrize

    前言 pytest.mark.parametrize装饰器可以实现测试用例参数化. parametrizing 1.这里是一个实现检查一定的输入和期望输出测试功能的典型例子 # content of ...

  8. [翻译] UIView-draggable 可拖拽的UIView

    UIView-draggable 可拖拽的UIView https://github.com/andreamazz/UIView-draggable UIView category that adds ...

  9. 批量删除linux的文件;find方法批量删除文件;find查找某时间段内的所有文件

    1.如图所示,有大量文件夹,想批量删除它们 2.使用命令 find . -maxdepth 1  -regex ".*ws.*" 可以批量找到他们.maxdepth值为1表示只在当 ...

  10. Liunx下文件权限详解

    刚接触Linux时对Linux下的文件权限的概念一直很模糊,观念还一直停留在windows下,所以有很多操作一直提示权限不够.为了弄懂文件权限问题我查找了很多资料整理如下,我把这些学习笔记贴出来和大家 ...