<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="cn.hpu.jk.mapper.FactoryMapper"> <!-- resultMap映射 --> <resultMap type="cn.hpu.jk.domain.Factory" id="factoryRM"> <!-- 主键 --> <id property="id" column="FACTORY_ID"/> <!-- 一般属性 --> <result property="fullName" column="FULL_NAME"/> <result property="factoryName" column="FACTORY_NAME"/> <result property="contacts" column="CONTACTS"/> <result property="phone" column="PHONE"/> <result property="mobile" column="MOBILE"/> <result property="fax" column="FAX"/> <result property="cnote" column="CNOTE"/> <result property="inspector" column="INSPECTOR"/> <result property="orderNo" column="ORDER_NO"/> <result property="createBy" column="CREATE_BY"/> <result property="creatDept" column="CREATE_DEPT"/> <result property="creatTime" column="CREATE_TIME"/> </resultMap> <!-- 查询 --> <select id="find" parameterType="map" resultMap="factoryRM"> select * from factory_c where 1=1 </select> <!-- 新增 oracle jbdc驱动当这个值为null时,必须告诉它当前字段 默认值的类型jdbcType=VARCHAR(MyBatis定义),Mysql不用写--> <insert id="insert" parameterType="cn.hpu.jk.domain.Factory"> insert into factory_c (FACTORY_ID,FULL_NAME,FACTORY_NAME,CONTACTS,PHONE,MOBILE,FAX,CNOTE, INSPECTOR,ORDER_NO,CREATE_BY,CREATE_DEPT,CREATE_TIME) values ( #{id}, #{fullName,jdbcType=VARCHAR}, #{factoryName,jdbcType=VARCHAR}, #{contacts,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, #{mobile,jdbcType=VARCHAR}, #{fax,jdbcType=VARCHAR}, #{cnote,jdbcType=VARCHAR}, #{inspector,jdbcType=VARCHAR}, #{orderNo,jdbcType=INTEGER}, #{createBy,jdbcType=VARCHAR}, #{creatDept,jdbcType=VARCHAR}, #{creatTime,jdbcType=TIMESTAMP} ) </insert> </mapper>
<!-- 修改语句 --> <update id="update" parameterType="cn.hpu.jk.domain.Factory"> update factory_c <set> <if test="fullName != null">FULL_NAME=#{fullName,jdbcType=VARCHAR},</if> <if test="factoryName != null">FACTORY_NAME=#{factoryName,jdbcType=VARCHAR},</if> <if test="contacts != null">CONTACTS=#{contacts,jdbcType=VARCHAR},</if> <if test="phone != null">PHONE=#{phone,jdbcType=VARCHAR},</if> <if test="mobile != null">MOBILE=#{mobile,jdbcType=VARCHAR},</if> <if test="fax != null">FAX=#{fax,jdbcType=VARCHAR},</if> <if test="cnote != null">CNOTE=#{cnote,jdbcType=VARCHAR},</if> <if test="inspector != null">INSPECTOR=#{inspector,jdbcType=VARCHAR},</if> <if test="orderNo != null">ORDER_NO=#{orderNo,jdbcType=INTEGER},</if> </set> where FACTORY_ID=#{id} </update> <!-- 查询一个 --> <select id="get" parameterType="string" resultMap="factoryRM"> select * from factory_c where factory_id=#{id} </select>
package cn.hpu.jk.dao.impl; import java.io.Serializable; import java.util.List; import java.util.Map; import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.support.SqlSessionDaoSupport; import org.springframework.beans.factory.annotation.Autowired; import cn.hpu.jk.dao.BaseDao; import cn.hpu.jk.pagination.Page; public abstract class BaseDaoImpl<T> extends SqlSessionDaoSupport implements BaseDao<T>{ @Autowired //mybatis-spring 1.0无需此方法;mybatis-spring1.2必须注入。 public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory){ super.setSqlSessionFactory(sqlSessionFactory); } private String ns; //命名空间 public String getNs() { return ns; } public void setNs(String ns) { this.ns = ns; } public List<T> findPage(Page page){ List<T> oList = this.getSqlSession().selectList(ns + ".findPage", page); return oList; } public List<T> find(Map map) { List<T> oList = this.getSqlSession().selectList(ns + ".find", map); return oList; } public T get(Serializable id) { return this.getSqlSession().selectOne(ns + ".get", id); } public void insert(T entity) { this.getSqlSession().insert(ns + ".insert", entity); } public void update(T entity) { this.getSqlSession().update(ns + ".update", entity); } public void deleteById(Serializable id) { this.getSqlSession().delete(ns + ".deleteById", id); } public void delete(Serializable[] ids) { this.getSqlSession().delete(ns + ".delete", ids); } }
@Override public void update(Factory factory) { factoryDao.update(factory); } @Override public Factory get(Serializable id) { return factoryDao.get(id); }
//转向修改界面 @RequestMapping("/basicinfo/factory/toupdate.action") public String toupdate(String id,Model model){ Factory obj=factoryService.get(id); model.addAttribute("obj", obj); return "/baseinfo/factory/jFactoryUpdate.jsp"; } //修改保存 @RequestMapping("/basicinfo/factory/update.action") public String update(Factory factory){ factoryService.update(factory); return "redirect:/basicinfo/factory/list.action"; }
<%@ page language="java" pageEncoding="UTF-8"%> <%@ include file="../../base.jsp"%> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>修改厂家信息</title> </head> <body> <form method="post"> <input type="hidden" name="id" value="${obj.id}"/> <div id="menubar"> <div id="middleMenubar"> <div id="innerMenubar"> <div id="navMenubar"> <ul> <li id="save"><a href="#" onclick="formSubmit('update.action','_self');">确定</a></li> <li id="back"><a href="list.action">返回</a></li> </ul> </div> </div> </div> </div> <div class="textbox" id="centerTextbox"> <div class="textbox-header"> <div class="textbox-inner-header"> <div class="textbox-title"> 修改生产厂家信息 </div> </div> </div> <div> <div> <table class="commonTable" cellspacing="1"> <tr> <td class="columnTitle_mustbe">厂家名称:</td> <td class="tableContent"><input type="text" name="fullName" value="${obj.fullName }"/></td> <td class="columnTitle_mustbe">简称:</td> <td class="tableContent"><input type="text" name="factoryName" value="${obj.factoryName }"/></td> </tr> <tr> <td class="columnTitle_mustbe">联系人:</td> <td class="tableContent"><input type="text" name="contacts" value="${obj.contacts }"/></td> <td class="columnTitle_mustbe">电话:</td> <td class="tableContent"><input type="text" name="phone" value="${obj.phone }"/></td> </tr> <tr> <td class="columnTitle_mustbe">手机:</td> <td class="tableContent"><input type="text" name="mobile" value="${obj.mobile }"/></td> <td class="columnTitle_mustbe">传真:</td> <td class="tableContent"><input type="text" name="fax" value="${obj.fax }"/></td> </tr> <tr> <td class="columnTitle_mustbe">检验员:</td> <td class="tableContent"><input type="text" name="inspector" value="${obj.inspector }"/></td> <td class="columnTitle_mustbe">排序号:</td> <td class="tableContent"><input type="text" name="orderNo" value="${obj.orderNo }"/></td> </tr> <tr> <td class="columnTitle_mustbe">备注:</td> <td class="tableContent"><textarea name="cnote" style="height:200px;width: 400px">${obj.cnote }</textarea></td> </tr> </table> </div> </div> </form> </body> </html>
<li id="update"><a href="#" onclick="formSubmit('toupdate.action','_self');this.blur();">修改</a></li>
发现修改成功!我们的修改功能编写完毕!
转载请注明出处:http://blog.csdn.net/acmman/article/details/48293635