博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
获取数据库表中自增长最新的id
阅读量:5322 次
发布时间:2019-06-14

本文共 4147 字,大约阅读时间需要 13 分钟。

 

mybatis

<insert id="InsertCourse">

insert into
training_course(type_id,course_title,course_summary,coverimg_url,course_content,message_type,
create_date,create_by,creater_role_id,creater_party_id,corresponding_party_id,attach_url,corresponding_region_id,corresponding_country_id,state,levelone_type_id,leveltwo_type_id,levelthree_type_id)
values(#{typeId},#{courseTitle},#{courseSummary},#{coverImgUrl},#{courseContent},#{messageType},
#{createDate},#{createBy},#{createrRoleId},#{createrPartyId},#{correspondingPartyId},#{attachUrl},#{correspondingRegionId},#{correspondingCountryId},#{state},#{levelOneTypeId},#{levelTwoTypeId},#{levelThreeTypeId})
<selectKey keyProperty="courseId" order="AFTER" resultType="java.lang.Integer">
SELECT LAST_INSERT_ID()
</selectKey>

 

 

action层

  1. public void CreateCourse()
  2. {
  3. JSONObject result=new JSONObject();
  4. response.setHeader("Content-Type", "application/json");
  5. try{
  6. request.setCharacterEncoding("UTF-8");
  7. int typeId=Integer.parseInt(request.getParameter("typeId"));
  8. int levelOneTypeId = Integer.parseInt(request.getParameter("levelOneTypeId"));
  1. int levelTwoTypeId = Integer.parseInt(request.getParameter("levelTwoTypeId"));
  2. int levelThreeTypeId = Integer.parseInt(request.getParameter("levelThreeTypeId"));
  3. char messageType=request.getParameter("messageType").charAt(0);
  4. String title=request.getParameter("courseTitle");
  5. String coverImgUrl=request.getParameter("coverImgUrl");
  6. coverImgUrl=coverImgUrl.replace("/var/www/topsale/topsale/", "http://obctop.tcl.com.cn/topsale/");
  7. // String attamentUrl=request.getParameter("attamentUrl");
  8. // if(attamentUrl!=""){
  9. // attamentUrl=attamentUrl.replace("/var/www/topsale/topsale/", "http://obctop.tcl.com.cn/topsale/");
  10. // }
  11. String summary=request.getParameter("courseSummary");
  12. String content=request.getParameter("courseContent");
  13. String partyId=request.getParameter("partyId");
  14. String regionId=request.getParameter("regionId");
  15. String countryId=request.getParameter("countryId");
  16. content=content.replace("/var/www/topsale/topsale/","http://obctop.tcl.com.cn/topsale/");
  17. TrainingCourse course=new TrainingCourse();
  18. course.setTypeId(typeId);
  19. course.setLevelOneTypeId(levelOneTypeId);
  20. course.setLevelTwoTypeId(levelTwoTypeId);
  21. course.setLevelThreeTypeId(levelThreeTypeId);
  1. course.setMessageType(messageType);
  2. course.setCourseTitle(title);
  3. course.setCourseSummary(summary);
  4. course.setCourseContent(content);
  5. course.setCoverImgUrl(coverImgUrl);
  6. // course.setAttachUrl(attamentUrl);
  7. course.setCreateDate(new Date());
  8. course.setCreateBy(WebPageUtil.getLoginedUserId());
  9. course.setCreaterRoleId(WebPageUtil.getLoginedUser().getRoleId());
  10. course.setCreaterPartyId(WebPageUtil.getLoginedUser().getPartyId());
  11. course.setCorrespondingPartyId(partyId);
  12. course.setCorrespondingRegionId(regionId);
  13. course.setCorrespondingCountryId(countryId);
  14. course.setState("0");
  15. result.accumulate("msg","success");
  16. courseService.InsertCourse(course);
  1. String allUserStr = request.getParameter("allUserStr");
  2. String roleType = request.getParameter("roleTypeName");
  3. String roleId =UUID.randomUUID().toString().replace("-", "").toLowerCase();
  4. roleId = roleType + "_" + roleId;
  1. System.out.println(allUserStr+"------------------------");
  2. //创建消息
  3. Message msg = new Message();
  1. msg.setMsgType("1");
  2. msg.setMsgTitle(title);
  3. msg.setMsgComment(content);
  4. msg.setMsgTitleUrl("<a href=coursedetail.jsp?courseId="+course.getCourseId()+">"); //获取对象中的courseId
  5. msg.setCreateBy(WebPageUtil.getLoginedUserId());
  6. msg.setCreateTime(new Date());
  7. msg.setCreateCountryId(countryId);
  8. msg.setCreatePartyId(WebPageUtil.getLoginedUser().getPartyId());
  9. msg.setMsgRoleId(roleId);
  10. msg.setMsgSummary(summary);
  11. msg.setMsgCoverUrl(coverImgUrl);
  12. msg.setCourseId(String.valueOf(course.getCourseId()));
  13. messageService.insertMessage(msg,allUserStr);
  14. } catch (Exception e) {
  15. // TODO Auto-generated catch block
  16. e.printStackTrace();
  17. log.error(e.getMessage(), e);
  18. String msg = e.getCause()==null?e.getMessage():e.getCause().getMessage().replaceAll("\"", "").replaceAll("\n", "");
  19. result.accumulate("success", true);
  20. result.accumulate("msg", msg);
  21. }
  22. WebPageUtil.writeBack(result.toString());
  23. }

转载于:https://www.cnblogs.com/Yusco/p/7856382.html

你可能感兴趣的文章
安卓当中的线程和每秒刷一次
查看>>
wpf样式绑定 行为绑定 事件关联 路由事件实例
查看>>
TCL:表格(xls)中写入数据
查看>>
Oracle事务
查看>>
String类中的equals方法总结(转载)
查看>>
标识符
查看>>
一步步教你轻松学奇异值分解SVD降维算法
查看>>
内存地址对齐
查看>>
创新课程管理系统数据库设计心得
查看>>
Could not resolve view with name '***' in servlet with name 'dispatcher'
查看>>
[转载] redis 的两种持久化方式及原理
查看>>
MyBaits学习
查看>>
管道,数据共享,进程池
查看>>
[Cypress] Stub a Post Request for Successful Form Submission with Cypress
查看>>
SDUTOJ3754_黑白棋(纯模拟)
查看>>
php中的isset和empty的用法区别
查看>>
把word文档中的所有图片导出
查看>>
ubuntu 18.04取消自动锁屏以及设置键盘快捷锁屏
查看>>
Leetcode 589. N-ary Tree Preorder Traversal
查看>>
正则表达式
查看>>