为了能到远方,脚下的每一步都不能少.|

岁月记忆

园龄:3年8个月粉丝:2关注:3

增加请求地址前缀

复制代码
package com.ruoyi.framework.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import com.ruoyi.common.annotation.ApiRestController;

@Configuration
public class ApiPrefixAutoConfiguration implements WebMvcConfigurer {

    /**
     *
     * <p>
     * 增加restApi前缀
     * </p>
     *
     */
    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        configurer.addPathPrefix("/app", c -> c.isAnnotationPresent(ApiRestController.class));
    }

}
复制代码

 

复制代码
package com.ruoyi.common.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.springframework.core.annotation.AliasFor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@RestController
@RequestMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public @interface ApiRestController {
    @AliasFor(annotation = RequestMapping.class)
    String name() default "";

    @AliasFor(annotation = RequestMapping.class)
    String[] value() default {};

    @AliasFor(annotation = RequestMapping.class)
    String[] path() default {};

}
复制代码

controller类中只需要加入@ApiRestController注解,请求地址就会添加"/app"

复制代码
package com.ruoyi.xgzj.business.app.appController;

import com.github.pagehelper.Page;
import com.ruoyi.common.annotation.ApiRestController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.generator.ghbTestTable.domain.GhbTestTable;
import com.ruoyi.generator.ghbTestTable.service.IGhbTestTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.ruoyi.common.utils.PageUtils.startPage;

@ApiRestController
public class appGhbTestController {

    @Autowired
    private IGhbTestTableService iGhbTestTableService;

    @GetMapping("/list")
    public AjaxResult list(@RequestBody GhbTestTable ghbTestTable){

        Page<Object> objects = startPage(Integer.parseInt(ghbTestTable.getPageNum()), Integer.parseInt(ghbTestTable.getPageSize()));
        List<GhbTestTable> ghbTestTables = iGhbTestTableService.selectGhbTestTableList(ghbTestTable);

        Map data = new HashMap();
        data.put("total",objects.getTotal());
        data.put("list",ghbTestTables);
        return AjaxResult.success(data);
    }



}
复制代码

 

本文作者:岁月记忆

本文链接:https://www.cnblogs.com/huang2979127746/p/16356140.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   岁月记忆  阅读(256)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起