mybatis:
mapper-locations: classpath:mapper/*.xml
数据库字段
pojo
@Data
public class User {
private int id ;
private String name;
private int age;
private String email;
剩下的就是get和set方法自行完成
mapper
@Mapper
public interface UserMapper {
List findAll();
}
如果是springboot,在启动类中使用@MapperScan(“mapper接口所在包全名”)即可,不用一个一个的在Mapper接口中加@Mapper注解。@Mapper注解是识别他为mybatis的mapper接口,会自动的把 加@Mapper 注解的接口生成动态代理类。
让springboot认识你的mapper层,也可以在启动类上面加MapperScan(“mapper层所在包的全名”)
mapper.xml
<?xml version="1.0" encoding="UTF-8" ?>SELECT * FROM user
controller
@RestController
public class UserController {
@Autowired
//