loginRegistry.excludePathPatterns("/parkLot/lotList/**");
时间: 2024-05-30 18:09:50 浏览: 4
这段代码是Java Spring框架中的配置,用于配置拦截器,其中`loginRegistry`是一个`InterceptorRegistry`类型的对象,`excludePathPatterns`方法用于设置例外路径,即不需要拦截的路径。在这段代码中,`/parkLot/lotList/**`是一个Ant风格的路径表达式,表示匹配以`/parkLot/lotList/`开头的所有路径。所以这段代码的作用是排除对以`/parkLot/lotList/`开头的路径的拦截。具体原理可以看一下Spring框架的拦截器实现。
相关问题
nested exception is org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'in_out' from result set. Cause: java.lang.IllegalArgumentException: No enum constant com.ruoyi.parklot.enums.ParkLot
这个错误是因为 MyBatis 在将查询结果映射为 Java 对象时,无法将数据库中的某些字段值转换为枚举类型。具体地说,这个错误提示中提到的 No enum constant xxx 是因为查询结果中存在某个字段值,在对应的枚举类型中找不到对应的枚举常量。
以您提到的错误提示为例,假设您的查询结果中有一个名为 in_out 的字段,其对应的枚举类型为 ParkLot。在查询结果中,in_out 字段的值为某个字符串,但是在 ParkLot 枚举类型中找不到对应的枚举常量,导致 MyBatis 映射失败,抛出了 ResultMapException 异常。
解决这个问题的方法是,在枚举类型中添加对应的枚举常量。以示例中的 ParkLot 枚举类型为例,可以在其定义中添加一个 UNKNOWN 常量,用于表示查询结果中不在枚举范围内的值:
```java
public enum ParkLot {
IN("1", "入场"),
OUT("2", "出场"),
UNKNOWN("unknown", "未知");
private String value;
private String desc;
ParkLot(String value, String desc) {
this.value = value;
this.desc = desc;
}
public String getValue() {
return value;
}
public String getDesc() {
return desc;
}
public static ParkLot fromValue(String value) {
for (ParkLot item : ParkLot.values()) {
if (item.getValue().equals(value)) {
return item;
}
}
return UNKNOWN;
}
}
```
在枚举类型中,我们添加了一个 UNKNOWN 常量,并在 fromValue 方法中对其进行了处理。如果查询结果中的值在枚举范围内,则返回对应的枚举常量;否则,返回 UNKNOWN 常量。
在查询结果映射时,我们可以使用 MyBatis 的 ResultMap 注解来指定字段值到枚举类型的转换:
```java
@Results(id = "parkLotMap", value = {
@Result(property = "inOut", column = "in_out", javaType = ParkLot.class, typeHandler = EnumTypeHandler.class)
})
public interface CarDao {
@Select("SELECT * FROM car WHERE id = #{id}")
@ResultMap("parkLotMap")
Car findById(Long id);
}
```
在以上的代码中,我们使用了 @Result 注解来指定 in_out 字段对应的枚举类型为 ParkLot,typeHandler 使用了 MyBatis 自带的 EnumTypeHandler,用于将字符串类型转换为枚举类型。这样,在查询结果映射时,MyBatis 就可以自动将 in_out 字段的值转换为对应的 ParkLot 枚举类型。
ExcelUtil<ParkLot> util = new ExcelUtil<ParkLot>(ParkLot.class); response.setHeader("Content-Disposition", "attachment;filename=" + "parkLot.xlsx"); util.exportExcel(response,list,"parklots");什么意思
这段代码是使用ExcelUtil工具类导出Excel文件,具体含义如下:
1. `ExcelUtil<ParkLot> util = new ExcelUtil<ParkLot>(ParkLot.class);`:创建一个ExcelUtil对象并指定泛型类型为ParkLot,用于处理ParkLot类型的数据。
2. `response.setHeader("Content-Disposition", "attachment;filename=" + "parkLot.xlsx");`:设置响应头,告诉浏览器以附件形式下载文件,文件名为parkLot.xlsx。
3. `util.exportExcel(response,list,"parklots");`:调用ExcelUtil对象的exportExcel方法,将list中的数据导出为Excel文件,并写入到response中。
其中,list为要导出的数据,"parklots"为Excel文件的sheet名称。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![m](https://img-home.csdnimg.cn/images/20210720083646.png)
![m](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)