@Test
public void testInsertUser() {
UserDao userDao = new UserDaoImpl();
User user = new User();
user.setUsername(“张飞1111”);
user.setSex(“2”);
user.setBirthday(new Date());
user.setAddress(“深圳黑马”);
userDao.insertUser(user);
}
通过动态代理的方式有实现类但是不需要自己手动去写
1、创建UserMapper接口
package com.itzheng.mybatis.mapper;
import java.util.List;
import com.itzheng.mybatis.pojo.User;
public interface UserMapper {
// 根据用户ID查询用户信息
/*
- 用户信息持化接口
*/
User getUserByid(Integer id);
// 根据用户名查找用户列表
List getUserByUserName(String userName);
// 添加用户
void insertUser(User user);
}
2、创建UserMapper.xml
<?xml version="1.0" encoding="UTF-8" ?><select id=“getUserByid” parameterType=“int”
resultType=“com.itzheng.mybatis.pojo.User”>
SELECT * FROM USER WHERE id = #{id1}
<select id=“getUserByUserName” parameterType=“string”
resultType=“com.itzheng.mybatis.pojo.User”>
SELECT id,username,birthday,sex,address FROM user
WHERE username LIKE
‘%${value}%’
<insert id=“insertUser”
parameterType=“com.itzheng.mybatis.pojo.User” useGeneratedKeys=“true”
keyProperty=“id”&g