结合业务层实现一共完成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. [bzoj1022][SHOI2008]小约翰的游戏 John (博弈论)

    Description 小约翰经常和他的哥哥玩一个非常有趣的游戏:桌子上有n堆石子,小约翰和他的哥哥轮流取石子,每个人取的时候,可以随意选择一堆石子,在这堆石子中取走任意多的石子,但不能一粒石子也不取 ...

  2. bzoj 1012 BST 支持插入,区间最大

    水... /************************************************************** Problem: 1012 User: idy002 Lang ...

  3. 中国剩余定理 hdu 1573 X问题

    HDU 1573 X问题 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  4. 区间DP POJ 1141 Brackets Sequence

    Brackets Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 29520   Accepted: 840 ...

  5. 37.递推:Pell数列

    总时间限制: 3000ms 内存限制: 65536kB 描述 Pell数列a1, a2, a3, ...的定义是这样的,a1 = 1, a2 = 2, ... , an = 2 * an − 1 + ...

  6. [转]Intent和PendingIntent的区别

    intent英文意思是意图,pending表示即将发生或来临的事情. PendingIntent这个类用于处理即将发生的事情.比如在通知Notification中用于跳转页面,但不是马上跳转. Int ...

  7. Codeforces Round #346 (Div. 2) D. Bicycle Race 叉积

    D. Bicycle Race 题目连接: http://www.codeforces.com/contest/659/problem/D Description Maria participates ...

  8. Acdream 1738 世风日下的哗啦啦族I 树套树

    世风日下的哗啦啦族I Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acdream.info/problem?pid=1738 Descri ...

  9. python 基本语法速览,快速入门

    https://zhuanlan.zhihu.com/p/24536868 学习参考于这个博文. 我做一个笔记. 关于python一些常用的语法快速的预览,适合已经掌握一门编程语言的人.零基础,没有任 ...

  10. cherokee +php fastcgi 出现 No input file specified 故障一例

    在arch上编译cherokee 时用的--with-wwwroot=/srv/http.在建立虚拟服务器时,只要虚拟服务器的根目录位于/srv/http下,php页面都能正确运行.但只要将拟服务器的 ...