@Data
@Entity
@Table(name="weather_daily")
@DynamicInsert
@DynamicUpdate
@NoArgsConstructor
@AllArgsConstructor
public class Dataset_info {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="daily_id",columnDefinition = "INT(11)")
private int Daily_id;
private BigDecimal w_avg_ta;
}
这是我的Dataset_info代码
public interface DatasetRepository extends JpaRepository<Dataset_info,Integer> {
@Query(value = "select w_avg_ta from weather_daily where w_date like concat('%',:query,'%')",nativeQuery = true)
public List<weather_avg> findByDataset(@Param("query") String query);
}
这是我的DatasetRepository代码
package kr.co.ds.datastation.dsapi.repository;
public interface weather_avg {
public String w_avg_ta();
}
这是我的weather_avg代码
@RestController
@RequestMapping(value = "/dataset")
@Slf4j
public class DatasetController {
@Autowired DatasetRepository datasetRepository;
@RequestMapping(value = "/list",method = RequestMethod.GET)
@ResponseBody
public String getDomainList(@RequestParam("query")String query) {
List<String> sj = new ArrayList<String>();
List<weather_avg> list= this.datasetRepository.findByDataset(query);
for (int i = 0; i < list.size(); i++) {
sj.add(list.get(i).w_avg_ta());
}
String all = sj.stream().collect(Collectors.joining("<br>"));
return all;
//log.info(query);
//return "Test";
}
}
这是我的DatasetController代码
List<weather_avg> dataset_infoList = this.datasetRepository.findByDataset(".go.");
这是我的应用程序代码
因此此代码正在运行,但是当我使用此代码进行调试时得到了结果 这是例子
http://localhost:8080/dataset/list?query=2019-09-29
我在互联网上打字 通常会显示查询结果
23.8(type is decimal(6,1))
但不是
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
[Request processing failed; nested exception is java.lang.IllegalArgumentException: Invoked
method public abstract java.lang.String
kr.co.ds.datastation.dsapi.repository.weather_avg.w_avg_ta() is no accessor method!] with root
cause
这是我的错误消息..实际上我不明白为什么它不起作用,所以如果有人知道如果您也没有提醒我包含的解决方案,请plz教我