官网啥都有
https://baomidou.com/
1.引入依赖
<dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.5.3.1</version> </dependency>
2.定义Mapper
自定义的mapper继承MybatiesPlus提供的BaseMapper接口
public interface HotelMapper extends BaseMapper<Hotel> { }
3.在 Spring Boot 启动类中添加 @MapperScan
注解,扫描 Mapper 文件夹
@MapperScan("com.zbc.mapper") @SpringBootApplication public class ElasticApplication { public static void main(String[] args) { SpringApplication.run(ElasticApplication.class, args); } }
4.测试
@SpringBootTest(classes = ElasticApplication.class) @RunWith(SpringRunner.class) public class TestElasticSearch { @Autowired private HotelMapper hotelMapper; @Test public void testGetDoc(){ Hotel hotel = hotelMapper.selectById("36934"); System.out.println(hotel.toString()); } }
常用注解
//表名注解,标识实体类对应的表
@TableName
案例:
@TableName("sys_user")
public class User {
private Long id;
private String name;
private Integer age;
private String email;
}
//主键注解
@TableId
案例:
@TableName("sys_user")
public class User {
@TableId
private Long id;
private String name;
private Integer age;
private String email;
}
//字段注解(非主键)
@TableField
案例:
@TableName("sys_user")
public class User {
@TableId
private Long id;
@TableField("nickname")
private String name;
private Integer age;
private String email;
}
标签:mybatisplus,String,TableName,private,class,注解,public
From: https://www.cnblogs.com/gstszbc/p/18140126