Caused by: org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 15
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:66)
at sun.reflect.GeneratedMethodAccessor70.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:354)
... 76 more
接口中代码
public Boolean hasThisKwordId(String KwordId)throws Exception;
public String findLastKwordId(String parentid)throws Exception;
Controller中代码
@RequestMapping(value="/validate")
@ResponseBody
public Object validateKwords() throws Exception {
PageData pd = new PageData();
Map<String,Object> map = new HashMap<String,Object>();
pd = this.getPageData();
if (kwordsService.findById(pd)!=null) {
map.put("msg", "true");
}else{
map.put("msg", "false");
}
return AppUtil.returnObject(pd, map);
}
@RequestMapping(value="/findkwordid")
@ResponseBody
public Object findKwordId() throws Exception{
PageData pd = new PageData();
Map<String,Object> map = new HashMap<String,Object>();
pd = this.getPageData();
String nextKwordid=getNextKwordId(pd.getString("parentid"));
map.put("nextKwordid", nextKwordid);
return AppUtil.returnObject(pd, map);
}
private String getNextKwordId(String parentid) throws Exception {
String lastKwordId=kwordsService.findLastKwordId(parentid);
String nextKwordId="";
if (StringUtil.isNullOrEmpty(lastKwordId)) {
nextKwordId=CodeConst.KWORDS_KWORDID_ROOT.equals(parentid)
?CodeConst.KWORDS_KWORDID_START
:parentid+CodeConst.KWORDS_KWORDID_START;
}else {
if (lastKwordId.length()>CodeConst.KWORDS_KWORDID_INTERVAL) {
nextKwordId=parentid+StringUtil.haoAddOne(lastKwordId.substring(lastKwordId.length()-CodeConst.KWORDS_KWORDID_INTERVAL,lastKwordId.length()),CodeConst.KWORDS_KWORDID_FORMAT);
}else {
nextKwordId=StringUtil.haoAddOne(lastKwordId, CodeConst.KWORDS_KWORDID_FORMAT);
}
}
return nextKwordId;
}
Mapper中代码
<select id="hasThisKwordId" parameterType="String" resultType="int">
select
count(0)
from
<include refid="tableName"></include>
where
KWORDID = #{KWORDID}
</select>
<select id="findLastKwordId" parameterType="String" resultType="String">
select
KWORDID
from
<include refid="tableName"></include>
where PARENTID=#{PARENTID}
order by KWORDID desc
limit 0,1
</select>
jsp中代码
function validateKwordId(str){
var parentid=$("#PARENTID").val()
var result=false
$.ajax({
url:'kwords/validate',
data:{PARENTID:parentid,KWORDID:str},
async:false,
dataType:'json',
type:'post',
success:function(resp){
if(resp.msg=='true'){
result=true
}
}
});
return result;
}
function validateKwordName(str){
var parentid=$("#PARENTID").val()
var result=false
$.ajax({
url:'kwords/validate',
data:{PARENTID:parentid,KWORDNAME:str},
async:false,
dataType:'json',
type:'post',
success:function(resp){
if(resp.msg=='true'){
result=true
}
}
});
return result;
}
function changeParentid(){
var pid=$("#PARENTID").val()
$.ajax( {
type : "POST",
url : "kwords/findkwordid",
data : "parentid=" + pid,
success : function(data) {
$("#KWORDID").val(data.nextKwordId);
if(validateKwordName($("#KWORDNAME").val())){
$("#KWORDNAME").tips({
side:3,
msg:'主题名称重复,请更换',
bg:'#AE81FF',
time:2
});
$("#KWORDNAME").focus();
}
},
error : function() {
$("#KWORDID").tips({
side:3,
msg:'主题代码变更失败',
bg:'#AE81FF',
time:2
});
$("#KWORDID").focus();
}
});
}