第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將 SQL 查詢放入 CrudRepository 中以限制列(以及此后的進一步 SQL 查詢)

將 SQL 查詢放入 CrudRepository 中以限制列(以及此后的進一步 SQL 查詢)

滄海一幻覺 2023-09-20 14:52:26
我正在開發(fā)一個 Spring 應(yīng)用程序,它記錄用戶請求響應(yīng)(將其發(fā)送到數(shù)據(jù)庫并檢索它)。獲取記錄代碼是這樣的(控制器):/**     * this method fetches all userrequest response records from user_request_response table     * @return     */    @CrossOrigin(origins = "*")    @GetMapping(path="/all")    public @ResponseBody Iterable<UserRequestResponse> getAllRequestResponseRecords() {        return userRequestResponseRepository.findAll();    }Dao code:import org.springframework.data.jpa.repository.Query;import org.springframework.data.repository.CrudRepository;import com.abc.datacollection.entity.UserProjection;import com.abc.datacollection.entity.UserRequestResponse;public interface UserRequestResponseRepository extends CrudRepository<UserRequestResponse, Integer> {public static final String FIND_QUERY =             "select new com.abc.datacollection.entity.UserRequestResponse(user.u_httpstatus ,user.u_queryparam) from UserRequestResponse user";    @Query(value = FIND_QUERY)    List<UserProjection> getAllRequestResponseRecords();}具有 getter 和 setter 的類:(刪除了一些變量及其 getter 和 setter)import java.sql.Date;import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.GenerationType;import javax.persistence.Id;@Entity // This tells Hibernate to make a table out of this classpublic class UserRequestResponse {    @Id    @GeneratedValue(strategy = GenerationType.IDENTITY)    private String u_httpstatus;    private String u_error_message;    private String u_queryparam;public UserRequestResponse(String u_httpstatus, String u_queryparam) {        this.u_httpstatus = u_httpstatus;        this.u_queryparam = u_queryparam;    }    public int getSys_id() {        return sys_id;    }public String getU_httpstatus() {            return u_httpstatus;        }MySQL查詢示例(我試圖將查詢放入CrudRepository中的java代碼中,InternSearchAnalytics.user_request_response是表的名稱):select u_httpstatus, u_queryparam from InternSearchAnalytics.user_request_response但是,當我運行 java 代碼并點擊生成的端點時,我得到了所有字段。有人可以幫我嗎?我已經(jīng)被這個問題困擾了兩天了。
查看完整描述

1 回答

?
烙印99

TA貢獻1829條經(jīng)驗 獲得超13個贊

您可以使用類中的新構(gòu)造函數(shù)從查詢中獲取選定的字段,UserRequestResponse例如


public UserRequestResponse(String u_httpstatus, String u_queryparam) {

    this.u_httpstatus = u_httpstatus;

    this.u_queryparam = u_queryparam;

}

對于查詢,您應(yīng)該使用構(gòu)造函數(shù)更改它


public static final String FIND_QUERY = 

                    "select new com.your.package.name.UserRequestResponse(user.u_httpstatus ,user.u_queryparam) from UserRequestResponse user";

一點是您需要使用具有完全限定名稱的構(gòu)造函數(shù)。希望這可以幫助。


查看完整回答
反對 回復 2023-09-20
  • 1 回答
  • 0 關(guān)注
  • 95 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號