@ -0,0 +1,31 @@ | |||
package com.ruoyi.applet.contoller; | |||
import com.ruoyi.common.annotation.Anonymous; | |||
import com.ruoyi.model.domain.AppBanner; | |||
import com.ruoyi.model.service.IAppBannerService; | |||
import io.swagger.annotations.Api; | |||
import io.swagger.annotations.ApiOperation; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.http.ResponseEntity; | |||
import org.springframework.web.bind.annotation.GetMapping; | |||
import org.springframework.web.bind.annotation.PostMapping; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RestController; | |||
import java.util.List; | |||
@Api("轮播图") | |||
@RestController | |||
@RequestMapping("/applet/banner") | |||
public class AppletBannerController { | |||
//1.查询轮播图接口 | |||
@Autowired | |||
private IAppBannerService iAppBannerService; | |||
@Anonymous | |||
@ApiOperation("轮播图列表") | |||
@GetMapping("/list") | |||
public List<AppBanner> list(){ | |||
return iAppBannerService.getBannerList(); | |||
} | |||
} |
@ -0,0 +1,17 @@ | |||
package com.ruoyi.applet.contoller; | |||
import io.swagger.annotations.Api; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RestController; | |||
@Api("获取个人信息") | |||
@RestController | |||
@RequestMapping("/applet/Info") | |||
public class AppletInfoController { | |||
//1.获取个人信息 | |||
//2.获取分享海报 | |||
//3.获取我的用户信息列表(分页) | |||
//4.通过我的用户信息中用户ID查看订单详情接口 | |||
// | |||
} |
@ -0,0 +1,40 @@ | |||
package com.ruoyi.applet.contoller; | |||
import com.ruoyi.applet.domain.AppletLoginRequest; | |||
import io.swagger.annotations.Api; | |||
import io.swagger.annotations.ApiOperation; | |||
import org.springframework.beans.BeanUtils; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.data.domain.Page; | |||
import org.springframework.data.domain.PageImpl; | |||
import org.springframework.data.domain.Pageable; | |||
import org.springframework.http.ResponseEntity; | |||
import org.springframework.web.bind.annotation.PostMapping; | |||
import org.springframework.web.bind.annotation.RequestBody; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RestController; | |||
import java.util.ArrayList; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
@Api("伴宠师登录") | |||
@RestController | |||
@RequestMapping("/applet/login") | |||
public class AppletLoginController { | |||
// @Autowired | |||
//1.微信授权登录接口 | |||
//2.获取微信手机号接口 | |||
//3.获取用户协议和隐私政策(用一个config拉取) | |||
// @Aonymous | |||
@ApiOperation("登录接口") | |||
@PostMapping("/login") | |||
public ResponseEntity login(@RequestBody AppletLoginRequest appletLoginRequest){ | |||
Map<String,Object> hashMap = new HashMap(); | |||
hashMap.put("userInfo",appletLoginRequest); | |||
hashMap.put("token",123); | |||
return ResponseEntity.ok(hashMap); | |||
} | |||
} |
@ -0,0 +1,13 @@ | |||
package com.ruoyi.applet.contoller; | |||
import io.swagger.annotations.Api; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RestController; | |||
@Api("工作台") | |||
@RestController | |||
@RequestMapping("/applet/work") | |||
public class AppletWorkController { | |||
//1.获取用户的状态,判断是否加入 | |||
//2.从工作台配置表获取图标和说明 | |||
} |
@ -0,0 +1,8 @@ | |||
package com.ruoyi.applet.domain; | |||
import lombok.Data; | |||
@Data | |||
public class AppletLoginRequest { | |||
private String code; | |||
} |
@ -0,0 +1,7 @@ | |||
package com.ruoyi.applet.service; | |||
import org.springframework.http.ResponseEntity; | |||
public interface IAppletBannerService { | |||
ResponseEntity getBannerList(); | |||
} |
@ -0,0 +1,23 @@ | |||
package com.ruoyi.applet.service.impl; | |||
import com.ruoyi.applet.service.IAppletBannerService; | |||
import com.ruoyi.model.domain.AppBanner; | |||
import com.ruoyi.model.service.IAppBannerService; | |||
import com.ruoyi.system.service.IBasicServicesService; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.http.ResponseEntity; | |||
import org.springframework.stereotype.Service; | |||
import java.util.List; | |||
@Service | |||
public class AppletBannerServiceImpl implements IAppletBannerService { | |||
@Autowired | |||
private IAppBannerService iAppBannerService; | |||
@Override | |||
public ResponseEntity getBannerList() { | |||
List<AppBanner> bannerList = iAppBannerService.getBannerList(); | |||
return ResponseEntity.ok(bannerList); | |||
} | |||
} |
@ -0,0 +1,104 @@ | |||
package com.ruoyi.model.controller; | |||
import java.io.IOException; | |||
import java.util.List; | |||
import javax.servlet.http.HttpServletResponse; | |||
import org.springframework.security.access.prepost.PreAuthorize; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.GetMapping; | |||
import org.springframework.web.bind.annotation.PostMapping; | |||
import org.springframework.web.bind.annotation.PutMapping; | |||
import org.springframework.web.bind.annotation.DeleteMapping; | |||
import org.springframework.web.bind.annotation.PathVariable; | |||
import org.springframework.web.bind.annotation.RequestBody; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RestController; | |||
import com.ruoyi.common.annotation.Log; | |||
import com.ruoyi.common.core.controller.BaseController; | |||
import com.ruoyi.common.core.domain.AjaxResult; | |||
import com.ruoyi.common.enums.BusinessType; | |||
import com.ruoyi.model.domain.AppBanner; | |||
import com.ruoyi.model.service.IAppBannerService; | |||
import com.ruoyi.common.utils.poi.ExcelUtil; | |||
import com.ruoyi.common.core.page.TableDataInfo; | |||
/** | |||
* 轮播图Controller | |||
* | |||
* @author ruoyi | |||
* @date 2025-03-04 | |||
*/ | |||
@RestController | |||
@RequestMapping("/model/banner") | |||
public class AppBannerController extends BaseController | |||
{ | |||
@Autowired | |||
private IAppBannerService appBannerService; | |||
/** | |||
* 查询轮播图列表 | |||
*/ | |||
@PreAuthorize("@ss.hasPermi('model:banner:list')") | |||
@GetMapping("/list") | |||
public TableDataInfo list(AppBanner appBanner) | |||
{ | |||
startPage(); | |||
List<AppBanner> list = appBannerService.selectAppBannerList(appBanner); | |||
return getDataTable(list); | |||
} | |||
/** | |||
* 导出轮播图列表 | |||
*/ | |||
@PreAuthorize("@ss.hasPermi('model:banner:export')") | |||
@Log(title = "轮播图", businessType = BusinessType.EXPORT) | |||
@PostMapping("/export") | |||
public void export(HttpServletResponse response, AppBanner appBanner) throws IOException { | |||
List<AppBanner> list = appBannerService.selectAppBannerList(appBanner); | |||
ExcelUtil<AppBanner> util = new ExcelUtil<AppBanner>(AppBanner.class); | |||
util.exportExcel(response, list, "轮播图数据"); | |||
} | |||
/** | |||
* 获取轮播图详细信息 | |||
*/ | |||
@PreAuthorize("@ss.hasPermi('model:banner:query')") | |||
@GetMapping(value = "/{id}") | |||
public AjaxResult getInfo(@PathVariable("id") Long id) | |||
{ | |||
return success(appBannerService.selectAppBannerById(id)); | |||
} | |||
/** | |||
* 新增轮播图 | |||
*/ | |||
@PreAuthorize("@ss.hasPermi('model:banner:add')") | |||
@Log(title = "轮播图", businessType = BusinessType.INSERT) | |||
@PostMapping | |||
public AjaxResult add(@RequestBody AppBanner appBanner) | |||
{ | |||
return toAjax(appBannerService.insertAppBanner(appBanner)); | |||
} | |||
/** | |||
* 修改轮播图 | |||
*/ | |||
@PreAuthorize("@ss.hasPermi('model:banner:edit')") | |||
@Log(title = "轮播图", businessType = BusinessType.UPDATE) | |||
@PutMapping | |||
public AjaxResult edit(@RequestBody AppBanner appBanner) | |||
{ | |||
return toAjax(appBannerService.updateAppBanner(appBanner)); | |||
} | |||
/** | |||
* 删除轮播图 | |||
*/ | |||
@PreAuthorize("@ss.hasPermi('model:banner:remove')") | |||
@Log(title = "轮播图", businessType = BusinessType.DELETE) | |||
@DeleteMapping("/{ids}") | |||
public AjaxResult remove(@PathVariable Long[] ids) | |||
{ | |||
return toAjax(appBannerService.deleteAppBannerByIds(ids)); | |||
} | |||
} |
@ -0,0 +1,83 @@ | |||
package com.ruoyi.model.domain; | |||
import org.apache.commons.lang3.builder.ToStringBuilder; | |||
import org.apache.commons.lang3.builder.ToStringStyle; | |||
import com.ruoyi.common.annotation.Excel; | |||
import com.ruoyi.common.core.domain.BaseEntity; | |||
/** | |||
* 轮播图对象 app_banner | |||
* | |||
* @author ruoyi | |||
* @date 2025-03-04 | |||
*/ | |||
public class AppBanner extends BaseEntity | |||
{ | |||
private static final long serialVersionUID = 1L; | |||
/** $column.columnComment */ | |||
private Long id; | |||
/** 轮播图图片 | |||
*/ | |||
@Excel(name = "轮播图图片 ") | |||
private String image; | |||
/** 跳转链接 */ | |||
@Excel(name = "跳转链接") | |||
private String url; | |||
/** 逻辑删除标识 */ | |||
private Long delFlag; | |||
public void setId(Long id) | |||
{ | |||
this.id = id; | |||
} | |||
public Long getId() | |||
{ | |||
return id; | |||
} | |||
public void setImage(String image) | |||
{ | |||
this.image = image; | |||
} | |||
public String getImage() | |||
{ | |||
return image; | |||
} | |||
public void setUrl(String url) | |||
{ | |||
this.url = url; | |||
} | |||
public String getUrl() | |||
{ | |||
return url; | |||
} | |||
public void setDelFlag(Long delFlag) | |||
{ | |||
this.delFlag = delFlag; | |||
} | |||
public Long getDelFlag() | |||
{ | |||
return delFlag; | |||
} | |||
@Override | |||
public String toString() { | |||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) | |||
.append("id", getId()) | |||
.append("image", getImage()) | |||
.append("url", getUrl()) | |||
.append("createTime", getCreateTime()) | |||
.append("createBy", getCreateBy()) | |||
.append("updateTime", getUpdateTime()) | |||
.append("updateBy", getUpdateBy()) | |||
.append("delFlag", getDelFlag()) | |||
.toString(); | |||
} | |||
} |
@ -0,0 +1,68 @@ | |||
package com.ruoyi.model.mapper; | |||
import java.util.List; | |||
import com.ruoyi.model.domain.AppBanner; | |||
/** | |||
* 轮播图Mapper接口 | |||
* | |||
* @author ruoyi | |||
* @date 2025-03-04 | |||
*/ | |||
public interface AppBannerMapper | |||
{ | |||
/** | |||
* 查询轮播图 | |||
* | |||
* @param id 轮播图主键 | |||
* @return 轮播图 | |||
*/ | |||
public AppBanner selectAppBannerById(Long id); | |||
/** | |||
* 查询轮播图列表 | |||
* | |||
* @param appBanner 轮播图 | |||
* @return 轮播图集合 | |||
*/ | |||
public List<AppBanner> selectAppBannerList(AppBanner appBanner); | |||
/** | |||
* 新增轮播图 | |||
* | |||
* @param appBanner 轮播图 | |||
* @return 结果 | |||
*/ | |||
public int insertAppBanner(AppBanner appBanner); | |||
/** | |||
* 修改轮播图 | |||
* | |||
* @param appBanner 轮播图 | |||
* @return 结果 | |||
*/ | |||
public int updateAppBanner(AppBanner appBanner); | |||
/** | |||
* 删除轮播图 | |||
* | |||
* @param id 轮播图主键 | |||
* @return 结果 | |||
*/ | |||
public int deleteAppBannerById(Long id); | |||
/** | |||
* 批量删除轮播图 | |||
* | |||
* @param ids 需要删除的数据主键集合 | |||
* @return 结果 | |||
*/ | |||
public int deleteAppBannerByIds(Long[] ids); | |||
/** | |||
* 查询轮播图列表 | |||
* | |||
* @return 轮播图集合 | |||
*/ | |||
public List<AppBanner> getBannerList(); | |||
} |
@ -0,0 +1,64 @@ | |||
package com.ruoyi.model.service; | |||
import java.util.List; | |||
import com.ruoyi.model.domain.AppBanner; | |||
/** | |||
* 轮播图Service接口 | |||
* | |||
* @author ruoyi | |||
* @date 2025-03-04 | |||
*/ | |||
public interface IAppBannerService | |||
{ | |||
/** | |||
* 查询轮播图 | |||
* | |||
* @param id 轮播图主键 | |||
* @return 轮播图 | |||
*/ | |||
public AppBanner selectAppBannerById(Long id); | |||
/** | |||
* 查询轮播图列表 | |||
* | |||
* @param appBanner 轮播图 | |||
* @return 轮播图集合 | |||
*/ | |||
public List<AppBanner> selectAppBannerList(AppBanner appBanner); | |||
/** | |||
* 新增轮播图 | |||
* | |||
* @param appBanner 轮播图 | |||
* @return 结果 | |||
*/ | |||
public int insertAppBanner(AppBanner appBanner); | |||
/** | |||
* 修改轮播图 | |||
* | |||
* @param appBanner 轮播图 | |||
* @return 结果 | |||
*/ | |||
public int updateAppBanner(AppBanner appBanner); | |||
/** | |||
* 批量删除轮播图 | |||
* | |||
* @param ids 需要删除的轮播图主键集合 | |||
* @return 结果 | |||
*/ | |||
public int deleteAppBannerByIds(Long[] ids); | |||
/** | |||
* 删除轮播图信息 | |||
* | |||
* @param id 轮播图主键 | |||
* @return 结果 | |||
*/ | |||
public int deleteAppBannerById(Long id); | |||
public List<AppBanner> getBannerList(); | |||
} |
@ -0,0 +1,101 @@ | |||
package com.ruoyi.model.service.impl; | |||
import java.util.List; | |||
import com.ruoyi.common.utils.DateUtils; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import com.ruoyi.model.mapper.AppBannerMapper; | |||
import com.ruoyi.model.domain.AppBanner; | |||
import com.ruoyi.model.service.IAppBannerService; | |||
/** | |||
* 轮播图Service业务层处理 | |||
* | |||
* @author ruoyi | |||
* @date 2025-03-04 | |||
*/ | |||
@Service | |||
public class AppBannerServiceImpl implements IAppBannerService | |||
{ | |||
@Autowired | |||
private AppBannerMapper appBannerMapper; | |||
/** | |||
* 查询轮播图 | |||
* | |||
* @param id 轮播图主键 | |||
* @return 轮播图 | |||
*/ | |||
@Override | |||
public AppBanner selectAppBannerById(Long id) | |||
{ | |||
return appBannerMapper.selectAppBannerById(id); | |||
} | |||
/** | |||
* 查询轮播图列表 | |||
* | |||
* @param appBanner 轮播图 | |||
* @return 轮播图 | |||
*/ | |||
@Override | |||
public List<AppBanner> selectAppBannerList(AppBanner appBanner) | |||
{ | |||
return appBannerMapper.selectAppBannerList(appBanner); | |||
} | |||
/** | |||
* 新增轮播图 | |||
* | |||
* @param appBanner 轮播图 | |||
* @return 结果 | |||
*/ | |||
@Override | |||
public int insertAppBanner(AppBanner appBanner) | |||
{ | |||
appBanner.setCreateTime(DateUtils.getNowDate()); | |||
return appBannerMapper.insertAppBanner(appBanner); | |||
} | |||
/** | |||
* 修改轮播图 | |||
* | |||
* @param appBanner 轮播图 | |||
* @return 结果 | |||
*/ | |||
@Override | |||
public int updateAppBanner(AppBanner appBanner) | |||
{ | |||
appBanner.setUpdateTime(DateUtils.getNowDate()); | |||
return appBannerMapper.updateAppBanner(appBanner); | |||
} | |||
/** | |||
* 批量删除轮播图 | |||
* | |||
* @param ids 需要删除的轮播图主键 | |||
* @return 结果 | |||
*/ | |||
@Override | |||
public int deleteAppBannerByIds(Long[] ids) | |||
{ | |||
return appBannerMapper.deleteAppBannerByIds(ids); | |||
} | |||
/** | |||
* 删除轮播图信息 | |||
* | |||
* @param id 轮播图主键 | |||
* @return 结果 | |||
*/ | |||
@Override | |||
public int deleteAppBannerById(Long id) | |||
{ | |||
return appBannerMapper.deleteAppBannerById(id); | |||
} | |||
@Override | |||
public List<AppBanner> getBannerList() { | |||
return appBannerMapper.getBannerList(); | |||
} | |||
} |
@ -0,0 +1,86 @@ | |||
<?xml version="1.0" encoding="UTF-8" ?> | |||
<!DOCTYPE mapper | |||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
<mapper namespace="com.ruoyi.model.mapper.AppBannerMapper"> | |||
<resultMap type="AppBanner" id="AppBannerResult"> | |||
<result property="id" column="id" /> | |||
<result property="image" column="image" /> | |||
<result property="url" column="url" /> | |||
<result property="createTime" column="create_time" /> | |||
<result property="createBy" column="create_by" /> | |||
<result property="updateTime" column="update_time" /> | |||
<result property="updateBy" column="update_by" /> | |||
<result property="delFlag" column="del_flag" /> | |||
</resultMap> | |||
<sql id="selectAppBannerVo"> | |||
select id, image, url, create_time, create_by, update_time, update_by, del_flag from app_banner | |||
</sql> | |||
<select id="selectAppBannerList" parameterType="AppBanner" resultMap="AppBannerResult"> | |||
<include refid="selectAppBannerVo"/> | |||
<where> | |||
<if test="image != null and image != ''"> and image = #{image}</if> | |||
<if test="url != null and url != ''"> and url = #{url}</if> | |||
</where> | |||
</select> | |||
<select id="selectAppBannerById" parameterType="Long" resultMap="AppBannerResult"> | |||
<include refid="selectAppBannerVo"/> | |||
where id = #{id} | |||
</select> | |||
<select id="getBannerList" resultType="com.ruoyi.model.domain.AppBanner"> | |||
<include refid="selectAppBannerVo"/> | |||
</select> | |||
<insert id="insertAppBanner" parameterType="AppBanner"> | |||
insert into app_banner | |||
<trim prefix="(" suffix=")" suffixOverrides=","> | |||
<if test="id != null">id,</if> | |||
<if test="image != null">image,</if> | |||
<if test="url != null">url,</if> | |||
<if test="createTime != null">create_time,</if> | |||
<if test="createBy != null">create_by,</if> | |||
<if test="updateTime != null">update_time,</if> | |||
<if test="updateBy != null">update_by,</if> | |||
<if test="delFlag != null">del_flag,</if> | |||
</trim> | |||
<trim prefix="values (" suffix=")" suffixOverrides=","> | |||
<if test="id != null">#{id},</if> | |||
<if test="image != null">#{image},</if> | |||
<if test="url != null">#{url},</if> | |||
<if test="createTime != null">#{createTime},</if> | |||
<if test="createBy != null">#{createBy},</if> | |||
<if test="updateTime != null">#{updateTime},</if> | |||
<if test="updateBy != null">#{updateBy},</if> | |||
<if test="delFlag != null">#{delFlag},</if> | |||
</trim> | |||
</insert> | |||
<update id="updateAppBanner" parameterType="AppBanner"> | |||
update app_banner | |||
<trim prefix="SET" suffixOverrides=","> | |||
<if test="image != null">image = #{image},</if> | |||
<if test="url != null">url = #{url},</if> | |||
<if test="createTime != null">create_time = #{createTime},</if> | |||
<if test="createBy != null">create_by = #{createBy},</if> | |||
<if test="updateTime != null">update_time = #{updateTime},</if> | |||
<if test="updateBy != null">update_by = #{updateBy},</if> | |||
<if test="delFlag != null">del_flag = #{delFlag},</if> | |||
</trim> | |||
where id = #{id} | |||
</update> | |||
<delete id="deleteAppBannerById" parameterType="Long"> | |||
delete from app_banner where id = #{id} | |||
</delete> | |||
<delete id="deleteAppBannerByIds" parameterType="String"> | |||
delete from app_banner where id in | |||
<foreach item="id" collection="array" open="(" separator="," close=")"> | |||
#{id} | |||
</foreach> | |||
</delete> | |||
</mapper> |
@ -0,0 +1,19 @@ | |||
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; | |||
/** | |||
* 匿名访问不鉴权注解 | |||
* | |||
* @author ruoyi | |||
*/ | |||
@Target({ ElementType.METHOD, ElementType.TYPE }) | |||
@Retention(RetentionPolicy.RUNTIME) | |||
@Documented | |||
public @interface Anonymous { | |||
} | |||
@ -0,0 +1,88 @@ | |||
package com.ruoyi.framework.config.properties; | |||
import java.util.*; | |||
import java.util.regex.Pattern; | |||
import org.apache.commons.lang3.RegExUtils; | |||
import org.springframework.beans.BeansException; | |||
import org.springframework.beans.factory.InitializingBean; | |||
import org.springframework.context.ApplicationContext; | |||
import org.springframework.context.ApplicationContextAware; | |||
import org.springframework.context.annotation.Configuration; | |||
import org.springframework.core.annotation.AnnotationUtils; | |||
import org.springframework.web.method.HandlerMethod; | |||
import org.springframework.web.servlet.mvc.method.RequestMappingInfo; | |||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; | |||
import com.ruoyi.common.annotation.Anonymous; | |||
/** | |||
* 设置Anonymous注解 允许 匿名访问不鉴权 | |||
* 项目初始化时候,会将Anonymous注解的 路径 提取出来,放到urls里面 | |||
* | |||
* InitializingBean:为bean提供了初始化方法的方式,凡是继承该接口的类,在初始化bean的时候都会执行afterPropertiesSet方法 | |||
* | |||
* ApplicationContextAware:当一个类实现了这个接口之后,这个类就可以方便的获得ApplicationContext对象(spring上下文) | |||
* ,Spring发现某个Bean实现了ApplicationContextAware接口,Spring容器会在创建该Bean之后,自动调用该Bean的setApplicationContext(参数)方法 | |||
* ,调用该方法时,会将容器本身ApplicationContext对象作为参数传递给该方法。 | |||
* | |||
* @author ruoyi | |||
*/ | |||
@Configuration | |||
public class PermitAllUrlProperties implements InitializingBean, ApplicationContextAware { | |||
private static final Pattern PATTERN = Pattern.compile("\\{(.*?)\\}"); | |||
// spring上下文 | |||
private ApplicationContext applicationContext; | |||
// 前端请求接口的时候,如果在这个url里面,直接放行 | |||
private List<String> urls = new ArrayList<>(); | |||
// 替代字符串 | |||
public String ASTERISK = "*"; | |||
@Override | |||
public void afterPropertiesSet() { | |||
// 将整个项目所有bean都拿出来 | |||
RequestMappingHandlerMapping mapping = applicationContext.getBean(RequestMappingHandlerMapping.class); | |||
// 获取 每个url 与 方法、类的对应关系 | |||
Map<RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods(); | |||
// info 是代表每个url对象 | |||
map.keySet().forEach(info -> { | |||
// 获取类和方法的信息 | |||
HandlerMethod handlerMethod = map.get(info); | |||
// 获取方法上边的注解,如果此方法被“Anonymous”注解,则返回该方法,否则返回null | |||
Anonymous method = AnnotationUtils.findAnnotation(handlerMethod.getMethod(), Anonymous.class); | |||
// method为null啥也不干,否则替代path variable 为 * | |||
Optional.ofNullable(method).ifPresent(anonymous -> Objects.requireNonNull(info.getPatternsCondition().getPatterns()) | |||
.forEach(url -> urls.add(RegExUtils.replaceAll(url, PATTERN, ASTERISK)))); | |||
// 获取类上边的注解,如果此类被“Anonymous”注解,则返回该类,否则返回null | |||
Anonymous controller = AnnotationUtils.findAnnotation(handlerMethod.getBeanType(), Anonymous.class); | |||
// controller为null啥也不干,否则替代path variable 为 * | |||
Optional.ofNullable(controller).ifPresent(anonymous -> Objects.requireNonNull(info.getPatternsCondition().getPatterns()) | |||
.forEach(url -> urls.add(RegExUtils.replaceAll(url, PATTERN, ASTERISK)))); | |||
}); | |||
} | |||
/** | |||
* @Description // 这玩意是接口ApplicationContextAware带来的,就是为了在本类中方便获取 applicationContext | |||
* @Date 16:15 2023/3/22 | |||
**/ | |||
@Override | |||
public void setApplicationContext(ApplicationContext context) throws BeansException { | |||
this.applicationContext = context; | |||
} | |||
public List<String> getUrls() { | |||
return urls; | |||
} | |||
public void setUrls(List<String> urls) { | |||
this.urls = urls; | |||
} | |||
} | |||