- 进入https://gitee.com/
1.创建我的仓库
2.新建仓库
3新建文件夹,上传文件
- 提交第一份文件
- 找到项目入口
- 进入对应文件夹
- 上传文件
knief4j-测试接口展示
http://localhost:8080/doc.html#/home
依赖:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.5</version>
<!-- <relativePath/> <!– lookup parent from repository –>-->
</parent>
<groupId>com.webgrd</groupId>
<artifactId>demo_websrv</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>demo_websrv</name>
<description>demo_websrv</description>
<properties>
<java.version>8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--数据库连接池-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.11</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.3</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.5.3</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.28</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.7</version>
</dependency>
<!-- 加密-->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi2-spring-boot-starter</artifactId>
<version>4.1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
2.yml配置:
knife4j:
enable: true
openapi:
title: 非法链路自动检测与智能分析
email: xiaoymin@foxmail.com
concat: 软件3班
url: https://docs.xiaominfo.com
version: v1.0
license: Apache 2.0
license-url: https://stackoverflow.com/
terms-of-service-url: https://stackoverflow.com/
group:
test1:
group-name: 软件3班
api-rule: package api-rule-resources:
- com.webgrd.weburl.controller
3.添加例外路径:
@Configuration
public class MyInterceptorConfig implements WebMvcConfigurer {
@Resource
private JwtInterceptor jwtInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
InterceptorRegistration registration = registry.addInterceptor(jwtInterceptor);
registration
.addPathPatterns("/**") //拦截所有
.excludePathPatterns(
"/weburl/user/login",
"/weburl/user/info",
// "auth/info",
"/weburl/user/logout",
"/doc.html",
"/**/css/**",
"/**/js/**",
"/swagger-resources",
"/favicon.ico",
"/error",
"/swagger-ui.html"
);
}
}
- 登录功能
- 下载postman Download Postman | Get Started for Free
- (2)在idea中打开代码与数据库连接时数据库名称要相同,密码也是数据库密码
(2)打开代码要改maven的地址:file-Settings 搜索maven
- 打开redies
3用户信息维护:
新增用户:通过http://localhost:8081/weburl/login先进性登录,然后复制结果出来的token的双引号里的内容粘贴到http://localhost:8081/weburl/add Header下面
2.更新用户信息
http://localhost:8080/weburl/user/update
3.根据ID获取用户信息
http://localhost:8080/weburl/user/get/6
4.根据用户ID删除用户信息
http://localhost:8080/weburl/user/delete/test1
基础页面维护
1新增基础页面
- BaseUrlController
@PostMapping("/add")
public Result<?> addUrl(@RequestBody BaseUrl baseUrl){
try {
// baseUrlService.save(baseUrl);
baseUrlService.myAddBaseUrl(baseUrl);
}catch (Exception e){
return Result.fail("2222","新增基础页面失败!"+e.toString());
}
return Result.success("","新增基础页面成功!");
}
- IBaseUrlService
int myAddBaseUrl(BaseUrl baseUrl);
3)BaseUrlServiceImpl
@Override
public int myAddBaseUrl(BaseUrl baseUrl) {
return baseUrlMapper.addBaseUrl(baseUrl);
}
4)BaseUrlMapper
int addBaseUrl(BaseUrl baseUrl);
5)BaseUrlMapper.xml
<!-- 新增基础页面-->
<insert id="addBaseUrl" parameterType="BaseUrl">
insert into base_url values (#{mainPage},#{rootlink},#{num},#{level},#{leaflink},#{description})
</insert>
新增基础页面成功啦!
更新基础页面
- BaseUrlController
@PutMapping("/update")
public Result<?> updateBaseUrl(@RequestBody BaseUrl baseUrl) {
int num;
try {
num = baseUrlService.myUpdateBaseUrl(baseUrl);
} catch (Exception e) {
return Result.fail("", "更新基础页面失败!" + e.toString());
}
return Result.success(num, "更新基础页面成功!");
}
2)IBaseUrlService
int myUpdateBaseUrl(BaseUrl baseUrl);
3)BaseUrlServiceImpl
@Resource
BaseUrlMapper baseUrlMapper ;
@Override
public int myUpdateBaseUrl(BaseUrl baseUrl) {
int num = baseUrlMapper.updateBaseUrl(baseUrl);
return num;
}
4)BaseUrlMapper
int updateBaseUrl(BaseUrl baseUrl);
5)BaseUrlMapper.xml
<!-- sql语句字段不区分大小写,但是变量名区分-->
<update id="updateBaseUrl" parameterType="BaseUrl">
update base_Url set description = #{description} where mainPage = #{mainPage}
</update>
更新基础页面测试:
http://localhost:8080/weburl/baseurl/update
根据主页查询基础页面信息
- BaseUrlController
/** * 根据主页查询基础页面信息 * @param mainPage * @return 基础页面信息 */
@GetMapping("getByMainPage")
public Result<List<BaseUrl>> qryBaseUrl(String mainPage){
List<BaseUrl> urlList = null ;
try{
urlList = baseUrlService.mySelectByMainPage(mainPage);
}catch (Exception e) {
return Result.fail(urlList,"查询失败"+e.toString());
}
return Result.success(urlList, "查询基础页面成功!");
}
2)IBaseUrlService
List<BaseUrl> mySelectByMainPage(String mainPage);
3)BaseUrlServiceImpl
@Override
public List<BaseUrl> myselectByMainPage(String mainPage) {
return baseUrlMapper.selectByMainPage(mainPage);
}
4)BaseUrlMapper
List<BaseUrl> selectByMainPage(String mainPage);
5)BaseUrlMapper.xml
<select id="selectByMainPage" resultType="BaseUrl">
select * from base_url where mainPage = #{mainPage}
</select>
测试:
http://localhost:8080/weburl/baseurl/getByMainPage?mainPage=http://127.0.0.1:8082/index.html
根据多条件查询基础页面信息
1)BaseUrlController
/** * 根据条件查询基础页面信息 * @param baseUrl * @return */
@GetMapping("/get")
public Result<List<BaseUrl>> selectBaseUrl(@RequestBody BaseUrl baseUrl){
List<BaseUrl> list = baseUrlService.mySelectBaseUrl(baseUrl);
return Result.success(list,"查询成功!");
}
2)IBaseUrlService
List<BaseUrl> mySelectBaseUrl(BaseUrl baseUrl);
3)BaseUrlServiceImpl
@Override
public List<BaseUrl> selectBaseUrl(BaseUrl baseUrl) {
return baseUrlMapper.mySelectBaseUrl(baseUrl);
}
4)BaseUrlMapper
List<BaseUrl> selectBaseUrl(BaseUrl baseUrl);
5)BaseUrlMapper.xml
<select id="selectBaseUrl" resultType="BaseUrl" parameterType="BaseUrl">
select *
from base_url
where 1 = 1
<if test="mainPage != null">and mainPage = #{mainPage}</if>
<if test="rootlink != null">and rootlink = #{rootlink}</if>
<if test="num != null">and num = #{num}</if>
<if test="level != null">and level = #{level}</if>
<if test="leaflink != null">and leaflink = #{leaflink}</if>
</select>
测试:
http://localhost:8080/weburl/baseurl/get