Skip to content

Commit 488dd1f

Browse files
committed
findByNameContainingIgnoreCaseAndDateBefore throw NullPointerException. Fixes #2010
1 parent 3101081 commit 488dd1f

File tree

6 files changed

+1020
-1
lines changed

6 files changed

+1020
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ private Type getParameterType(String pName, Method method, ResourceDescription d
238238
java.lang.reflect.Parameter[] parameters = method.getParameters();
239239
for (int i = 0; i < parameters.length; i++) {
240240
java.lang.reflect.Parameter parameter = parameters[i];
241-
if (pName.equals(parameter.getName()) || pName.equals(parameter.getAnnotation(Param.class).value())) {
241+
if (pName.equals(parameter.getName()) || (parameter.getAnnotation(Param.class)!=null && pName.equals(parameter.getAnnotation(Param.class).value()))) {
242242
ResolvableType resolvableType = ResolvableType.forMethodParameter(method, i);
243243
type = resolvableType.getType();
244244
break;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package test.org.springdoc.api.app37;
2+
3+
import java.io.Serializable;
4+
5+
import javax.persistence.Column;
6+
import javax.persistence.GeneratedValue;
7+
import javax.persistence.GenerationType;
8+
import javax.persistence.Id;
9+
import javax.persistence.MappedSuperclass;
10+
11+
import lombok.Data;
12+
import lombok.NoArgsConstructor;
13+
import lombok.experimental.SuperBuilder;
14+
import org.hibernate.annotations.DynamicInsert;
15+
import org.hibernate.annotations.DynamicUpdate;
16+
17+
/**
18+
* @author bnasslahsen
19+
*/
20+
21+
@Data
22+
@MappedSuperclass
23+
@DynamicInsert(true)
24+
@DynamicUpdate(true)
25+
@SuperBuilder(toBuilder = true)
26+
@NoArgsConstructor
27+
public abstract class BaseEntity implements Serializable {
28+
29+
/** SVUDI */
30+
private static final long serialVersionUID = 1L;
31+
32+
/** 数据库中的ID */
33+
@Id
34+
@GeneratedValue(strategy = GenerationType.IDENTITY)
35+
@Column(name = "ID", unique = true, nullable = false, insertable = false, updatable = false)
36+
private Long id;
37+
38+
39+
/**
40+
* 数据是否合法
41+
*
42+
* @return 是否合法
43+
*/
44+
public abstract boolean isValid();
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package test.org.springdoc.api.app37;
2+
3+
import java.math.BigDecimal;
4+
import java.time.LocalDate;
5+
6+
import javax.persistence.Column;
7+
import javax.persistence.Entity;
8+
import javax.persistence.Table;
9+
import javax.validation.constraints.NotNull;
10+
11+
import lombok.EqualsAndHashCode;
12+
import lombok.Getter;
13+
import lombok.NoArgsConstructor;
14+
import lombok.Setter;
15+
import lombok.ToString;
16+
import lombok.experimental.SuperBuilder;
17+
18+
/**
19+
* @author bnasslahsen
20+
*/
21+
22+
@Getter
23+
@Setter
24+
@ToString(callSuper = true)
25+
@EqualsAndHashCode(callSuper = false)
26+
@Entity
27+
@Table(name = "PRODUCT_ENTITY")
28+
@SuperBuilder(toBuilder = true)
29+
@NoArgsConstructor
30+
public class ProductEntity extends BaseEntity implements Comparable<ProductEntity> {
31+
32+
/** SVUDI */
33+
private static final long serialVersionUID = 1L;
34+
35+
/** 名字. */
36+
@NotNull
37+
@Column(nullable = false)
38+
private String name;
39+
40+
/** 单价. */
41+
@NotNull
42+
@Column(nullable = false)
43+
private BigDecimal price;
44+
45+
/** 日期. */
46+
@NotNull
47+
@Column(nullable = false)
48+
private LocalDate date;
49+
50+
@Override
51+
public boolean isValid() {
52+
return name != null && price != null && date != null;
53+
}
54+
55+
/** 根据日期排序 */
56+
@Override
57+
public int compareTo(ProductEntity oProduct) {
58+
return this.getDate().compareTo(oProduct.getDate());
59+
}
60+
61+
}
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)