ORM

关系数据库需要按对象来处理,出现ORM设置,列对应类的属性,行对应对应类的实例,也就是每一行对应一个新的实例,对应类是需要实现序列化(implements Serializable  - import java.io.Serializable),这些对应类称为持久化对象,是数据层DAO,Domain,向下直接对应数据库,向上接服务层,它们的属性是对应数据库的列,方法是对数据库的操作,比如,先设定一个公共基类,可以完成,一般表的createby,createddate,modifiedby,modifieddate这4个常用字段的添加,最好将分页属性也放进去,再将这些对应类建立,这些对应类应该是继承基类,并且,对应数据表的(可以是单表结构,单表查询结果,多表查询结果,查询结果添加自定义字段的,查询结果进行转换过的等等 - 引申为po,dto),对这些类的方法中实现具体操作(可以建立接口( interface IBasicService<T> ->CURD同find、getAll,getCount。。。  )同DAOImpl这样的实现类 (

引申扩展服务层(serice类,封装业务流程)一般流程:

1.Interface:

public interface ICustomerService {

定义各种方法,只是定义,实现可以交代其他人来写了。。。

PageInfo<CustomerContactVo> queryCustomerContactList(CustomerContactVo contactVo) throws Exception;

}

2.service:

实现接口,实现接口中定义的方法,对数据层进行调用:

public class CustomerServiceImpl implements ICustomerService{

private static final Logger logger = LoggerFactory.getLogger(CustomerServiceImpl.class);

...

//对DAO进行调用,其中interface  ICustomerDao ->  CustomerDaoImpl implements  ICustomerDao {}

@Resource
private ICustomerDao customerDao; //下面方法没有用到,只是举个DAO层例子,这个DAO接口实现的方法将对数据库进行操作,对业务需求进行实现,引申为服务层用DAO接口方式同数据层解耦(业务层不依赖持久层),这个接口可以选择任何数据库来实现,高层不依赖低层(依赖倒转原则),依赖抽象,面对接口编程。

...

@Override
public PageInfo<CustomerContactVo> queryCustomerContactList(CustomerContactVo contactVo) throws Exception {
PageHelper.startPage(contactVo.getPage(), contactVo.getRows());
PageInfo<CustomerContactVo> customerContact = null;

try {
if (!StringUtils.isBlank(contactVo.getApplicationQuery())) {
UserInfo userInfo = (UserInfo) Core.cache().get(contactVo.getToken());
if (null != userInfo) {
contactVo.setCreatedBy(userInfo.getId());
}
}
customerContact = new PageInfo<CustomerContactVo>(customerDao.queryCustomerContactById(contactVo));
} catch (Exception e) {
// DAO exception 处理
}

return customerContact;
}

}

3.api (servlet/controller/action):

@Controller
@RequestMapping(value = "/customer")
@Api(value = "/customer")
public class CustomerApi extends BasicApi<Object> {

@Reference(timeout = 100000)

private ICustomerService customerService; //同上面服务实现DAO接口实现一样,这里是表示层对服务接口的调用,让表示层不依赖于业务层

@RequestMapping(value = "/queryCustomerContactList", method = RequestMethod.POST)
public @ResponseBody Object queryCustomerContactList(CustomerContactVo contactVo, HttpServletRequest request)
throws JsonProcessingException {
if (ObjectUtils.isEmpty(contactVo)) {
throw new Exception("E04", "", null);
}
Object object = sendDataTablePageAjaxData(customerService.queryCustomerContactList(contactVo));
return object;
}

}

4.Html

Html,css,javascript,Jquery,bootstrap,vue,ios,android...

->XML JSON

->HTTP AJAX

->HTTP

)来做,也可以不用,如果考虑多个数据库切换最好做,比如:mssqlImpl implements IBasicService()):

public class BasicDomain implements Serializable {

private static final long serialVersionUID = 6686489176603998566L;

/**
* 前台传入参数:当前页
*/
private int page = 1;
/**
* 前台传入参数:每页页数
*/
private int rows = 10;
/**
* 前台传入参数:排序字段
*/
private String sidx;
/**
* 前台传入参数:排序类型
*/
private String sord;
/**
* 数据库分页参数:当前页
*/
private int start;

/**
* 数据库分页参数:每页页数
*/
private int limit = 10;

/**
* 创建时间
*/
private Date createdDate;
/**
* 创建人
*/
private String createdBy;
/**
* 修改时间
*/
private Date modifiedDate;
/**
* 修改人
*/
private String modifiedBy;

。。。

getter/setter

。。。

}

//PO

public class Customer extends BasicDomain {
/**
*
*/
private static final long serialVersionUID = 1L;
private String customerID;
private Long accountID;// 客户ID
private String name;// 名称
private String number;// 编号

。。。

//非实体关联关系属性,仅供方便传参
private CustomerExt customerExt;
private CustomerBankInfo customerBankInfo;

//可以List VO ,VO是业务层的数据传递,也是前端显示数据,比如,DTO(DTO类封装业务实体对象)是0同1,那么VO是男同女,view同model要避免强耦合,

private List<CustomerAddressVO> customerAddressList;

public CustomerBankInfo getCustomerBankInfo() {
return customerBankInfo;
}

public List<CustomerAddressVO> getCustomerAddressList() {
return customerAddressList;
}

public void setCustomerBankInfo(CustomerBankInfo customerBankInfo) {
this.customerBankInfo = customerBankInfo;
}

public void setCustomerAddressList(List<CustomerAddressVO> customerAddressList) {
this.customerAddressList = customerAddressList;
}

。。。

}

