搭建SSM开发环境实现增删改查(IDEA)

搭建SSM开发环境实现增删改查(IDEA),第1张

搭建SSM开发环境实现增删改查(IDEA) 基础环境搭建 创建maven工程

next,finish,等待创建完成,创建完成后,src/main下只有webapp文件夹,我们需要手动创建java和resources,鼠标右击main,new folder,将java改成Sources类型,resources变成Resources类型

引入项目依赖
  • spring
  • springmvc
  • mybatis
  • 数据库连接池,驱动
  • 其它(jstl,servlet-api,junit)
编写ssm整合的配置文件 web.xml

添加约束


  

配置spring,springmvc,字符过滤器,Restful URI

    
        contextConfigLocation
        classpath:applicationContext.xml
    
    
        org.springframework.web.context.ContextLoaderListener
    

    
    
        dispatcherServlet
        org.springframework.web.servlet.DispatcherServlet
        1
    
    
        dispatcherServlet
        /
    

    
    
        CharacterEncodingFilter
        org.springframework.web.filter.CharacterEncodingFilter
        
            encoding
            utf-8
        
        
            forceRequestEncoding
            true
        
        
            forceResponseEncoding
            true
        
    
    
        CharacterEncodingFilter
        

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:applicationContext.xml"})
public class MapperTest {
	
	@Autowired
	DepartmentMapper departmentMapper;
	
	@Autowired
	EmployeeMapper employeeMapper;
	
	@Autowired
	SqlSession sqlSession;
	
	
	@Test
	public void testCRUD(){
		//1、插入几个部门
//		departmentMapper.insertSelective(new Department(null, "开发部"));
//		departmentMapper.insertSelective(new Department(null, "测试部"));
		
		//2、生成员工数据,测试员工插入
		//employeeMapper.insertSelective(new Employee(null, "Jerry", "M", "Jerry@atguigu.com", 2));
		
		//3、批量插入多个员工;批量,使用可以执行批量 *** 作的sqlSession。
		
		EmployeeMapper mapper = sqlSession.getMapper(EmployeeMapper.class);
		for(int i = 0;i<1000;i++){
			String uid = UUID.randomUUID().toString().substring(0,5)+i;
			mapper.insertSelective(new Employee(null,uid, "M", uid+"@163.com", 3));
		}
		System.out.println("批量完成");
		
	}

}

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5671880.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-16
下一篇2022-12-16

发表评论

登录后才能评论

评论列表(0条)

    保存