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