zoukankan      html  css  js  c++  java
  • eclipse使用(一)

      使用eclipse时,编写对象的返回值非常麻烦,而使用返回值快捷键可以简化这一过程

    • 第一种 Alt+shift+L
      • 将光标放在有返回值的代码句的分号后面;
        Resources.getResourceAsStream("mybatis.xml");
        
        new SqlSessionFactoryBuilder().build(resourceAsStream);
        
        factory.openSession();
        
      • 按住Alt+Shift+L键,会弹出对话框,输入变量的名字,点击OK即可;

    InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");
    
    SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(resourceAsStream);
    
    SqlSession session = factory.openSession();
    • 第二种 Ctrl+1
      • 将光标放置在有返回值代码句那一行上(分号前后都行);
        Resources.getResourceAsStream("mybatis.xml");
        
        new SqlSessionFactoryBuilder().build(resourceAsStream);
        
        factory.openSession();
      • 选择Assign statement to new local variable : 生成局部变量;
        InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");
        
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        
        SqlSession session = factory.openSession();

         

      • 选择Assign statement to new field : 生成全局变量;
        import java.io.IOException;
        import java.io.InputStream;
        import java.util.List;
        
        import org.apache.ibatis.io.Resources;
        import org.apache.ibatis.session.SqlSession;
        import org.apache.ibatis.session.SqlSessionFactory;
        import org.apache.ibatis.session.SqlSessionFactoryBuilder;
        
        import com.bjm.pojo.People;
        
        public class Test {
        	private static SqlSessionFactory factory;
        	private static InputStream resourceAsStream;
        	private static SqlSession openSession;
        
        	public static void main(String[] args) throws IOException{
        		resourceAsStream = Resources.getResourceAsStream("mybatis.xml");
        		factory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        		openSession = factory.openSession();
        		List<People> selectList = openSession.selectList("com.bjm.mapper.selAll");
        		
        		for (People people : selectList) {
        			System.out.println(people.toString());
        		}openSession.close();
        	}
        }
        
  • 相关阅读:
    获取与端点的连接
    判断div内滚动条是否在底部
    MVC的使用!
    格式转换解决存取数据安全问题
    JQuery input file 上传图片
    contenteditable 常用的一些CSS !!
    C# 生成Json类型数据
    生成Excel
    生成验证码
    图片水印
  • 原文地址:https://www.cnblogs.com/bjm1/p/10247269.html
Copyright © 2011-2022 走看看