首页 技术 正文
技术 2022年11月19日
0 收藏 939 点赞 3,048 浏览 2533 个字

结合业务层实现一共完成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>

未完待续。。。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,991
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,505
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,766
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844