GithubHelp home page GithubHelp logo

mybatis-learning's Introduction

Mybatis-Learning

这是学习mybatis的demo以及总结,会从最基本的项目构建开始,包括Junit测试,log4j等等。

主要是介绍了什么是框架,介绍mybatis,演示从0到搭建一个实现插入功能的mybatis demo,同时包含test测试以及日志。

多个mapper文件时,如果id相同则使用namespace加以区分,否则会报错。

改进成使用util单例模式来获取SqlSession的实例,节省资源,以及从属性文件读取信息,有利于解耦合。

定义别名能让我们快速简洁的看出类型信息,省去许多写路径名的麻烦。

完整的增删改查的demo。

如何在插入数据后返回主键id信息,这个在实际开发中比较多见。

增删改查之后,需要返回执行是否成功的结果,这也是一个比较实际的应用,mybatis执行之后返回的是影响的行数。

Mybatis查询结果使用lsit或者map返回,其实map在里面也是调用了返回list,再对结果进行处理的。

占位符大部分时候是安全的,使用拼接符号是不安全的,但是我们有时候使用占位符是无法实现功能的,所以必须使用拼接,这个时候就需要自己过滤非法的输入。

当mybatis的属性名与查询出来的字段名不一致的时候,我们有两种做法,一种是在SQL里面直接使用别名,一种的自己定义映射关系ResultMap。

mybatis-learning's People

Contributors

damaer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.