日期:2014-05-16 浏览次数:20411 次
public interface UserMapper { Long getId(); User login(Map<String,Object> param); User getUser(Map<String,Object> param); List<User> getUserList(); List<Map<String,Object>> getUserNameList(); void insertUser(User user);
<mapper namespace="com.user.persistence.UserMapper"> <insert id="insertUser" parameterType="User" > INSERT INTO t_user (id,name, password, create_date) VALUES (#{id},#{name}, #{password}, #{createDate,jdbcType=TIMESTAMP}) </insert>
@Component public class UserDao extends SqlSessionDaoSupport { public void insertUser(User user) { getSqlSession().insert("com.liao.user.persistence.UserMapper.insertUser", user); } ..............
@Service //默认将类中的所有函数纳入事务管理. @Transactional public class UserService{ @Autowired private UserMapper userMapper; public void insertUser(User user,Map<String,Object> param) { //新增用户 userMapper.insertUser(user);
@Controller @RequestMapping("/user") public class UserController { @Autowired private UserService userService; @RequestMapping(value="/save",method=RequestMethod.POST) public @ResponseBody Map<String,Object> saveOrUpdate(HttpServletRequest request, HttpServletResponse response){ Map<String,Object> responseMap = new HashMap<String,Object>(); User user = new User(); Long newId = userService.getId(); user.setId(newId); user.setCreateDate(new Date()); user.setName(name); user.setPassword(password); Map<String,Object> param = new HashMap<String,Object>(); param.put("user_id", newId); userService.insertUser(user, param); responseMap.put("method", "Create"); responseMap.put("success", "true"); responseMap.put("info", "新增成功!"); } return responseMap;
submit: function() { if (this.form.getForm().isValid()) { var id = this.form.getForm().findField("id").getValue(); this.form.getForm().submit({ waitTitle: '保存数据', waitMsg: '正在保存……', scope: this, method: 'post', params: '', success: function(form, action) { var info = action.result.info; if (action.result.success) { this.store.reload(); if (action.result.method == "Create") { this.form.getForm().reset(); } else { this.dlg.hide(); } } Ext.Msg.aler