| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
felixilef
9年前发布

spring+spring mvc+mybatis

[Java]代码    

package com.mytest.tesst;    import java.io.InputStream;  import java.util.HashMap;  import java.util.List;  import java.util.Map;    import org.apache.ibatis.session.SqlSession;  import org.apache.ibatis.session.SqlSessionFactory;  import org.apache.ibatis.session.SqlSessionFactoryBuilder;    import com.mytest.beans.User;    public class MyBatisTest {     public static void main(String[] args) {    // TODO Auto-generated method stub    String resource = "mybatis_config.xml";  //  com.mysql.jdbc.Driver    InputStream is = MyBatisTest.class.getClassLoader().getResourceAsStream(resource);    SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(is);    SqlSession session = sessionFactory.openSession();    String statement = "com.mytest.dao.UserDao.getUser";//获取对应的sql替换          //ִ查询sql,获取结果,通过id去查询用户          User user = session.selectOne(statement, 1);          System.out.println(user);          //查询列表          List<User> userList = session.selectList("com.mytest.dao.UserDao.getList");          System.out.println("user_count:"+userList.size());          Map<String,String> map = new HashMap<String,String>();          map.put("name", "123");          map.put("age", "1234");          User user1 = session.selectOne("com.mytest.dao.UserDao.getUserByMap", map );          System.out.println("user1:"+user1);   }    }