一般带上下面3个:

@Override
public int hashCode() {

@Override
public boolean equals(Object obj) {

@Override
public String toString() {

Mybatis的学习1的更多相关文章

  1. Mybatis架构学习

    Mybatis架构学习 MyBatis 是支持定制化 SQL.存储过程以及高级映射的持久层框架.MyBatis 封装了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.可以对配置和原生Map使用 ...

  2. MyBatis入门学习教程-使用MyBatis对表执行CRUD操作

    上一篇MyBatis学习总结(一)--MyBatis快速入门中我们讲了如何使用Mybatis查询users表中的数据,算是对MyBatis有一个初步的入门了,今天讲解一下如何使用MyBatis对use ...

  3. MyBatis入门学习(二)

    在MyBatis入门学习(一)中我们完成了对MyBatis简要的介绍以及简单的入门小项目测试,主要完成对一个用户信息的查询.这一节我们主要来简要的介绍MyBatis框架的增删改查操作,加深对该框架的了 ...

  4. Mybatis的学习总结二:使用Mybatis对表进行CRUD操作【参考】

    一.使用Mybatis对表进行CRUD操作------基于XML的实现 1.定义SQL的映射文件 2.在conf.xml中进行注册. 2.创建测试类 [具体过程参考:Mybatis的学习总结一] 二. ...

  5. Spring+SpringMVC+MyBatis深入学习及搭建(二)——MyBatis原始Dao开发和mapper代理开发

    转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/6869133.html 前面有写到Spring+SpringMVC+MyBatis深入学习及搭建(一)——My ...

  6. Spring+SpringMVC+MyBatis深入学习及搭建(三)——MyBatis全局配置文件解析

    转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/6874672.html 前面有写到Spring+SpringMVC+MyBatis深入学习及搭建(二)——My ...

  7. Spring+SpringMVC+MyBatis深入学习及搭建(四)——MyBatis输入映射与输出映射

    转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/6878529.html 前面有讲到Spring+SpringMVC+MyBatis深入学习及搭建(三)——My ...

  8. Spring+SpringMVC+MyBatis深入学习及搭建(五)——动态sql

    转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/6908763.html 前面有讲到Spring+SpringMVC+MyBatis深入学习及搭建(四)——My ...

  9. Spring+SpringMVC+MyBatis深入学习及搭建(六)——MyBatis关联查询

    转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/6923464.html 前面有将到:Spring+SpringMVC+MyBatis深入学习及搭建(五)--动 ...

  10. Spring+SpringMVC+MyBatis深入学习及搭建(七)——MyBatis延迟加载

    转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/6953005.html 前面讲到:Spring+SpringMVC+MyBatis深入学习及搭建(六)——My ...

随机推荐

  1. CAFFE在win10+VS2017下的安装笔记

    老版的caffe在BVLC的github上已经找不到,如果要想下载老版caffe可以下载微软的caffe版本:https://github.com/Microsoft/caffe 网上的大多安装caf ...

  2. 【转】Syncthing的安装与使用

    Syncthing的安装与使用 无论办公.文件共享.团队协作还是家庭照片.视频.音乐.高清电影的存储,我们常常都有文件同步和存储的需求.但随着国内各大网盘的花式阵亡或限速,早已没什么好选择了. 除了转 ...

  3. php使用insert语句动态添加用户

    <html> <head> <title>Adding User</title> </head> <body> <h2&g ...

  4. 简易Asset工作流

    前言: 当前比较主流的制作流程都可以按顺序细分为三个部分:资产环节(asset section),镜头环节(shot section),合成环节(composite section). 考虑到单一资产 ...

  5. DNS搭建

    构建主从服务DNS 1.主服务名字:ns1.amber.com #hostname ns1.amber.com bash 刷新一下 #bash 2.Vim /etc/hosts 3.Vim /etc/ ...

  6. ERROR: cannot launch node of type [teleop/teleop_key]: can't locate node [teleop_key] in package [teleop]

    节点由python写成,编译通过,运行时报错如下: ERROR: cannot launch node of type [teleop/teleop_key]: can't locate node [ ...

  7. 7_CentOS下安装和卸载AdobeReader

    曾经最喜欢Fedora 版本的Linux,但是因为现在Fedora的界面实在太花里胡哨了,所以最近开始捣鼓CenOS,本来 RedHat的EL版本也是一个不错的选择,最后想想还是用社区版的. 话说Ce ...

  8. catkin-make: command not found 错误解决

    参考网址:https://answers.ros.org/question/212492/catkin_make-command-not-found/ zc@ubuntu:~ $ source /op ...

  9. k2datas 基础编程题,判断字符串是否有重复串

    package String; public class DuplicateString { public static boolean isDup(String s) throws Exceptio ...

  10. oracle数据库的权限系统

    oracle数据库的权限系统分为系统权限与对象权限.系统权限( database system privilege )可以让用户执行特定的命令集.例如,create table权限允许用户创建表,gr ...