package com.csnf.controller;

import com.csnf.entity.Category;
import com.csnf.mapper.CategoryMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class MapperUtils {
    public static void main(String[] args) throws IOException {
        Category category=new Category();
        category.setCategory_name("手机");
        category.setCategoryImageSrc("http://localhost:8080/images/category/phone.jpg");
        InputStream in= Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactoryBuilder builder=new SqlSessionFactoryBuilder();
        SqlSession session =builder.build(in).openSession();
        CategoryMapper mapper=session.getMapper(CategoryMapper.class);
        mapper.insert(category);
        session.commit();
    }
}
