Home > Back-end >  Several problems about sqlsession in mybatis
Several problems about sqlsession in mybatis

Time:09-29

When using mybatis. Do not use the mapper class for mapping, but directly use the selectList sqlsession provide performance mapper. In XML statement:
 
SqlSession SqlSession=mySqlSessionFactory (.) openSession ();
.//the statement for the mapper XML only a select node id
//¶s is introduced into the map data in SQL object
List List=sqlSession. SelectList (statement, ¶s);
return list;

Eventually executed SQL very simple
 select * from sys_user su where su. Usrid='sa' 

So every time after receipt of the HTTP request execution will create a sqlsession, but each time all around 400 ms, sometimes even longer, the same statements in PLSQL performed only need less than 100 milliseconds,
If you use ServiceImpl T> This mapping method, the first execution in about 1000 milliseconds, but behind the request is less than 100 milliseconds, and PLSQL execution situation,

question 1: how to use the sqlSession selectList when can query speed and PLSQL performance consistent?

Tried to cache a sqlsession, do speed, but mybatis clearly don't put the sqlsession in static in the official document scope, must be a HTTP request to create a sqlsession, so this method is not feasible,
problem two: this kind of writing mybatis mapper mapping relationship is how to optimize the sqlsession?

CodePudding user response:

Sys_user table according to the total amount is not big, only about ten

CodePudding user response:

Do you want with the code to see what kind of actuators, it is simple or reuse. The amount of data is too small, you is not good, had better have a millions of data
  • Related