无标题文章111


"http://mybatis.org/dtd/mybatis-3-config.dtd">


















2.
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">













insert into tb_user values (default,#{username},#{password},#{email},#{gender},#{nickname},#{photo})


delete from tb_user where username=#{username}


update tb_user set password=#{password} where username=#{username}

3.package com.lin;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.function.Supplier;

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.lin.dao.UserDao;
import com.lin.model.User;

/**

  • Unit test for simple App.
    */
    public class AppTest {
    public static void main(String[] args) throws IOException {
    //通过输入流 读取配置文件
    InputStream in = Resources.getResourceAsStream("mybatis-config.xml");
    //建立sql会话工厂
    SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(in);
    SqlSession session = factory.openSession();
    UserDao userDao = session.getMapper(UserDao.class);
    // List userList = userDao.findAll();
    // for (User user : userList) {
    // System.out.println(user.getUsername());
    // }
    User user = new User();
    user.setUsername("admin");
    user.setPassword("123123");
    userDao.update(user);
    session.commit();
}

}

你可能感兴趣的:(无标题文章111)