Mybatis 学习笔记四 MyBatis-Plus插件
maven依赖
com.baomidou mybatis-plus 3.0.5 org.apache.velocity velocity-engine-core 2.0 org.freemarker freemarker 2.3.28 org.projectlombok lombok 1.18.4 provided
配置
mybatis配置
conf.xml
注意:保持基本配置即可;
spring配置
applicationContext.xml
mapper配置
userMapper.xml
meng.mybatis.test.UserMapper类
import com.baomidou.mybatisplus.core.mapper.BaseMapper;import java.util.List;public interface UserMapper extends BaseMapper{ List findUsers(); User findUserByUserid(int id);}
实体类
User.java
import com.baomidou.mybatisplus.annotation.TableField;import com.baomidou.mybatisplus.annotation.TableName;import lombok.AllArgsConstructor;import lombok.Data;import lombok.NoArgsConstructor;import lombok.ToString;@TableName("users")@Data@NoArgsConstructor@AllArgsConstructor@ToStringpublic class User { private int id; private String name; private int age; @TableField(value = "stu_id") private String stuId;}
测试
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml"); UserMapper userMapper = context.getBean(UserMapper.class); User user = userMapper.selectById(1); System.out.println(user]");