spring+spring mvc+mybatis

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

 基本信息

× 1    浏览数: 28280 分享时间: 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
    参考学习下, 刚入门
  • 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
  • ossaa的头像 ossaa 2018-10-22 21:58 代码数:0
    Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts. iepnw.com
  • ossaa的头像 ossaa 2018-10-31 16:40 代码数:0
    This is such a great resource that you are providing and you give it away for free. I love seeing websites that understand the value of providing a quality resource for free. It is the old what goes around comes around routine. Poster Displays
  • ossaa的头像 ossaa 2018-11-01 19:25 代码数:0
    I recently came across your blog and have been reading along. I thought I would leave my first comment. I don't know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often. SEO Agentur Ruhrgebiet
您的评论: