Skip to content

Commit 2603a8b

Browse files
committed
findByNameContainingIgnoreCaseAndDateBefore throw NullPointerException. Fixes #2010
1 parent e8c6430 commit 2603a8b

File tree

6 files changed

+1018
-1
lines changed

6 files changed

+1018
-1
lines changed

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/data/DataRestOperationService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ private Type getParameterType(String pName, Method method, ResourceDescription d
239239
java.lang.reflect.Parameter[] parameters = method.getParameters();
240240
for (int i = 0; i < parameters.length; i++) {
241241
java.lang.reflect.Parameter parameter = parameters[i];
242-
if (pName.equals(parameter.getName()) || pName.equals(parameter.getAnnotation(Param.class).value())) {
242+
if (pName.equals(parameter.getName()) || (parameter.getAnnotation(Param.class)!=null && pName.equals(parameter.getAnnotation(Param.class).value()))) {
243243
ResolvableType resolvableType = ResolvableType.forMethodParameter(method, i);
244244
type = resolvableType.getType();
245245
break;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package test.org.springdoc.api.app37;
2+
3+
import java.io.Serializable;
4+
5+
import jakarta.persistence.Column;
6+
import jakarta.persistence.GeneratedValue;
7+
import jakarta.persistence.GenerationType;
8+
import jakarta.persistence.Id;
9+
import jakarta.persistence.MappedSuperclass;
10+
import lombok.Data;
11+
import lombok.NoArgsConstructor;
12+
import lombok.experimental.SuperBuilder;
13+
import org.hibernate.annotations.DynamicInsert;
14+
import org.hibernate.annotations.DynamicUpdate;
15+
16+
/**
17+
* @author bnasslahsen
18+
*/
19+
20+
@Data
21+
@MappedSuperclass
22+
@DynamicInsert(true)
23+
@DynamicUpdate(true)
24+
@SuperBuilder(toBuilder = true)
25+
@NoArgsConstructor
26+
public abstract class BaseEntity implements Serializable {
27+
28+
/** SVUDI */
29+
private static final long serialVersionUID = 1L;
30+
31+
/** 数据库中的ID */
32+
@Id
33+
@GeneratedValue(strategy = GenerationType.IDENTITY)
34+
@Column(name = "ID", unique = true, nullable = false, insertable = false, updatable = false)
35+
private Long id;
36+
37+
38+
/**
39+
* 数据是否合法
40+
*
41+
* @return 是否合法
42+
*/
43+
public abstract boolean isValid();
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package test.org.springdoc.api.app37;
2+
3+
import java.math.BigDecimal;
4+
import java.time.LocalDate;
5+
6+
import jakarta.persistence.Column;
7+
import jakarta.persistence.Entity;
8+
import jakarta.persistence.Table;
9+
import jakarta.validation.constraints.NotNull;
10+
import lombok.EqualsAndHashCode;
11+
import lombok.Getter;
12+
import lombok.NoArgsConstructor;
13+
import lombok.Setter;
14+
import lombok.ToString;
15+
import lombok.experimental.SuperBuilder;
16+
17+
/**
18+
* @author bnasslahsen
19+
*/
20+
21+
@Getter
22+
@Setter
23+
@ToString(callSuper = true)
24+
@EqualsAndHashCode(callSuper = false)
25+
@Entity
26+
@Table(name = "PRODUCT_ENTITY")
27+
@SuperBuilder(toBuilder = true)
28+
@NoArgsConstructor
29+
public class ProductEntity extends BaseEntity implements Comparable<ProductEntity> {
30+
31+
/** SVUDI */
32+
private static final long serialVersionUID = 1L;
33+
34+
/** 名字. */
35+
@NotNull
36+
@Column(nullable = false)
37+
private String name;
38+
39+
/** 单价. */
40+
@NotNull
41+
@Column(nullable = false)
42+
private BigDecimal price;
43+
44+
/** 日期. */
45+
@NotNull
46+
@Column(nullable = false)
47+
private LocalDate date;
48+
49+
@Override
50+
public boolean isValid() {
51+
return name != null && price != null && date != null;
52+
}
53+
54+
/** 根据日期排序 */
55+
@Override
56+
public int compareTo(ProductEntity oProduct) {
57+
return this.getDate().compareTo(oProduct.getDate());
58+
}
59+
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package test.org.springdoc.api.app37;
2+
3+
/**
4+
* @author bnasslahsen
5+
*/
6+
7+
import java.time.LocalDate;
8+
import java.util.List;
9+
10+
import ch.qos.logback.core.rolling.helper.DateTokenConverter;
11+
import io.swagger.v3.oas.annotations.Parameter;
12+
13+
import org.springframework.data.jpa.repository.JpaRepository;
14+
import org.springframework.data.repository.query.Param;
15+
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
16+
import org.springframework.format.annotation.DateTimeFormat;
17+
18+
/**
19+
* 商品信息
20+
*
21+
* @author zctmdc
22+
*/
23+
@RepositoryRestResource(path = "product")
24+
public interface ProductRepository extends JpaRepository<ProductEntity, Long> {
25+
26+
/**
27+
* 根据商品名称查询商品信息
28+
*
29+
* @param name 商品名称
30+
* @return 商品信息列表
31+
*/
32+
List<ProductEntity> findByName(@Parameter(name = "name2", required = true) String name);
33+
34+
/**
35+
* 根据商品名称查询最新的商品信息
36+
*
37+
* @param name 商品名称
38+
* @return 商品信息
39+
*/
40+
ProductEntity findTopByNameOrderByDateDesc(@Parameter(name = "name2", required = true) String name);
41+
42+
/**
43+
* 根据商品名称模糊查询商品信息并按时间降序排序
44+
*
45+
* @param name 商品名称
46+
* @return 商品信息列表
47+
*/
48+
List<ProductEntity> findByNameContainingIgnoreCaseOrderByDateDesc(
49+
@Parameter(name = "name2", required = true) String name);
50+
51+
/**
52+
* 根据商品名称模糊查询商品信息并按时间降序排序
53+
*
54+
* @param name 商品名称
55+
* @return 商品信息列表
56+
*/
57+
List<ProductEntity> findByNameContainingIgnoreCase(
58+
@Parameter(name = "name2", required = true) String name);
59+
60+
/**
61+
* 根据商品名称模糊查询指定日期前的商品信息
62+
*
63+
* @param end 指定日期结束
64+
* @return 商品信息列表
65+
*/
66+
List<ProductEntity> findByDateBefore(
67+
@Parameter(name = "end2", required = true) @DateTimeFormat(pattern = DateTokenConverter.DEFAULT_DATE_PATTERN) @Param("end") LocalDate end);
68+
69+
/**
70+
* 根据商品名称模糊查询指定日期前的商品信息
71+
*
72+
* @param name 商品名称
73+
* @param end 指定日期结束
74+
* @return 商品信息列表
75+
*/
76+
List<ProductEntity> findByNameContainingIgnoreCaseAndDateBefore(
77+
@Parameter(name = "name2", required = true) String name,
78+
@Parameter(name = "end2", required = true) @DateTimeFormat(pattern = DateTokenConverter.DEFAULT_DATE_PATTERN) @Param("end") LocalDate end);
79+
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
*
3+
* * Copyright 2019-2022 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app37;
20+
21+
import test.org.springdoc.api.AbstractSpringDocTest;
22+
23+
import org.springframework.boot.autoconfigure.SpringBootApplication;
24+
25+
public class SpringDocApp37Test extends AbstractSpringDocTest {
26+
27+
@SpringBootApplication
28+
static class SpringDocTestApp {
29+
30+
}
31+
32+
}

0 commit comments

Comments
 (0)