Mybatis for beginners. example: SQL statement & quot; SELECT * FROMt_userWHERElogin_nameLIKE & quot; % & quot ;#{ value} & quot; % & quot; test Program & quot; @ TestpublicvoiddeleteUser () throwsIOException {mybatis configuration file Stringresource & quot; SqlMapConfig. xml & quot; InputStreaminput mybatismysqlnamespace database string
Mybatis beginners, such:
SQL statement in xml
SELECT * FROM t_user WHERE login_name LIKE "%"#{value}"%"
Test Procedure
@ Test public void deleteUser () throws IOException {// mybatis configuration file String resource = "SqlMapConfig. xml "; InputStream input = Resources. getResourceAsStream (resource); // Create a session factory SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder (). build (input); // Obtain SqlSession sqlSession = sqlSessionFactory through the factory. openSession (); // operate the database through the session // The first parameter: statement id, equal to = namespace + statementId // the second contestant: list of parameters that match the parameterType in the ing file
Users = sqlSession. selectList ("test. findUserByName "," admina "); for (User user: users) {System. out. println (user); String loginName = user. getLoginName (); System. out. println (loginName);} sqlSession. close ();}
Running problems
Run SQL in the database. This item has a value. I checked it based on this item. why is the query successful but all other items have a value? if this item has no value, solve it.