本文介绍: 配置系统文件配置扫描包02 编写测试接口测试类测试用的控制层接口03 启动项目启动之后,会自动生成默认密码Using generated security password: 8d97e198-138c-4093-9a5c–ac83e2dda426这时候访问接口被spring–security默认拦截,必须登录后才能访问
SpringSecurity的默认登录页的使用
01 前期准备
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--mysql驱动-->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<!--模块化插件配置类-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--mybatisplus依赖-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
<!--spring-security依赖-->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/(需要连接的数据库)?userSSL=false;serverTimezone=Asia/Shanghai
username: (账号)
password: (密码)
mvc:
pathmatch:
matching-strategy: ant_path_matcher
mybatis-plus:
config-locations: classpath:mapper/*.xml
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
@SpringBootApplication
@MapperScan("com.example.demo.mapper")
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
02 编写测试接口
- 测试类
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Category {
@TableId
private Long categoryId;
private String categoryName;
private String categoryPicture1;
private String categoryPicture2;
}
- 测试用的控制层接口
@RestController
@RequestMapping("category")
public class CategoryController {
@Autowired
private ICategoryService iCategoryService;
@GetMapping("all")
public GetData selectAll(){
List<Category> categories=iCategoryService.list();
GetData getData = new GetData(200,"查询成功",categories);
return getData;
}
@GetMapping("byId")
public GetData selectDetail(Long id){
Category category=iCategoryService.getById(id);
GetData getData = new GetData(200,"查询成功",category);
return getData;
}
}
03 启动项目
原文地址:https://blog.csdn.net/2302_77182979/article/details/134718107
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_18295.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。