each用法、mybatis傳遞多個參數方法

//獲取當前月份

var yearMonth = date.getFullYear()+"-"+(date.getMonth()+1);

//select動態顯示

var html = "<option  value='-1'>請選擇</option>";
$.each(data, function(i, trObj){
html += "<option  value='"+trObj.id+"'>"+trObj.name+"</option>";
});
if(level ==2)
{
$("#entryDeptBuEdit").empty();
$('#entryDeptBuEdit').append(html);
$("#sensitive_bu").empty();
$('#sensitive_bu').append(html);
}


//多個查詢條件的mybatis方法

//1.map方法

//service層

@Override
public BoleRecommend checkIdCardEffective(String idCard) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
String currentDate = format.format(new Date());
Map<String, String> map = new HashMap<String, String>();
map.put("idCard",idCard);
map.put("date",currentDate);
BoleRecommend bole = boleRecomDao.checkIdCardEffective(map);
return bole;
}

//Dao層

public BoleRecommend checkIdCardEffective(Map<String, String> map);

//mapper.xml層

<select id="checkIdCardEffective" resultMap="boleRecommendBean" parameterType ="map">
select * from bole_recommend_t where yearmonth=#{date} and ID_num = #{idCard}
</select>

//2.註解方法

@RequestMapping(value = "/getWebsiteByChannel")
public void getWebsiteByChannel(String recruitChannel,String year ,String month, HttpServletResponse response) {
JsonArray jo = channelAnalysisService.getWebsiteByChannel(recruitChannel, year, month);
try {
response.getWriter().print(jo.toString());
} catch (IOException e) {
e.printStackTrace();
}
}

@Override
public JsonArray getWebsiteByChannel(String recruitChannel, String year, String month) {
JsonArray ja = new JsonArray();
List<ChannelAnalysis> list = channelAnalysisMapper.getWebsiteByChannel(recruitChannel, year, month);
for (int i = 0; i < list.size(); i++) {
JsonObject jo = new JsonObject();
jo.addProperty("year", list.get(i).getYear());
jo.addProperty("month", list.get(i).getMonth());
jo.addProperty("recruitWebsite", list.get(i).getRecruitWebsite());
jo.addProperty("channelMonthNum", list.get(i).getChannelMonthNum());
ja.add(jo);
}
return ja;
}

public List<ChannelAnalysis> getRecruitWebsiteByCenter(@Param("recruitCenter")String recruitCenter,@Param("year")String year,@Param("month")String month);

<select id="getRecruitWebsiteByCenter" resultMap="ChannelAnalysisBean" >
select 

from  
recruite_channel_show_t 
where 
recruit_website IS null AND recruit_center=#{recruitCenter} AND year=#{year} AND month=#{month}
</select>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章