spring+spring mvc+mybatis

felixilef的头像 felixilef 0 2016-03-06 13:10 1

 基本信息

× 1   

浏览数: 31722

分享时间: 2 年 前

3

[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);
	}

}

12 3 [下一页]

  • shihunga的头像 shihunga 2016-12-26 11:28 代码数:0

    参考学习下, 刚入门

  • jack2825的头像 jack2825 2018-12-18 16:43 代码数:0

    I read your blog frequently and I just thought I’d say keep up the amazing work!

    Play for free and downloadable for PC and MAC <a href="https://games.lol/arcade/">80s arcade games</a>

  • jack2825的头像 jack2825 2018-12-18 16:45 代码数:0

    I read your blog frequently and I just thought I’d say keep up the amazing work!

    Play for free and downloadable for PC and MAC <a href="https://games.lol/arcade/">80s arcade games</a>

  • jack2825的头像 jack2825 2018-12-18 16:48 代码数:0
    這實際上是我一直試圖找到的那種信息。感謝您撰寫此信息。
    
    玩<a href="https://games.lol/arcade/"> 80年代街機遊戲</a>玩得開心
  • pevahanifo的头像 pevahanifo 2018-10-20 18:09 代码数:0

    I was looking at some of your posts on this website and I conceive this web site is really instructive! Keep putting up.. Megabucks Ranch

  • weclch2008的头像 weclch2008 2016-05-10 13:51 代码数:0

    这个代码还是有一定的参考价值的!

  • ossaa的头像 ossaa 2018-10-21 18:39 代码数:0

    I know your expertise on this. I must say we should have an online discussion on this. Writing only comments will close the discussion straight away! And will restrict the benefits from this information.Enjoy Mexico Villa Rentals

  • ossaa的头像 ossaa 2018-10-21 21:41 代码数:0

    I’ve been searching for some decent stuff on the subject and haven't had any luck up until this point, You just got a new biggest fan!..

    Enjoy Mexico top desinations

  • ossaa的头像 ossaa 2018-10-22 17:21 代码数:0

    i read a lot of stuff and i found that the way of writing to clearifing that exactly want to say was very good so i am impressed and ilike to come again in future.. 

    Enjoy Mexico Villa Rentals in Cabo San Lucas

  • ossaa的头像 ossaa 2018-10-22 20:04 代码数:0

    I admit, I have not been on this web page in a long time... however it was another joy to see It is such an important topic and ignored by so many, even professionals. professionals. I thank you to help making people more aware of possible issues.

    Enjoy Mexico Villa Rentals in Punta Mita

您的评论: