------------I do not have him, but the hand is ripe, humble and foolish, and eager to be hungry-------------
Getmapper function, get to the interface, directly through the point of call method, so as not to directly hand-hit way to write the wrong method name, (strong type of way)
Example:
Ibookdao mapper = Session.getmapper (Ibookdao. Class); List<Book> list = Mapper.findallbook ();
The tool class, the main thing is to get sqlsession object, the wording
Package Cn.dawn.util;import Org.apache.ibatis.io.resources;import org.apache.ibatis.session.sqlsession;import Org.apache.ibatis.session.sqlsessionfactory;import Org.apache.ibatis.session.sqlsessionfactorybuilder;import Java.io.ioexception;import Java.io.InputStream;/** * Created by Dawn on 2018/2/24.*/ Public classMybatisutils {StaticString Path ="Mybatis-config.xml"; StaticInputStream E; StaticSqlsessionfactorybuilder Builder =NewSqlsessionfactorybuilder (); StaticSqlsessionfactory Factory; Static { Try{e=resources.getresourceasstream (path); Factory=Builder.build (e); } Catch(IOException E1) {e1.printstacktrace (); } } Public Staticsqlsession getsession () {returnfactory.opensession (); }}
How does he use this method?
As follows:
Sqlsession session= mybatisutils.getsession ();
Ssm-mybatis-10:mybatis sqlsession Getmapper () and Simple tool class Mybatisutils