首页 > 其他分享 >SpringBoot+MybatisPlus--使用

SpringBoot+MybatisPlus--使用

时间:2022-10-19 22:34:38浏览次数:81  
标签:TableField MybatisPlus SpringBoot Service -- 创建 private 注解 public

1、在entity包下面创建数据实体类,添加注解@Data,如果和数据库名字不一样的话,还需要+@TableField注解。字段名字不一样也需要添加此注解

@TableName(value = "user")
public class AnnotationUser4Bean {
   @TableId(value = "user_id", type = IdType.AUTO)
   private String userId;
    
   @TableField("name")
   private String name;
    
   @TableField("sex")
   private String sex;
    
   @TableField("age")
   private Integer age;
}

2,创建Mapper接口,对应刚创建的实体类

public interface AddressBookMapper extends BaseMapper<AddressBook> {
}

3、创建Service接口

public interface AddressBookService extends IService<AddressBook> {
}

4、创建Service实现类,需要加@Service注解

@Service
public class AddressBookServiceImpl extends ServiceImpl<AddressBookMapper, AddressBook> implements AddressBookService {
}

5、创建对应的Controller类

@Slf4j
@RestController
@RequestMapping("/addressBook")
public class AddressBookController {
    @Autowired
    private AddressBookService addressBookService;

    @Autowired
    private OrdersService ordersService;
}

 

标签:TableField,MybatisPlus,SpringBoot,Service,--,创建,private,注解,public
From: https://www.cnblogs.com/zhaolei0419/p/16808091.html

相关文章