MyBatis 3.4.5; @SelectProvider不替换参数占位符

时间:2019-04-23 04:22:17

标签: java mybatis

当我尝试使用MyBatis创建动态查询时,会成功生成sql,但不会在SQL占位符中替换参数。

映射器@SelectProvider定义

@SelectProvider(type = ActivitySqlProvider.class, method = "getActivitiesByUserAndType")
@ResultMap("activityResult")
List<Activities> getActivities(@Param("userId") long userId, @Param("type") String type);

ActivitySqlProvider类

public String getActivitiesByUserAndType(final Map<String, Object> params) {

  String COLUMNS = "ACTIVITYID, USERID, TYPE, CREATED, DESCRIPTION";
  String TABLE_NAME = "ACTIVITY";

  boolean hasType = params.containsKey("type");

  final String sql = new SQL() {{
    SELECT(COLUMNS);
    FROM(TABLE_NAME);
    WHERE("USERID = #{userId}");

    if (hasType) {
      WHERE("TYPE = #{type}");
    }

  }}.toString();

  System.out.println(sql);
  return sql;
}

SQL字符串正确打印,我可以看到占位符。不确定我缺少什么。

1 个答案:

答案 0 :(得分:1)

一个盲目的猜测:您使用了错误的async UPLOAD_IMAGES() { try { let self = this; var storageRef = firebase.storage().ref(); var files = document.getElementById("photoupload").files; var file = files[0]; // Create the file metadata var metadata = { contentType: "image/jpeg" }; // Upload file and metadata to the object 'images/mountains.jpg' var uploadTask = storageRef .child(`${this.name}/` + file.name) .put(file, metadata); // Listen for state changes, errors, and completion of the upload. uploadTask.on( firebase.storage.TaskEvent.STATE_CHANGED, // or 'state_changed' function(snapshot) { // Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded var progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100; console.log("Upload is " + progress + "% done"); switch (snapshot.state) { case firebase.storage.TaskState.PAUSED: // or 'paused' console.log("Upload is paused"); break; case firebase.storage.TaskState.RUNNING: // or 'running' console.log("Upload is running"); break; } }, function(error) { // A full list of error codes is available at // https://firebase.google.com/docs/storage/web/handle-errors switch (error.code) { case "storage/unauthorized": // User doesn't have permission to access the object break; case "storage/canceled": // User canceled the upload break; case "storage/unknown": // Unknown error occurred, inspect error.serverResponse break; } }, function() { // Upload completed successfully, now we can get the download URL uploadTask.snapshot.ref .getDownloadURL() .then(function(downloadURL) { console.log("File available at", downloadURL); self = downloadURL; }); } ); } catch (error) { console.log("ERR ===", error); alert("Image uploading failed!"); } }注释。

确保您具有: function() { // Upload completed successfully, now we can get the download URL uploadTask.snapshot.ref .getDownloadURL() .then(function(downloadURL) { console.log("File available at", downloadURL); self = downloadURL; }); }

,而不是: @Param

打印import org.apache.ibatis.annotations.Param;地图的内容以验证此声明。