SuperMarketSys_SSM超市管理系统(Spring+SpringMVC+Mybatis)
2017-10-20 17:06
483 查看
web.xml配置以及相应框架配置文件
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>SuperMarketSys_SSM</display-name> <welcome-file-list> <welcome-file>/WEB-INF/jsp/login.jsp</welcome-file> </welcome-file-list> <filter> <filter-name>encodingFilter</filter-name> <filter-class> org.springframework.web.filter.CharacterEncodingFilter </filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springmvc-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext-*.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>classpath:log4j.properties</param-value> </context-param> <context-param> <param-name>webAppRootKey</param-name> <param-value>SuperMarketSys_SSM.root</param-value> </context-param> <listener> <listener-class> org.springframework.web.util.Log4jConfigListener </listener-class> </listener> </web-app>
resource包
applicationContext-mybatis.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- 扫描service层所有的包 --> <context:component-scan base-package="com.yccz.service"/> <!-- <context:component-scan base-package="com.yccz.entity"/> --> <!-- 读取数据库配置文件 --> <context:property-placeholder location="classpath:database.properties"/> <!-- JNDI获取数据源(使用dbcp连接池) --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" scope="singleton"> <property name="driverClassName" value="${driver}" /> <property name="url" value="${url}" /> <property name="username" value="${user}" /> <property name="password" value="${password}" /> <property name="initialSize" value="${initialSize}"/> <property name="maxActive" value="${maxActive}"/> <property name="maxIdle" value="${maxIdle}"/> <property name="minIdle" value="${minIdle}"/> <property name="maxWait" value="${maxWait}"/> <property name="removeAbandonedTimeout" value="${removeAbandonedTimeout}"/> <property name="removeAbandoned" value="${removeAbandoned}"/> <!-- sql 心跳 --> <property name= "testWhileIdle" value="true"/> <property name= "testOnBorrow" value="false"/> <property name= "testOnReturn" value="false"/> <property name= "validationQuery" value="select 1"/> <property name= "timeBetweenEvictionRunsMillis" value="60000"/> <property name= "numTestsPerEvictionRun" value="${maxActive}"/> </bean> <!-- 事务管理 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <!-- 配置mybitas SqlSessionFactoryBean--> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="configLocation" value="classpath:mybatis-config.xml"/> </bean> <!-- AOP 事务处理 开始 --> <aop:aspectj-autoproxy /> <aop:config proxy-target-class="true"> <aop:pointcut expression="execution(* *com.yccz.service..*(..))" id="transService"/> <aop:advisor pointcut-ref="transService" advice-ref="txAdvice" /> </aop:config> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="*" propagation="REQUIRED" rollback-for="Exception" /> </tx:attributes> </tx:advice> <!-- AOP 事务处理 结束 --> <!-- 没有必要在 Spring 的 XML 配置文件中注册所有的映射器。 相反,你可以使用一个 MapperScannerConfigurer , 它 将 会 查 找 类 路 径 下 的 映 射 器 并 自 动 将 它 们 创 建 成 MapperFactoryBean。 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.yccz.dao" /> </bean> </beans>
mybatis-config.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <settings> <!-- 懒加载配置 --> <setting name="lazyLoadingEnabled" value="false" /> </settings> <typeAliases> <!--这里给实体类取别名,方便在mapper配置文件中使用--> <package name="com.yccz.entity"/> </typeAliases> </configuration>
springmvc-servlet.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!-- 扫描所有的controller层下的类 --> <context:component-scan base-package="com.yccz.controller"/> <!-- 这个标签注册了Spring MVC分发请求到控制器所必须的DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter实例 --> <mvc:annotation-driven/> <!-- 扫描所有的静态文件,不写所有的js无效 --> <mvc:resources location="/statics/" mapping="/statics/**"/> <mvc:default-servlet-handler/> <!-- 解决json数据传递的中文乱码问题-StringHttpMessageConverter --> <mvc:annotation-driven> <mvc:message-converters> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>application/json;charset=UTF-8</value> </list> </property> </bean> <!-- 解决JSON数据传递的日期格式问题--> <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/html;charset=UTF-8</value> <value>application/json</value> </list> </property> <property name="features"> <list> <!-- Date的日期转换器 --> <value>WriteDateUseDateFormat</value> </list> </property> </bean> </mvc:message-converters> </mvc:annotation-driven> <!-- 完成视图的对应 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean> <!-- 上传下载 --> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <!-- 上传文件大小上限,单位为字节(10MB) --> <property name="maxUploadSize"> <value>10485760</value> </property> <!-- 请求的编码格式,必须和jSP的pageEncoding属性一致,以便正确读取表单的内容,默认为ISO-8859-1 --> <property name="defaultEncoding"> <value>UTF-8</value> </property> </bean> </beans>
database.properties
driver=com.mysql.jdbc.Driver #在和mysqlä¼ é€’æ•°æ®çš„过程ä¸ï¼Œä½¿ç”¨unicodeç¼–ç æ ¼å¼ï¼Œå¹¶ä¸”å—符集设置为utf-8 url=jdbc:mysql://localhost:3306/smbms?useUnicode=true&characterEncoding=utf-8 user=root password=123 minIdle=45 maxIdle=50 initialSize=5 maxActive=100 maxWait=100 #\u8D85\u65F6\u65F6\u95F4\uFF1B\u5355\u4F4D\u4E3A\u79D2\u3002180\u79D2=3\u5206\u949F removeAbandonedTimeout=180 #\u8D85\u8FC7\u65F6\u95F4\u9650\u5236\u662F\u5426\u56DE\u6536 removeAbandoned=true
实体层entity(省略set、get方法)
package com.yccz.entity; import java.util.Date; import java.util.List; /** * 订单表 * @author Administrator * */ public class Bill { private int id; private String billCode; private String productName; private String productDesc; private String productUnit; private double productCount; private double totalPrice; private int isPayment; private int createdBy; private Date creationDate; private int modifyBy; private Date modifyDate; private int providerId; private String proName; //供应商集合 private Provider provider; } }
package com.yccz.entity; import java.util.Date; /** * * <p>Title: Provider</p> * <p>Description:供应商类 </p> * <p>Company: </p> * @author Bill * @date 2017年10月20日 */ public class Provider { private int id; private String proCode; private String proName; private String proDesc; private String proContact; private String proPhone; private String proAddress; }
/** * 用户表 * @author Administrator * */ @Component public class User { @Autowired RoleService roleService; private int id; private String userCode; private String userName; private String userPassword; private int gender; //解决json日期格式转换问题-注解方式 @JSONField(format="yyyy-MM-dd") private Date birthday; private String phone; private String address; private int userRole; private int createdBy; private Date creationDate; private int modifyBy; private Date modifyDate; private String roleName; private int age; private String idPicPath; //证件照路径 private String workPicPath; //工作证照片路径 public void setGender(int gender) { if(gender==1){ this.sex="男"; }else{ this.sex="女"; } this.gender = gender; } public Date getBirthday() { return birthday; } public void setBirthday(Date birthday) { //通过生日算出年龄 Date now = new Date(); int age = 0; SimpleDateFormat format_y = new SimpleDateFormat("yyyy"); SimpleDateFormat format_M = new SimpleDateFormat("MM"); String birth_year = format_y.format(birthday); String this_year = format_y.format(now); String birth_month = format_M.format(birthday); String this_month = format_M.format(now); age = Integer.parseInt(this_year)-Integer.parseInt(birth_year); if(birthday==null){ age=10000; } if(this_month.compareTo(birth_month)<0){ age-=1; } if(age<0){ age = 0; } this.age = age; this.birthday = birthday; } }
import java.util.Date; public class Role { private Integer id; //id private String roleCode; //角色编码 private String roleName; //角色名称 private Integer createdBy; //创建者 private Date creationDate; //创建时间 private Integer modifyBy; //更新者 private Date modifyDate;//更新时间 }
util包
//分页的类,可以统一写成PageHellper public class BillPage { // 总页数 private int totalPageCount = 0; // 页面大小,即每页显示记录数 private int pageSize = 5; // 记录总数 private int totalCount; // 当前页码 private int currPageNo = 1; // 每页订单集合 private List<Bill> billList; public int getCurrPageNo() { return currPageNo; } public void setCurrPageNo(int currPageNo) { if (currPageNo > 0) this.currPageNo = currPageNo; } public int getPageSize() { return pageSize; } public void setPageSize(int pageSize) { if (pageSize > 0) this.pageSize = pageSize; } public int getTotalCount() { return totalCount; } public void setTotalCount(int totalCount) {//总记录60条数据 页面大小 5条 if (totalCount > 0) { this.totalCount = totalCount; // 计算总页数 this.totalPageCount = this.totalCount % pageSize == 0 ? (this.totalCount / pageSize) : (this.totalCount / pageSize + 1); if(currPageNo>totalPageCount) this.currPageNo = totalPageCount; } } public int getTotalPageCount() { return totalPageCount; } public void setTotalPageCount(int totalPageCount) { this.totalPageCount = totalPageCount; } public List<Bill> getBillList() { return billList; } public void setBillList(List<Bill> billList) { this.billList = billList; } }
用户管理模块
Dao层(数据持久层)UserMapper.java
package com.yccz.dao; import java.util.List; import org.apache.ibatis.annotations.Param; import com.yccz.entity.User; /** * <p>Title: UserMapper</p> * <p>Description: </p> * <p>Company: </p> * @author Bill * @date 2017年10月18日 */ public interface UserMapper { public User getUserByCode(@Param("userCode")String userCode); public List<User> queryUsers(@Param("userName")String userName,@Param("userRole")String userRole,@Param("start")int start,@Param("size")int size); public User findUser(@Param("userCode")String userCode,@Param("userPassword") String userPassword); public int getUserCount(@Param("userName")String userName,@Param("userRole")String userRole); public int add(User user); public int modify(User user); public User getUserById(String userid); public int updatePwd(int id,String pwd); public int deleteUserById(Integer delId); }
UserMapper.xml
<?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="com.yccz.dao.UserMapper"> <resultMap type="User" id="userMap"> <result property="id" column="id"/> <result property="userCode" column="userCode"/> <result property="userName" column="userName"/> <result property="phone" column="phone"/> <result property="birthday" column="birthday"/> <result property="gender" column="gender"/> <result property="userRole" column="userRole"/> <result property="roleName" column="roleName"/> </resultMap> <select id="findUser" resultMap="userMap"> select u.*,r.roleName from smbms_user u,smbms_role r where u.userRole=r.id and u.userCode=#{userCode} and u.userPassword=#{userPassword} </select> <select id="getUserByCode" resultType="User"> select * from smbms_user u <trim prefix="where" prefixOverrides="and | or"> <if test="userCode!=null"> and u.userCode = #{userCode} </if> </trim> </select> <resultMap type="User" id="userList"> <result property="id" column="id"/> <result property="userCode" column="userCode"/> <result property="userName" column="userName"/> <result property="phone" column="phone"/> <result property="birthday" column="birthday"/> <result property="gender" column="gender"/> <result property="userRole" column="userRole"/> <result property="roleName" column="roleName"/> </resultMap> <select id="queryUsers" resultMap="userList"> select u.*,r.roleName from smbms_user u,smbms_role r where u.userRole = r.id <if test="userName != null and userName != ''"> and u.userName like CONCAT ('%',#{userName},'%') </if> <if test="userRole != null and userRole!=0"> and u.userRole = #{userRole} </if> order by creationDate DESC limit #{start},#{size} </select> <select id="getUserCount" resultType="Int"> select count(1) as count from smbms_user u,smbms_role r where u.userRole = r.id <if test="userName != null and userName != ''"> and u.userName like CONCAT ('%',#{userName},'%') </if> <if test="userRole != null and userRole!=0"> and u.userRole = #{userRole} </if> </select> <select id="getUserById" resultType="user"> select u.*,r.roleName from smbms_user u,smbms_role r where u.id=#{userid} and u.userRole=r.id </select> <insert id="add" parameterType="User"> insert into smbms_user (userCode,userName,userPassword,gender,birthday,phone, address,userRole,createdBy,creationDate,idPicPath,workPicPath) values (#{userCode},#{userName},#{userPassword},#{gender},#{birthday},#{phone}, #{address},#{userRole},#{createdBy},#{creationDate},#{idPicPath},#{workPicPath}) </insert> <update id="modify" parameterType="User"> update smbms_user <trim prefix="set" suffixOverrides="," suffix="where id = #{id}"> <if test="userCode != null">userCode=#{userCode},</if> <if test="userName != null">userName=#{userName},</if> <if test="userPassword != null">userPassword=#{userPassword},</if> <if test="gender != null">gender=#{gender},</if> <if test="birthday != null">birthday=#{birthday},</if> <if test="phone != null">phone=#{phone},</if> <if test="address != null">address=#{address},</if> <if test="userRole != null">userRole=#{userRole},</if> <if test="modifyBy != null">modifyBy=#{modifyBy},</if> <if test="modifyDate != null">modifyDate=#{modifyDate},</if> <if test="idPicPath != null">idPicPath=#{idPicPath},</if> <if test="workPicPath != null">workPicPath=#{workPicPath},</if> </trim> </update> <update id="updatePwd" parameterType="Integer"> update smbms_user set userPassword=#{pwd} where id=#{id} </update> <delete id="deleteUserById" parameterType="Integer"> delete from smbms_user where id=#{delId} </delete> </mapper>
service(业务处理层)
UserService.java
**package com.yccz.service; import java.util.List; import com.yccz.entity.User; public interface UserService { public User findUser(String userCode, String userPassword); public List<User> queryUsers(String queryname,String queryUserRole,int start,int size); public int getUserCount(String queryname,String queryUserRole); public boolean add(User user); public boolean modify(User user); public User getUserById(String userid); public User getUserByCode(String userCode); public boolean updatePwd(int id,String pwd); public boolean deleteUserById(Integer delId); }
UserServiceImpl.java
package com.yccz.service.impl; import java.util.List; import javax.annotation.Resource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.yccz.dao.UserMapper; import com.yccz.entity.User; import com.yccz.service.UserService; @Service public class UserServiceImpl implements UserService { @Resource private UserMapper userMapper; @Override public User findUser(String userCode, String userPassword) { return userMapper.findUser(userCode, userPassword); } @Override public List<User> queryUsers(String userName, String userRole, int start, int size) { start = (start-1)*size; return userMapper.queryUsers(userName, userRole, start, size); } @Override public int getUserCount(String userName, String userRole) { return userMapper.getUserCount(userName, userRole); } @Override public boolean add(User user) { boolean flag = false; int rows = userMapper.add(user); if(rows>0){ flag=true; System.out.println("add success!"); }else{ System.out.println("add failed!"); } return flag; } @Override public boolean modify(User user) { boolean flag = false; if(userMapper.modify(user)>0) flag = true; return flag; } @Override public User getUserById(String userid) { User user = userMapper.getUserById(userid); return user; } @Override public User getUserByCode(String userCode) { User user = userMapper.getUserByCode(userCode); return user; } @Override public boolean updatePwd(int id, String pwd) { boolean flag = false; int rows = userMapper.updatePwd(id, pwd); if(rows>0) flag=true; return flag; } @Override public boolean deleteUserById(Integer delId) { boolean flag = false; int rows = userMapper.deleteUserById(delId); if(rows>0){ flag=true; } return flag; } }
controller层(控制器层)
UserController
package com.yccz.controller;
import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.math.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import com.alibaba.fastjson.JSONArray;
import com.mysql.jdbc.StringUtils;
import com.yccz.entity.Role;
import com.yccz.entity.User;
import com.yccz.service.RoleService;
import com.yccz.service.UserService;
import com.yccz.util.UserPage;
/**
*
Title: UserController
* Description:
* Company:
* @author Bill
* @date 2017年10月12日
*/
@Controller
@RequestMapping(“/user”)
public class UserController {
@Autowired
private UserService userService;
@Autowired
private RoleService roleService;
@RequestMapping(value="/login.html") public String login(){ return "login"; } @RequestMapping(value="/dologin.html",method=RequestMethod.POST) public String doLogin(String userCode,String userPassword,HttpServletRequest request,HttpSession session){ User user = userService.findUser(userCode, userPassword); if(user!=null){ session.setAttribute("user", user); return "redirect:/user/main.html"; }else{ request.setAttribute("error", "用户名密码不正确"); return "login"; } } @RequestMapping(value="/main.html") public String main(HttpSession session){ if(session.getAttribute("user")==null){ return "redirect:/user/login.html"; } return "frame"; } @RequestMapping(value="/userlist.html") public String userlist(String currPageNo,@RequestParam(value="queryname",required=false)String queryname,@RequestParam(value="queryUserRole",required=false)String queryUserRole ,Model model){ if(currPageNo==null){ currPageNo="1"; } UserPage userPage = new UserPage(); List<User> userlist = userService.queryUsers(queryname, queryUserRole, Integer.parseInt(currPageNo), userPage.getPageSize()); int totalCount = userService.getUserCount(queryname, queryUserRole); List<Role> roleList = roleService.getRoleList(); userPage.setTotalCount(totalCount); userPage.setUserList(userlist); userPage.setCurrPageNo(Integer.parseInt(currPageNo)); model.addAttribute("roleList",roleList ); model.addAttribute("Page", userPage); model.addAttribute("queryname", queryname); model.addAttribute("queryUserRole", queryUserRole); return "userlist"; } @RequestMapping(value="/useradd.html",method=RequestMethod.GET) public String addUser(){ return "useradd"; } //负责保存用户信息
/* @RequestMapping(value=”useraddsave.html”,method=RequestMethod.POST)
public String addUserSave(User user,HttpSession session){
User admin = (User)session.getAttribute("user"); int createdby = admin.getId(); user.setCreatedBy(createdby); if(userService.add(user)){ return "redirect:/user/userlist.html"; } return "useradd"; }*/ @RequestMapping(value="/usermodify.html",method=RequestMethod.GET) public String getUserById(String userid,String username,Model model){ System.out.println("========"+userid); User user = userService.getUserById(userid);
// System.out.println(user.getPhone()+”==========”);
model.addAttribute(“user”, user);
return “usermodify”;
} @RequestMapping(value="/usermodifysave.html",method=RequestMethod.POST) public String modifyUserSave(User user,HttpSession session,String mybirthday) throws ParseException{ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); user.setBirthday(sdf.parse(mybirthday)); User admin = (User)session.getAttribute("user"); int createdby = admin.getId(); user.setCreatedBy(createdby); user.setModifyDate(new Date()); if(userService.modify(user)){ return "redirect:/user/userlist.html"; } return "usermodify"; } @RequestMapping(value="/view/{userid}",method=RequestMethod.GET) public String view(@PathVariable String userid,Model model){ System.out.println(userid+"=========uid"); User user =userService.getUserById(userid); System.out.println(user==null); model.addAttribute("user", user); return "userview"; } //多文件上传+添加 @RequestMapping(value="/useraddsave.html",method=RequestMethod.POST) public String addUserSave(User user,HttpSession session,HttpServletRequest request, String mybirthday, @RequestParam(value ="attachs", required = false) MultipartFile[] attachs) throws ParseException{ String idPicPath = null; String workPicPath = null; String errorInfo = null; boolean flag = true; String path = request.getSession().getServletContext().getRealPath("statics"+File.separator+"uploadfiles"); for(int i = 0;i < attachs.length ;i++){ MultipartFile attach = attachs[i]; if(!attach.isEmpty()){ if(i == 0){ errorInfo = "uploadFileError"; }else if(i == 1){ errorInfo = "uploadWpError"; } String oldFileName = attach.getOriginalFilename();//原文件名 String prefix=FilenameUtils.getExtension(oldFileName);//原文件后缀 int filesize = 500000; if(attach.getSize() > filesize){//上传大小不得超过 500k request.setAttribute(errorInfo, " * 上传大小不得超过 500k"); flag = false; }else if(prefix.equalsIgnoreCase("jpg") || prefix.equalsIgnoreCase("png") || prefix.equalsIgnoreCase("jpeg") || prefix.equalsIgnoreCase("pneg")){//上传图片格式不正确 String fileName = System.currentTimeMillis()+RandomUtils.nextInt(1000000)+"_Personal.jpg"; File targetFile = new File(path, fileName); if(!targetFile.exists()){ targetFile.mkdirs(); } //保存 try { attach.transferTo(targetFile); } catch (Exception e) { e.printStackTrace(); request.setAttribute(errorInfo, " * 上传失败!"); flag = false; } if(i == 0){ idPicPath = path+File.separator+fileName; }else if(i == 1){ workPicPath = path+File.separator+fileName; } }else{ request.setAttribute(errorInfo, " * 上传图片格式不正确"); flag = false; } } } if(flag){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); user.setBirthday(sdf.parse(mybirthday)); user.setCreatedBy(((User)session.getAttribute("user")).getId()); user.setCreationDate(new Date()); user.setIdPicPath(idPicPath); user.setWorkPicPath(workPicPath); if(userService.add(user)){ return "redirect:/user/userlist.html"; } } return "useradd"; } @RequestMapping(value="/ucexist.json") @ResponseBody public Object userCodeIsExit(@RequestParam String userCode){// //保存验证结果 HashMap<String, String> resultMap = new HashMap<String, String>(); if(StringUtils.isNullOrEmpty(userCode)){ resultMap.put("userCode", "exist"); }else{ User user = userService.getUserByCode(userCode); if(null != user) resultMap.put("userCode", "exist"); else resultMap.put("userCode", "noexist"); } return JSONArray.toJSONString(resultMap); } //ajax方式实现查看 @RequestMapping(value="/view",method=RequestMethod.GET) @ResponseBody public User view(@RequestParam String userid){ User user = new User(); try { user = userService.getUserById(userid); } catch (Exception e) { e.printStackTrace(); } return user; } //跳转到密码修改页面 @RequestMapping(value="/pwdmodify.html",method=RequestMethod.GET) public String intopwdmodify(HttpSession session){ User user = (User)session.getAttribute("user"); if(user==null){ return "userlist"; } return "pwdmodify"; } //检测旧密码是否输入正确 @RequestMapping(value="/pwdmodify.html",method=RequestMethod.POST) @ResponseBody public Object getPwdByUserId(@RequestParam String oldpassword,HttpSession session){ HashMap<String, String> resultMap = new HashMap<String, String>(); if(null == session.getAttribute("user")){ resultMap.put("result", "sessionerror"); }else if(StringUtils.isNullOrEmpty(oldpassword)){ resultMap.put("result", "error"); }else{ String sessionPwd = ((User)session.getAttribute("user")).getUserPassword(); if(oldpassword.equals(sessionPwd)){ resultMap.put("result", "true"); }else{ resultMap.put("result", "false"); } } return JSONArray.toJSONString(resultMap); } //保存修改后的密码 @RequestMapping(value="/pwdsave.html") public String pwdSave(@RequestParam(value="newpassword") String newPassword,HttpSession session,HttpServletRequest request){ boolean flag = false; Object o = session.getAttribute("user"); if(o !=null&&!StringUtils.isNullOrEmpty(newPassword)){ flag = userService.updatePwd(((User)o).getId(), newPassword); if(flag){ request.setAttribute("sys_message","修改密码成功"); session.removeAttribute("user"); return "login"; }else{ request.setAttribute("sys_message", "修改密码失败!"); } }else{ request.setAttribute("sys_message", "修改密码失败"); } return "pwdmodify"; } @RequestMapping(value="/rolelist",method=RequestMethod.GET,produces={"application/json;charset=UTF-8"}) @ResponseBody public Object getRoleList(){ List<Role> roleList = null; roleList = roleService.getRoleList(); return JSONArray.toJSONString(roleList); } //删除用户信息 @RequestMapping(value="/deluser.json",method=RequestMethod.GET) @ResponseBody public Object deluser(@RequestParam String id){ HashMap<String, String> resultMap = new HashMap<String, String>(); if(StringUtils.isNullOrEmpty(id)){ resultMap.put("delResult", "notexist"); }else{ if(userService.deleteUserById(Integer.parseInt(id))) resultMap.put("delResult", "true"); else resultMap.put("delResult", "false"); } return JSONArray.toJSONString(resultMap); }
}
jsp文件
useradd.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@include file="common/head.jsp"%> <div class="right"> <div class="location"> <strong>你现在所在的位置是:</strong> <span>用户管理页面 >> 用户添加页面</span> </div> <div class="providerAdd"> <form id="userForm" name="userForm" method="post" action="${pageContext.request.contextPath}/user/useraddsave.html" enctype="multipart/form-data"> <input type="hidden" name="method" value="add"> <!--div的class 为error是验证错误,ok是验证成功--> <div> <label for="userCode">用户编码:</label> <input type="text" name="userCode" id="userCode" value=""> <!-- 放置提示信息 --> <font color="red"></font> </div> <div> <label for="userName">用户名称:</label> <input type="text" name="userName" id="userName" value=""> <font color="red"></font> </div> <div> <label for="userPassword">用户密码:</label> <input type="password" name="userPassword" id="userPassword" value=""> <font color="red"></font> </div> <div> <label for="ruserPassword">确认密码:</label> <input type="password" name="ruserPassword" id="ruserPassword" value=""> <font color="red"></font> </div> <div> <label >用户性别:</label> <select name="gender" id="gender"> <option value="1" selected="selected">男</option> <option value="2">女</option> </select> </div> <div> <label for="birthday">出生日期:</label> <input type="text" Class="Wdate" id="birthday" name="mybirthday" readonly="readonly" onclick="WdatePicker();"> <font color="red"></font> </div> <div> <label for="phone">用户电话:</label> <input type="text" name="phone" id="phone" value=""> <font color="red"></font> </div> <div> <label for="address">用户地址:</label> <input name="address" id="address" value=""> </div> <div> <label >用户角色:</label> <!-- 列出所有的角色分类 --> <select name="userRole" id="userRole"></select> <!-- <select name="userrole" id="userRole"> <option value="1">系统管理员</option> <option value="2">经理</option> <option value="3" selected="selected">普通用户</option> </select> --> <font color="red"></font> </div> <div> <input type="hidden" id="errorinfo" value=""/> <label for="a_idPicPath">证件照:</label> <input type="file" name="attachs" id="a_idPicPath"/> <font color="red"></font> </div> <div> <input type="hidden" id="errorinfo_wp" value=""/> <label for="a_workPicPath">工作证照片:</label> <input type="file" name="attachs" id="a_workPicPath"/> <font color="red"></font> </div> <div class="providerAddBtn"> <input type="button" name="add" id="add" value="保存" > <input type="button" id="back" name="back" value="返回" > </div> </form> </div> </div> </section> <%@include file="./common/foot.jsp" %> <script type="text/javascript" src="statics/js/useradd.js"></script>
userlist.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%> <%@include file="./common/head.jsp"%> <div class="right"> <div class="location"> <strong>你现在所在的位置是:</strong> <span>用户管理页面</span> </div> <div class="search"> <form method="post" action="user/userlist.html"> <input name="method" value="query" class="input-text" type="hidden"> <span>用户名:</span> <input name="queryname" class="input-text" type="text" value="${queryname}"> <span>用户角色:</span> <select name="queryUserRole"> <option value="0">--请选择--</option> <c:forEach items="${roleList}" var="role"> <option value="${role.id }" <c:if test="${queryUserRole eq role.id}">selected="selected"</c:if>> ${role.roleName} </option> </c:forEach> </select> <input type="hidden" name="pageIndex" value="1"/> <input value="查 询" type="submit" id="searchbutton"> <a href="${pageContext.request.contextPath}/user/useradd.html" >添加用户</a> </form> </div> <!--用户--> <table class="providerTable" cellpadding="0" cellspacing="0"> <tr class="firstTr"> <th width="10%">用户编码</th> <th width="20%">用户名称</th> <th width="10%">性别</th> <th width="10%">年龄</th> <th width="10%">电话</th> <th width="10%">用户角色</th> <th width="30%">操作</th> </tr> <c:forEach var="user" items="${Page.userList}"> <tr> <td> <span>${user.userCode }</span> </td> <td> <span>${user.userName }</span> </td> <td> <span> ${user.sex} </span> </td> <td> <span>${user.age }</span> </td> <td> <span>${user.phone }</span> </td> <td> <span>${user.roleName}</span> </td> <td> <span><a class="viewUser" href="javascript:;" userid=${user.id } username=${user.userName }><img src="${pageContext.request.contextPath }/statics/images/read.png" alt="查看" title="查看"/></a></span> <%-- <span><a class="viewUser" href="/SuperMarketSys/user/view/${user.id}" ><img src="/SuperMarketSys/statics/images/read.png" alt="查看" title="查看"/></a></span> --%> <span><a class="modifyUser" href="/SuperMarketSys_SSM/user/usermodify.html?userid=${user.id}&username=${user.userName}"><img src="/SuperMarketSys_SSM/statics/images/xiugai.png" alt="修改" title="修改"/></a></span> <span><a class="deleteUser" href="javascript:;" userid=${user.id} username=${user.userName}><img src="/SuperMarketSys_SSM/statics/images/schu.png" alt="删除" title="删除"/></a></span> </td> </tr> </c:forEach> </table> 当前页数:[${Page.currPageNo }/${Page.totalPageCount }] <c:if test="${Page.currPageNo>1}"> <a href="user/userlist.html?currPageNo=1&queryUserRole=${queryUserRole}">首页</a> <a href="user/userlist.html?currPageNo=${Page.currPageNo-1}&queryUserRole=${queryUserRole}&queryname=${queryname}">上一页</a> </c:if> <c:if test="${Page.totalPageCount ne Page.currPageNo}"> <a href="user/userlist.html?currPageNo=${Page.currPageNo+1}&queryUserRole=${queryUserRole}&queryname=${queryname}">下一页</a> <a href="user/userlist.html?currPageNo=${Page.totalPageCount }&queryUserRole=${queryUserRole}">末页</a> </c:if> <!-- ajax方式查看的div --> <div class="providerAdd"> <div> <label>用户编码:</label> <input type="text" id="v_userCode" value="" readonly="readonly"> </div> <div> <label>用户名称:</label> <input type="text" id="v_userName" value="" readonly="readonly"> </div> <div> <label>用户性别:</label> <input type="text" id="v_gender" value="" readonly="readonly"> </div> <div> <label>出生日期:</label> <input type="text" Class="Wdate" id="v_birthday" value="" readonly="readonly" onclick="WdatePicker();"> </div> <div> <label>用户电话:</label> <input type="text" id="v_phone" value="" readonly="readonly"> </div> <div> <label>用户角色:</label> <input type="text" id="v_userRoleName" value="" readonly="readonly"> </div> <div> <label>用户地址:</label> <input type="text" id="v_address" value="" readonly="readonly"> </div> </div> </div> </section> <!--点击删除按钮后弹出的页面--> <div class="zhezhao"></div> <div class="remove" id="removeUse"> <div class="removerChid"> <h2>提示</h2> <div class="removeMain"> <p>你确定要删除该用户吗?</p> <a href="#" id="yes">确定</a> <a href="#" id="no">取消</a> </div> </div> </div> <%@include file="./common/foot.jsp" %> <script type="text/javascript" src="${pageContext.request.contextPath }/statics/js/userlist.js"></script>
usermodify.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@include file="./common/head.jsp"%> <div class="right"> <div class="location"> <strong>你现在所在的位置是:</strong> <span>用户管理页面 >> 用户修改页面</span> </div> <div class="providerAdd"> <form id="userForm" name="userForm" method="post" action="${pageContext.request.contextPath }/user/usermodifysave.html"> <input type="hidden" name="id" value="${user.id}"/> <div> <label for="userName">用户名称:</label> <input type="text" name="userName" id="userName" value="${user.userName }"> <font color="red"></font> </div> <div> <label >用户性别:</label> <select name="gender" id="gender"> <c:choose> <c:when test="${user.gender == 1 }"> <option value="1" selected="selected">男</option> <option value="2">女</option> </c:when> <c:otherwise> <option value="1">男</option> <option value="2" selected="selected">女</option> </c:otherwise> </c:choose> </select> </div> <div> <label for="data">出生日期:</label> <input type="text" Class="Wdate" id="birthday" name="mybirthday" value="${user.birthday}" readonly="readonly" onclick="WdatePicker();"> <font color="red"></font> </div> <div> <label for="userphone">用户电话:</label> <input type="text" name="phone" id="phone" value="${user.phone }"> <font color="red"></font> </div> <div> <label for="userAddress">用户地址:</label> <input type="text" name="address" id="address" value="${user.address }"> </div> <div> <label >用户角色:</label> <!-- 列出所有的角色分类 --> <%-- <input type="hidden" value="${user.userRole }" id="rid" /> <select name="userRole" id="userRole"></select> --%> <select name="userRole" id="userRole"> <c:choose> <c:when test="${user.userRole == 1 }"> <option value="1" selected="selected">系统管理员</option> <option value="2">经理</option> <option value="3">普通用户</option> </c:when> <c:when test="${user.userRole == 2 }"> <option value="1">系统管理员</option> <option value="2" selected="selected">经理</option> <option value="3">普通用户</option> </c:when> <c:otherwise> <option value="1">系统管理员</option> <option value="2">经理</option> <option value="3" selected="selected">普通用户</option> </c:otherwise> </c:choose> </select> <font color="red"></font> </div> <div class="providerAddBtn"> <input type="button" name="save" id="save" value="保存" /> <input type="button" id="back" name="back" value="返回"/> </div> </form> </div> </div> </section> <%@include file="./common/foot.jsp" %> <script type="text/javascript" src="statics/js/usermodify.js"></script>
userview.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@include file="/WEB-INF/jsp/common/head.jsp"%> <div class="right"> <div class="location"> <strong>你现在所在的位置是:</strong> <span>用户管理页面 >> 用户信息查看页面</span> </div> <div class="providerView"> <p><strong>用户编号:</strong><span>${user.userCode }</span></p> <p><strong>用户名称:</strong><span>${user.userName }</span></p> <p><strong>用户性别:</strong> <span> <c:if test="${user.gender == 1 }">男</c:if> <c:if test="${user.gender == 2 }">女</c:if> </span> </p> <p><strong>出生日期:</strong><span>${user.birthday }</span></p> <p><strong>用户电话:</strong><span>${user.phone }</span></p> <p><strong>用户地址:</strong><span>${user.address }</span></p> <p><strong>用户角色:</strong><span>${user.roleName}</span></p> <div class="providerAddBtn"> <input type="button" id="back" name="back" value="返回" > </div> </div> </div> </section> <%@include file="./common/foot.jsp" %> <script type="text/javascript" src="statics/js/userview.js"></script>
js文件
useradd.js
var userCode = null; var userName = null; var userPassword = null; var ruserPassword = null; var phone = null; var birthday = null; var userRole = null; var addBtn = null; var backBtn = null; var a_idPicPath = null; var errorinfo = null; var errorinfo_wp = null; var a_workPicPath = null; $(function(){ userCode = $("#userCode"); userName = $("#userName"); userPassword = $("#userPassword"); ruserPassword = $("#ruserPassword"); phone = $("#phone"); birthday = $("#birthday"); userRole = $("#userRole"); addBtn = $("#add"); backBtn = $("#back"); a_idPicPath = $("#a_idPicPath"); errorinfo = $("#errorinfo"); a_workPicPath = $("#a_workPicPath"); errorinfo_wp = $("#errorinfo_wp"); //初始化的时候,要把所有的提示信息变为:* 以提示必填项,更灵活,不要写在页面上 userCode.next().html("*"); userName.next().html("*"); userPassword.next().html("*"); ruserPassword.next().html("*"); phone.next().html("*"); birthday.next().html("*"); userRole.next().html("*"); if(errorinfo.val() == null || errorinfo.val() == ""){ a_idPicPath.next().html("* 上传大小不能超过500K * 上传文件类型必须为:jpg、jpeg、png、pneg"); }else{ a_idPicPath.next().html(errorinfo.val()); } if(errorinfo_wp.val() == null || errorinfo_wp.val() == ""){ a_workPicPath.next().html("* 上传大小不能超过500K * 上传文件类型必须为:jpg、jpeg、png、pneg"); }else{ a_workPicPath.next().html(errorinfo_wp.val()); } $.ajax({ type:"GET",//请求类型 url:path+"/user/rolelist",//请求的url data:{},//请求参数 dataType:"json",//ajax接口(请求url)返回的数据类型 success:function(data){//data:返回数据(json对象) if(data != null){ userRole.html(""); var options = "<option value=\"0\">请选择</option>"; for(var i = 0; i < data.length; i++){ //alert(data[i].id); //alert(data[i].roleName); options += "<option value=\""+data[i].id+"\">"+data[i].roleName+"</option>"; } userRole.html(options); } }, error:function(data){//当访问时候,404,500 等非200的错误状态码 validateTip(userRole.next(),{"color":"red"},imgNo+" 获取用户角色列表error",false); } }); /* * 验证 * 失焦\获焦 * jquery的方法传递 */ userCode.bind("blur",function(){ //ajax后台验证--userCode是否已存在 $.ajax({ type:"GET",//请求类型 url:path+"/user/ucexist.json",//请求的url data:{userCode:userCode.val()},//请求参数 dataType:"json",//ajax接口(请求url)返回的数据类型 success:function(data){//data:返回数据(json对象) if(data.userCode == "exist"){//账号已存在,错误提示 validateTip(userCode.next(),{"color":"red"},imgNo+ " 该用户账号已存在",false); }else{//账号可用,正确提示 validateTip(userCode.next(),{"color":"green"},imgYes+" 该账号可以使用",true); } }, error:function(data){//当访问时候,404,500 等非200的错误状态码 validateTip(userCode.next(),{"color":"red"},imgNo+" 您访问的页面不存在",false); } }); }).bind("focus",function(){ //显示友情提示 validateTip(userCode.next(),{"color":"#666666"},"* 用户编码是您登录系统的账号",false); }).focus(); userName.bind("focus",function(){ validateTip(userName.next(),{"color":"#666666"},"* 用户名长度必须是大于1小于10的字符",false); }).bind("blur",function(){ if(userName.val() != null && userName.val().length > 1 && userName.val().length < 10){ validateTip(userName.next(),{"color":"green"},imgYes,true); }else{ validateTip(userName.next(),{"color":"red"},imgNo+" 用户名输入的不符合规范,请重新输入",false); } }); userPassword.bind("focus",function(){ validateTip(userPassword.next(),{"color":"#666666"},"* 密码长度必须是大于6小于20",false); }).bind("blur",function(){ if(userPassword.val() != null && userPassword.val().length > 6 && userPassword.val().length < 20 ){ validateTip(userPassword.next(),{"color":"green"},imgYes,true); }else{ validateTip(userPassword.next(),{"color":"red"},imgNo + " 密码输入不符合规范,请重新输入",false); } }); ruserPassword.bind("focus",function(){ validateTip(ruserPassword.next(),{"color":"#666666"},"* 请输入与上面一只的密码",false); }).bind("blur",function(){ if(ruserPassword.val() != null && ruserPassword.val().length > 6 && ruserPassword.val().length < 20 && userPassword.val() == ruserPassword.val()){ validateTip(ruserPassword.next(),{"color":"green"},imgYes,true); }else{ validateTip(ruserPassword.next(),{"color":"red"},imgNo + " 两次密码输入不一致,请重新输入",false); } }); birthday.bind("focus",function(){ validateTip(birthday.next(),{"color":"#666666"},"* 点击输入框,选择日期",false); }).bind("blur",function(){ if(birthday.val() != null && birthday.val() != ""){ validateTip(birthday.next(),{"color":"green"},imgYes,true); }else{ validateTip(birthday.next(),{"color":"red"},imgNo + " 选择的日期不正确,请重新输入",false); } }); phone.bind("focus",function(){ validateTip(phone.next(),{"color":"#666666"},"* 请输入手机号",false); }).bind("blur",function(){ var patrn=/^(13[0-9]|15[0-9]|18[0-9])\d{8}$/; if(phone.val().match(patrn)){ validateTip(phone.next(),{"color":"green"},imgYes,true); }else{ validateTip(phone.next(),{"color":"red"},imgNo + " 您输入的手机号格式不正确",false); } }); userRole.bind("focus",function(){ validateTip(userRole.next(),{"color":"#666666"},"* 请选择用户角色",false); }).bind("blur",function(){ if(userRole.val() != null && userRole.val() > 0){ validateTip(userRole.next(),{"color":"green"},imgYes,true); }else{ validateTip(userRole.next(),{"color":"red"},imgNo + " 请重新选择用户角色",false); } }); addBtn.bind("click",function(){ if(userCode.attr("validateStatus") != "true"){ userCode.blur(); }else if(userName.attr("validateStatus") != "true"){ userName.blur(); }else if(userPassword.attr("validateStatus") != "true"){ userPassword.blur(); }else if(ruserPassword.attr("validateStatus") != "true"){ ruserPassword.blur(); }else if(birthday.attr("validateStatus") != "true"){ birthday.blur(); }else if(phone.attr("validateStatus") != "true"){ phone.blur(); }/*else if(userRole.attr("validateStatus") != "true"){ userRole.blur(); }*/else{ if(confirm("是否确认提交数据")){ $("#userForm").submit(); } } }); backBtn.on("click",function(){ if(referer != undefined && null != referer && "" != referer && "null" != referer && referer.length > 4){ window.location.href = referer; }else{ history.back(-1); } }); });
userlist.js
var userObj; //用户管理页面上点击删除按钮弹出删除框(userlist.jsp) function deleteUser(obj){ $.ajax({ type:"GET", url:path+"/user/deluser.json", data:{id:obj.attr("userid")}, dataType:"json", success:function(data){ if(data.delResult == "true"){//删除成功:移除删除行 cancleBtn(); obj.parents("tr").remove(); }else if(data.delResult == "false"){//删除失败 //alert("对不起,删除用户【"+obj.attr("username")+"】失败"); changeDLGContent("对不起,删除用户【"+obj.attr("username")+"】失败"); }else if(data.delResult == "notexist"){ //alert("对不起,用户【"+obj.attr("username")+"】不存在"); changeDLGContent("对不起,用户【"+obj.attr("username")+"】不存在"); } }, error:function(data){ //alert("对不起,删除失败"); changeDLGContent("对不起,删除失败"); } }); } function openYesOrNoDLG(){ $('.zhezhao').css('display', 'block'); $('#removeUse').fadeIn(); } function cancleBtn(){ $('.zhezhao').css('display', 'none'); $('#removeUse').fadeOut(); } function changeDLGContent(contentStr){ var p = $(".removeMain").find("p"); p.html(contentStr); } $(function(){ //通过jquery的class选择器(数组) //对每个class为viewUser的元素进行动作绑定(click) /** * bind、live、delegate * on */ $(".viewUser").on("click",function(){ //将被绑定的元素(a)转换成jquery对象,可以使用jquery方法 var obj = $(this); /*window.location.href=path+"/user/view/"+ obj.attr("userid");*/ $.ajax({ type:"GET", url:path+"/user/view", data:{userid:obj.attr("userid"),format:"json"}, /*url:path+"/user/view",*/ /*data:{id:obj.attr("userid"),format:"json"},*/ dataType:"json", success:function(result){ //alert(result.userName); if("failed" == result){ alert("操作超时!"); }else if("nodata" == result){ alert("没有数据!"); }else{ $("#v_userCode").val(result.userCode); $("#v_userName").val(result.userName); if(result.gender == "1"){ $("#v_gender").val("女"); }else if(result.gender == "2"){ $("#v_gender").val("男"); } $("#v_birthday").val(result.birthday); $("#v_phone").val(result.phone); $("#v_address").val(result.address); $("#v_userRoleName").val(result.roleName); $("#v_creationDate").val(result.creationDate); } }, error:function(data){ alert("error!"); } }); }); $(".modifyUser").on("click",function(){ var obj = $(this); window.location.href=path+"/user/usermodify.html?uid="+ obj.attr("userid"); }); $('#no').click(function () { cancleBtn(); }); $('#yes').click(function () { deleteUser(userObj); return false; }); $(".deleteUser").on("click",function(){ userObj = $(this); changeDLGContent("你确定要删除用户【"+userObj.attr("username")+"】吗?"); openYesOrNoDLG(); }); /*$(".deleteUser").on("click",function(){ var obj = $(this); if(confirm("你确定要删除用户【"+obj.attr("username")+"】吗?")){ $.ajax({ type:"GET", url:path+"/jsp/user.do", data:{method:"deluser",uid:obj.attr("userid")}, dataType:"json", success:function(data){ if(data.delResult == "true"){//删除成功:移除删除行 alert("删除成功"); obj.parents("tr").remove(); }else if(data.delResult == "false"){//删除失败 alert("对不起,删除用户【"+obj.attr("username")+"】失败"); }else if(data.delResult == "notexist"){ alert("对不起,用户【"+obj.attr("username")+"】不存在"); } }, error:function(data){ alert("对不起,删除失败"); } }); } });*/ });
相关文章推荐
- SuperMarketSys_SSM超市管理系统(Spring+SpringMVC+Mybatis)
- SSM学生管理系统SpringMVC+MyBatis
- java 库存 进销存 商户 多用户管理系统 SSM springmvc 项目源码
- java 库存 进销存 商户 多用户管理系统 SSM springmvc 项目源码
- java 库存 进销存 商户 多用户管理系统 SSM springmvc 项目源码
- [spring+springmvc+mybatis实践]学生社团管理系统
- ssm框架创建简单的DVD管理系统(四)spring的配置与mybatis的配置
- spring boot+mvc+mybatis(通用mapper)+druid+jsp+bootstrap实现后台权限管理系统源码
- ssm(springMVC+spring+mybatis)框架--网络电影投票系统
- java 库存 进销存 商户 多用户管理系统 SSM springmvc 项目源码
- java 库存 进销存 商户 多用户管理系统 SSM springmvc 项目源码
- java 库存 进销存 商户 多用户管理系统 SSM springmvc 项目源码
- spring+springmvc+mybatis shiro权限管理系统demo mysql数据库
- 基于现如今流行的SSM(spring springMVC mybatis mysql)框架的hrm人事管理系统后台实例
- java 库存 进销存 商户 多用户管理系统 SSM springmvc 项目源码
- SpringMvc+Mybatis实现一个简单人事管理系统(三)
- J2EE项目系列(四)--SSM框架构建积分系统和基本商品检索系统(Spring+SpringMVC+MyBatis+Lucene+Redis+MAVEN)(1)框架整合构建
- java 库存 进销存 商户 多用户管理系统 SSM springmvc 项目源码
- J2EE项目系列(四)--SSM框架构建积分系统和基本商品检索系统(Spring+SpringMVC+MyBatis+Lucene+Redis+MAVEN)(2)建立商品数据库和Lucene的搭建