<!-- 修改状态 --> <update id="updateState" parameterType="map"> update contract_c set state=#{state} where CONTRACT_ID in <foreach collection="ids" item="id" open="(" close=")" separator=","> #{id} </foreach> </update>
package cn.hpu.jk.dao.impl; import java.util.Map; import org.springframework.stereotype.Repository; import cn.hpu.jk.dao.ContractDao; import cn.hpu.jk.domain.Contract; @Repository //为了包扫描的时候这个Dao被扫描到 public class ContractDaoImpl extends BaseDaoImpl<Contract> implements ContractDao{ public ContractDaoImpl(){ //设置命名空间 super.setNs("cn.hpu.jk.mapper.ContractMapper"); } @Override public void updateState(Map map) { super.getSqlSession().update(super.getNs()+".updateState", map); } }
@Override public void submit(Serializable[] ids) { //默认刚建完的是草稿,建完之后确定没问题就上报 //0草稿 1已上报 Map map=new HashMap(); map.put("state",1);//1已上报 map.put("ids", ids); contractDao.updateState(map); } @Override public void cancel(Serializable[] ids) { Map map=new HashMap(); map.put("state",0);//0 map.put("ids", ids); contractDao.updateState(map); }
//上报 @RequestMapping("/cargo/contract/submit.action") public String submit(String[] id){ contractService.submit(id); return "redirect:/cargo/contract/list.action"; } //取消 @RequestMapping("/cargo/contract/cancel.action") public String cancel(String[] id){ contractService.cancel(id); return "redirect:/cargo/contract/list.action"; }
<li id="new"><a href="#" onclick="formSubmit('submit.action','_self');this.blur();">上报</a></li> <li id="new"><a href="#" onclick="formSubmit('cancel.action','_self');this.blur();">取消</a></li>
上报结果
同理反过来也是可以的