项目——通过自动回复机器人学Mybatis(五)

来源:互联网 发布:572-393的简便算法 编辑:程序博客网 时间:2024/05/22 12:17

实现批量删除

Message.xml添加批量删除sql:

<delete id="deleteBatch" parameterType="java.util.List">  delete from message where id in(  <foreach collection="list" item="item" separator=",">  #{item}  </foreach>  )  </delete>




MessageDao:

public boolean deleteBatch(List<Integer> ids){DBAccess dbAccess = new DBAccess();SqlSession sqlSession=null;boolean is_ok=false;try {sqlSession=dbAccess.getSqlSession();//通过sqlSession执行SQL语句if(sqlSession.delete("Message.deleteBatch",ids)>0){is_ok=true;}sqlSession.commit();} catch (Exception e) {e.printStackTrace();}finally{if(sqlSession!=null){sqlSession.close();}}return is_ok;}



MaintainService:

public boolean deleteBatch(String[] ids){boolean is_ok=false;MessageDao messageDao=new MessageDao();List<Integer> idList=new ArrayList<Integer>();for(String id:ids){idList.add(Integer.valueOf(id));}is_ok=messageDao.deleteBatch(idList);return is_ok;}




deleteBatchServlet:

@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {//设置编码req.setCharacterEncoding("UTF-8");PrintWriter writer = resp.getWriter();String[] ids=req.getParameter("ids").split(",");     //页面传入多个idMaintainService maintainService = new MaintainService();if(maintainService.deleteBatch(ids)){writer.write("del_success");}else{writer.write("del_false");}writer.flush();writer.close();}@Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {// TODO Auto-generated method stubthis.doGet(req, resp);}




list.jsp:

<a class="btn03" href="javascript:deleteBatch('<%=basePath%>');">删 除</a>




list.js:

/** * 调用后台批量删除方法 */function deleteBatch(basePath) {var url=basePath+"del_Bat.action";var ids=""; $("input:checkbox[name='id']:checked").each(function(){ //遍历选中checkbox            ids+=$(this).val()+","; //获取被选中的值    });if(ids.length > 0) //如果获取到        ids = ids.substring(0, ids.length - 1); //把最后一个逗号去掉$.ajax({type:"post",url:url,data:{"ids":ids},async:false,success:function(data){if(jQuery.isEmptyObject(data)){return;}else{if(data=="del_success"){alert("删除成功");}else if(data=="del_false"){alert("删除失败");}    window.location.reload();}    },    error:function(data){    alert("请求失败");}});}



实现自动回复功能

1.跳转到talk.jsp的InitTalkServlet:

@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {req.setCharacterEncoding("UTF-8");req.getRequestDispatcher("/WEB-INF/jsp/front/talk.jsp").forward(req, resp);}@Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {// TODO Auto-generated method stubthis.doGet(req, resp);}



2.talk.jsp主体

<body><input type="hidden" value="<%= basePath %>" id="basePath"/><br/><div class="talk"><div class="talk_title"><span>正在与公众号对话</span></div><div class="talk_record"><div id="jp-container" class="jp-container"></div></div><div class="talk_word"> <input class="add_face" id="facial" type="button" title="添加表情" value="" /><input id="content" class="messages emotion"   /><input class="talk_send" onclick="send();" type="button" title="发送" value="发送" /></div></div><div style="text-align:center;margin:50px 0; font:normal 14px/24px 'MicroSoft YaHei';"></div></body>


3.talk.js

/** * 页面加载 */$(function(){render();var content = "客官,来啦,坐吧!<br/>回复[查看]收取更多精彩内容。";content += "<br/>回复[帮助]可以查看所有可用的指令。";// 添加公众号的开场白appendDialog("talk_recordbox","公众号",content);render();});/** * 发送消息 * @param basePath */function send() {var content = $("#content").val();if(!content) {alert("请输入内容!");return;}$.ajax({url : $("#basePath").val() + "auto_reply.action",type : "POST",dataType : "text",timeout : 10000,data : {"content":content},success : function (data) {appendDialog("talk_recordboxme","My账号",content);appendDialog("talk_recordbox","公众号",data);$("#content").val("");render();}});}/** * 渲染方法,加载滚动条 */function render() {// the element we want to apply the jScrollPanevar $el= $('#jp-container').jScrollPane({verticalGutter : -16}),// the extension functions and options extensionPlugin = {extPluginOpts: {// speed for the fadeOut animationmouseLeaveFadeSpeed: 500,// scrollbar fades out after hovertimeout_t millisecondshovertimeout_t: 1000,// if set to false, the scrollbar will be shown on mouseenter and hidden on mouseleave// if set to true, the same will happen, but the scrollbar will be also hidden on mouseenter after "hovertimeout_t" ms// also, it will be shown when we start to scroll and hidden when stoppinguseTimeout: true,// the extension only applies for devices with width > deviceWidthdeviceWidth: 980},hovertimeout: null, // timeout to hide the scrollbarisScrollbarHover: false,// true if the mouse is over the scrollbarelementtimeout: null,// avoids showing the scrollbar when moving from inside the element to outside, passing over the scrollbarisScrolling: false,// true if scrollingaddHoverFunc: function() {// run only if the window has a width bigger than deviceWidthif( $(window).width() <= this.extPluginOpts.deviceWidth ) return false;var instance= this;// functions to show / hide the scrollbar$.fn.jspmouseenter = $.fn.show;$.fn.jspmouseleave = $.fn.fadeOut;// hide the jScrollPane vertical barvar $vBar= this.getContentPane().siblings('.jspVerticalBar').hide();/* * mouseenter / mouseleave events on the main element * also scrollstart / scrollstop - @James Padolsey : http://james.padolsey.com/javascript/special-scroll-events-for-jquery/ */$el.bind('mouseenter.jsp',function() {// show the scrollbar$vBar.stop( true, true ).jspmouseenter();if( !instance.extPluginOpts.useTimeout ) return false;// hide the scrollbar after hovertimeout_t msclearTimeout( instance.hovertimeout );instance.hovertimeout = setTimeout(function() {// if scrolling at the moment don't hide itif( !instance.isScrolling )$vBar.stop( true, true ).jspmouseleave( instance.extPluginOpts.mouseLeaveFadeSpeed || 0 );}, instance.extPluginOpts.hovertimeout_t );}).bind('mouseleave.jsp',function() {// hide the scrollbarif( !instance.extPluginOpts.useTimeout )$vBar.stop( true, true ).jspmouseleave( instance.extPluginOpts.mouseLeaveFadeSpeed || 0 );else {clearTimeout( instance.elementtimeout );if( !instance.isScrolling )$vBar.stop( true, true ).jspmouseleave( instance.extPluginOpts.mouseLeaveFadeSpeed || 0 );}});if( this.extPluginOpts.useTimeout ) {$el.bind('scrollstart.jsp', function() {// when scrolling show the scrollbarclearTimeout( instance.hovertimeout );instance.isScrolling= true;$vBar.stop( true, true ).jspmouseenter();}).bind('scrollstop.jsp', function() {// when stop scrolling hide the scrollbar (if not hovering it at the moment)clearTimeout( instance.hovertimeout );instance.isScrolling= false;instance.hovertimeout = setTimeout(function() {if( !instance.isScrollbarHover )$vBar.stop( true, true ).jspmouseleave( instance.extPluginOpts.mouseLeaveFadeSpeed || 0 );}, instance.extPluginOpts.hovertimeout_t );});// wrap the scrollbar// we need this to be able to add the mouseenter / mouseleave events to the scrollbarvar $vBarWrapper= $('<div/>').css({position: 'absolute',left: $vBar.css('left'),top: $vBar.css('top'),right: $vBar.css('right'),bottom: $vBar.css('bottom'),width: $vBar.width(),height: $vBar.height()}).bind('mouseenter.jsp',function() {clearTimeout( instance.hovertimeout );clearTimeout( instance.elementtimeout );instance.isScrollbarHover= true;// show the scrollbar after 100 ms.// avoids showing the scrollbar when moving from inside the element to outside, passing over the scrollbarinstance.elementtimeout= setTimeout(function() {$vBar.stop( true, true ).jspmouseenter();}, 100 );}).bind('mouseleave.jsp',function() {// hide the scrollbar after hovertimeout_tclearTimeout( instance.hovertimeout );instance.isScrollbarHover= false;instance.hovertimeout = setTimeout(function() {// if scrolling at the moment don't hide itif( !instance.isScrolling )$vBar.stop( true, true ).jspmouseleave( instance.extPluginOpts.mouseLeaveFadeSpeed || 0 );}, instance.extPluginOpts.hovertimeout_t );});$vBar.wrap( $vBarWrapper );}}},// the jScrollPane instancejspapi = $el.data('jsp');// extend the jScollPane by merging$.extend( true, jspapi, extensionPlugin );jspapi.addHoverFunc();}/** * 向聊天记录中添加聊天内容 * @param myClass 添内容的样式 * @param name 发送消息的账号名称 * @param content 发送的内容 */function appendDialog(myClass,name,content) {var div = "";div += "<div class='" + myClass + "'>";div += "<div class='user'><img src='" + $("#basePath").val() + "resources/images/thumbs/" + myClass + ".jpg'/>" + name + "</div>";div += "<div class='talk_recordtextbg'> </div>";div += "<div class='talk_recordtext'>";div += "<h3>" + content + "</h3>";div += "<span class='talk_time'>" + getCurrentDate() + "</span>";div += "</div>";div += "</div>";$('#jp-container').children().eq(0).children().eq(0).append(div);}
我是主搞后端的,基本的js和ajax还是懂得,但是上面的渲染方法render()还是有点不大懂,不过我还是会继续深入学前端和js等等,毕竟不想当将军(全栈工程师、架构师)的士兵不是好士兵奋斗




演示:









阅读全文
0 0