-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
135 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
OnlineSurveyBackEnd/src/main/java/qdu/suvvm/onlinesurvey/mapper/ResultMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package qdu.suvvm.onlinesurvey.mapper; | ||
|
||
import org.apache.ibatis.annotations.*; | ||
import org.apache.ibatis.jdbc.SQL; | ||
import qdu.suvvm.onlinesurvey.pojo.Result; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @ClassName: ResultMapper | ||
* @Description: TODO | ||
* @Author: SUVVM | ||
* @Date: 2019/12/2 18:32 | ||
*/ | ||
public interface ResultMapper { | ||
|
||
@SelectProvider(type = ResultMapperProvider.class, method = "findRes") | ||
public List<Result> getResult(Result res); | ||
|
||
@Delete("delete from userresults where uid=#{uid}") | ||
public int deleteResultByUId(Integer uid); | ||
|
||
@Delete("delete from userresults where iid=#{iid}") | ||
public int deleteResultByIId(Integer iid); | ||
|
||
// 插入investigate并获取自增id | ||
@Options(useGeneratedKeys = true, keyProperty = "id") | ||
@Insert("insert into userresults(uid,iid,ans) values(#{uid},#{iid},#{ans})") | ||
public int insertResult(Result res); | ||
|
||
// 根据id更新investigate | ||
@Update("update from userresults set ans=#{ans} where iid=#{iid} && uid=##{uid}") | ||
public int updateResult(Result res); | ||
|
||
@Select("select * from userresults where uid=#{id}") | ||
public List<Result> getResultByUId(Integer id); | ||
|
||
@Select("select * from userresults where iid=#{id}") | ||
public List<Result> getResultByIId(Integer id); | ||
|
||
class ResultMapperProvider{ | ||
/** | ||
* @FunctionName: findRes | ||
* @Description: 用于生成查询作答的动态sql | ||
* @Parameter: | ||
* res 查询数据封装的回答类 | ||
* @Return: 返回对应sql语句 | ||
*/ | ||
public String findRes(Result res) { | ||
return new SQL() { | ||
{ | ||
SELECT("*"); | ||
FROM("userresults"); | ||
if(res.getUid() != null) { | ||
WHERE("uid = #{uid}"); | ||
} | ||
if(res.getIid() != null) { | ||
WHERE("iid=#{iid}"); | ||
} | ||
} | ||
}.toString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
OnlineSurveyBackEnd/src/main/java/qdu/suvvm/onlinesurvey/pojo/Result.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package qdu.suvvm.onlinesurvey.pojo; | ||
|
||
/** | ||
* @ClassName: Result | ||
* @Description: TODO | ||
* @Author: SUVVM | ||
* @Date: 2019/12/2 18:29 | ||
*/ | ||
public class Result { | ||
private Integer uid; | ||
private Integer iid; | ||
private String ans; | ||
|
||
public Integer getUid() { | ||
return uid; | ||
} | ||
|
||
public void setUid(Integer uid) { | ||
this.uid = uid; | ||
} | ||
|
||
public Integer getIid() { | ||
return iid; | ||
} | ||
|
||
public void setIid(Integer iid) { | ||
this.iid = iid; | ||
} | ||
|
||
public String getAns() { | ||
return ans; | ||
} | ||
|
||
public void setAns(String ans) { | ||
this.ans = ans; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Result{" + | ||
"uid=" + uid + | ||
", iid=" + iid + | ||
", ans='" + ans + '\'' + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters