<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                前章已介紹過`APT`,在這里有所涉及,通過配置pom.xml build plugin,當實體類為SLog,那么會生成一個QSLog,理論上寫也是可以的(已測試) > 本框架主要封裝常用操作,更多見[官方文檔](http://www.querydsl.com/static/querydsl/latest/reference/html/index.html) ### 依賴模塊 ``` <!-- https://mvnrepository.com/artifact/com.querydsl/querydsl-jpa --> <dependency> <groupId>com.querydsl</groupId> <artifactId>querydsl-jpa</artifactId> </dependency> <!-- https://mvnrepository.com/artifact/com.querydsl/querydsl-apt --> <dependency> <groupId>com.querydsl</groupId> <artifactId>querydsl-apt</artifactId> <scope>provided</scope> </dependency> ``` ### 依賴插件 ``` <!-- 編譯 --> <build> <finalName>gotv-admin</finalName> <plugins> <!-- QDSL --> <plugin> <groupId>com.mysema.maven</groupId> <artifactId>apt-maven-plugin</artifactId> <version>1.1.3</version> <executions> <execution> <goals> <goal>process</goal> </goals> <configuration> <outputDirectory>target/generated-sources/java</outputDirectory> <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor> </configuration> </execution> </executions> <dependencies> <dependency> <groupId>com.querydsl</groupId> <artifactId>querydsl-apt</artifactId> <version>${querydsl.version}</version> </dependency> </dependencies> </plugin> </plugins> </build> ``` ### 生成示例 實體類 ``` @Data @Accessors(chain = true) @EqualsAndHashCode(callSuper = false) @FieldNameConstants(innerTypeName = "FIELDS") @Table(name = "mis_log") @Entity @EntityListeners(AuditingEntityListener.class) @DynamicInsert @DynamicUpdate public class LogRecord extends JpaPlusEntity<LogRecord> { private static final long serialVersionUID = 1L; /** * 主鍵,例(L1408447004119666688) */ @Id @GeneratedValue(generator = "idGenerator") @GenericGenerator(name = "idGenerator", // 名稱 strategy = "com.xiesx.FastBoot.db.jpa.identifier.IdWorkerGenerator", // 生成策略 parameters = {// 生成參數 @Parameter(name = "prefix", value = "L"), // 前綴,L @Parameter(name = "workerId", value = "1"), // 終端ID,默認0 @Parameter(name = "centerId", value = "1") // 數據中心ID,默認0 }) @JSONField(ordinal = 1) private String id; /** * 創建時間 */ @CreatedDate @Column(updatable = false, nullable = false) @JSONField(ordinal = 2) private Date createTime; /** * 修改時間 */ @LastModifiedDate @Column(nullable = false) @JSONField(ordinal = 3) private Date updateTime; /** * 請求IP */ @Column @JSONField(ordinal = 4) private String ip; /** * 方法 */ @Column @JSONField(ordinal = 5) private String method; /** * 方式 */ @Column @JSONField(ordinal = 6) private String type; /** * 地址 */ @Column @JSONField(ordinal = 7) private String url; /** * 請求參數 */ @JSONField(serialize = false) private String req; /** * 響應結果 */ @JSONField(serialize = false) private String res; /** * 執行時間(毫秒) */ @Column @JSONField(ordinal = 10) private Long t; /** * 操作人 */ @LastModifiedBy @Column @JSONField(ordinal = 11, serialize = false) private String opt; // ====================== @Transient @JSONField(serialize = false, ordinal = 8) public Object getParams() { return JSON.parse(req); } @Transient @JSONField(serialize = false, ordinal = 9) public Object getResult() { return JSON.parse(res); } } ``` Q實體類 ``` @Generated("com.querydsl.codegen.EntitySerializer") public class QLogRecord extends EntityPathBase<LogRecord> { private static final long serialVersionUID = 261544295L; public static final QLogRecord logRecord = new QLogRecord("logRecord"); public final DateTimePath<java.util.Date> createTime = createDateTime("createTime", java.util.Date.class); public final StringPath id = createString("id"); public final StringPath ip = createString("ip"); public final StringPath method = createString("method"); public final StringPath opt = createString("opt"); public final StringPath req = createString("req"); public final StringPath res = createString("res"); public final NumberPath<Long> t = createNumber("t", Long.class); public final StringPath type = createString("type"); public final DateTimePath<java.util.Date> updateTime = createDateTime("updateTime", java.util.Date.class); public final StringPath url = createString("url"); public QLogRecord(String variable) { super(LogRecord.class, forVariable(variable)); } public QLogRecord(Path<? extends LogRecord> path) { super(path.getType(), path.getMetadata()); } public QLogRecord(PathMetadata metadata) { super(LogRecord.class, metadata); } } ``` ### 如何使用 方式1 ``` @Autowired JPAQueryFactory mJPAQueryFactory; ``` 方式2 ``` JPAQueryFactory mJPAQueryFactory = SpringHelper.getBean(JPAQueryFactory.class); ``` 查詢對象 ``` QLogRecord ql = QLogRecord.logRecord; ``` 條件查詢 ``` List<SLog> logs = mJPAQueryFactory.selectFrom(ql) .where( ql.method.eq("POST"), ql.method.eq("GET")) .fetch(); ``` 排序查詢 ``` List<SLog> logs = mJPAQueryFactory.selectFrom(ql) .orderBy(ql.createDate.desc(),ql.t.asc()) .fetch(); ``` 聚合查詢 ``` List<Person> persons = mJPAQueryFactory.selectFrom(person) .where(person.children.size() .eq(JPAExpressions.select(parent.children.size().max()).from(parent))) .fetch(); ``` 投影查詢 ``` List<Tuple> tuples = mJPAQueryFactory .select( ql.method, ql.type, ql.url) .from(qSLog) .fetch(); ``` 添加 ``` 待補充 ``` 修改 ``` int row = (int) mJPAQueryFactory.update(qu) .set(qu.status, 1) .where(qu.id.in(base.getIds())) .execute(); ``` 刪除 ``` int row = (int) mJPAQueryFactory.delete(qu) .where(qu.id.in(ids())) .execute(); ``` > 沒有什么框架是萬能,合適的才是最好的
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看