先选上这三个依赖,后面所用到的依赖可以手动导入
com.baomidou
mybatis-plus-boot-starter
3.4.2
mysql
mysql-connector-java
8.0.26
org.springframework.boot
spring-boot-devtools
true
runtime
三、新建application.yml等配置文件
- 开发环境(dev):开发环境是专门用于开发的服务器,配置可以比较随意,为了开发调试方便。
- 测试环境(test):一般是克隆一份生产环境的配置,一个程序在测试环境工作不正常。
- 生产环境(prod):是值正式提供对外服务的,一般会关掉错误报告,打开错误日志。
application.yml
server:
port: 8080
spring:
freemarker:
suffix: .html
cache: false
profiles:
active: dev
application-dev.yml
# 配置数据库连接
spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/"你的数据库名"?serverTimezone=GMT%2b8&useUnicode=true&characterEncoding=utf-8&useSSL=false
username: 数据库用户名
password: 数据库密码
四、新建Vo、Dao等包、各个类与接口
Vo
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@TableName("kss_user") // 指定实体和数据库表kss-user做映射
public class User extends Model implements java.io.Serializable{ //实现这个接口是为了微服务之间的通信
@TableId( type = IdType.AUTO) //指定主键
private Integer id;
private String nickname;
private String password;
}
Dao
@Repository public interface UserMapper extends baseMapperService{ }
public interface IUserService extends IService{ default void logined(String nickname,String password){} }
@Service @Slf4j public class UserServiceImpl extends ServiceImplControllerimplements IUserService{ }
@RestController
@Log4j2
public class TestController {
@Autowired
private IUserService userService;
@GetMapping(value = {"/page"})
public Page index(){
Page page = new Page<>(1,2);
LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>();
Page userPage = userService.page(page, lambdaQueryWrapper);
return userPage;
}
}
项目结构
五、编写启动类启动测试
@SpringBootApplication
@MapperScan("com.example.perinf.Dao")//写了这个mapper接口就不用再写@Mapper注解
public class PerinfApplication {
public static void main(String[] args) {
SpringApplication.run(PerinfApplication.class, args);
}
//配置拦截器实现分页
@Bean
public PaginationInterceptor getPaginationInterceptor(){
return new PaginationInterceptor();
}
}
启动测试
项目搭建成功
不要忘了导入依赖
重新启动idea,启动项目,热部署配置成功
写在最后本人是即将大三的废物蒟蒻一个,若有问题欢迎指正与讨论,感谢三连



