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. JSP学习1---创建一个简单的jsp程序

    一.新建一个“Dynamic Web Project”动态Web项目 1.1输入项目名称 Project1,在Dynamic Web module version(动态Web模块版本),选择3.0(注 ...

  2. NGUI外包开发总结一下今天的收获

    先总结一下今天的收获:在一个脚本类中对其成员变量进行初始化时,什么时候在Awake()中,什么时候在Start()中是有讲究的. 1)当成员变量会被外部脚本引用时,尤其是该成员变量是一个自己定义的非脚 ...

  3. webpack打包vue -->简易讲解

    ### 1. 测试环境: 推荐这篇文章:讲的很细致 https://www.cnblogs.com/lhweb15/p/5660609.html 1. webpack.config.js自行安装 { ...

  4. 查看局域网内所有IP的方法

    1,windows下查看局域网内所有IP的方法: 在MS-DOS命令行输入arp -a 2,Linux下,查看局域网内所有IP的方法: 在命令行输入nmap -sP 172.10.3.0/24

  5. Wpf开源收集

    1,到底有哪些开源MVVM框架? 前面介绍了WPF的基本概念和一些相关知识,我们了解到开发WPF应用程序可以使用现成的框架和模式,最为合适的莫过于时下正热的MVVM模式,所以这里我们也列出针对MVVM ...

  6. git bash的一些使用经验

    1.最开始使用git的时候, git remote -v 查看远程仓库 报了一个错误fatal: not a git repository (or any of the parent director ...

  7. Pytest高级进阶之Fixture

    From: https://www.cnblogs.com/feiyi211/p/6626314.html 一. fixture介绍 fixture是pytest的一个闪光点,pytest要精通怎么能 ...

  8. socket通信中select函数的使用和解释

    select函数的作用: select()在SOCKET编程中还是比较重要的,可是对于初学SOCKET的人来说都不太爱用select()写程序,他们只是习惯写诸如 conncet().accept() ...

  9. C++primer第一章(部分)

    1.4.2 for 语句 for (init-statement; condition; expression) statement; step1:初始化 step2:判断条件,为真则执行循体:为假则 ...

  10. jupyter可视化调试

    1. 安装PixieDust  pip install pixiedust 2. %%pixie_debugger <The Visual Python Debugger for Jupyter ...