SpringSecurity的默认登录页的使用

01 前期准备

	<dependency>
            &lt;groupId&gt;org.springframework.boot</groupId&gt;
            <artifactId&gt;spring-boot-starter-web</artifactId&gt;
        </dependency&gt;
		<!--mysql驱动--&gt;
        <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进行投诉反馈,一经查实,立即删除

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注