ssm框架-图书管理系统用户界面功能实现
程序员文章站
2022-04-26 10:00:06
...
首先对该项目后台进行了分层:
如下图
UserInfoController.java:
package com.hyg.im.controller;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.hyg.im.model.UserInfo;
import com.hyg.im.service.UserInfoService;
import com.hyg.im.util.JSON;
@Controller
//@RequestMapping("/user")
public class UserInfoController{
@Autowired
private UserInfoService userInfoService;
/**
* 查询用户列表
*/
@RequestMapping("/findUserInfoList")
public void findUserInfoList(HttpServletRequest request,HttpServletResponse response) throws Exception{
String pageIndex =request.getParameter("pageIndex");//页面索引
String pageSize =request.getParameter("pageSize");//每页多少条
String username =request.getParameter("key");//获取用户姓名
HashMap mapParam=new HashMap<String, Comparable>();
/*mapParam.put("pageIndex",Integer.parseInt(pageIndex));*/
mapParam.put("pageSize", Integer.parseInt(pageSize));
mapParam.put("rowNum", Integer.parseInt(pageSize)*Integer.parseInt(pageIndex));
mapParam.put("username",username);
List<UserInfo> userInfoList = userInfoService.findUserInfoList(mapParam);
int count = userInfoService.findUserInfoCount();//查询数据总数
HashMap map=new HashMap();
map.put("total", count);
map.put("data", userInfoList);
String json = JSON.encode(map);
System.out.println(json);
//向前端返回数据
response.getWriter().write(json);
}
@RequestMapping("/addUserInfo")
public void addUserInfo(HttpServletRequest request,HttpServletResponse response) throws Exception{
String data = request.getParameter("data");
/*
List list = (ArrayList)JSON.decode(data);
HashMap o = (HashMap)list.get(0);
String userno = o.get("userno") != null ? o.get("id").toString() : "";*/
String userid = request.getParameter("userid");
if(userid == null || userid.equals("")){
userid = "0";
}
String userno = request.getParameter("userno");
String password = request.getParameter("password");
String username = request.getParameter("username");
String sex = request.getParameter("sex");
String address = request.getParameter("address");
String phone = request.getParameter("phone");
String role = request.getParameter("role");
UserInfo userInfo =new UserInfo();
userInfo.setUserid(Long.parseLong(userid));
userInfo.setUserno(userno);
userInfo.setPassword(password);
userInfo.setUsername(username);
userInfo.setSex(sex);
userInfo.setAddress(address);
userInfo.setPhone(phone);
userInfo.setRole(Integer.parseInt(role));
//调用业务层,增加用户
int result = userInfoService.addUserInfo(userInfo);
if(result > 0){
response.getWriter().write("success");
}else{
response.getWriter().write("fail");
}
}
@RequestMapping("/findUserInfo")
public void findUserInfo(HttpServletRequest request,HttpServletResponse response) throws Exception{
String id = request.getParameter("id");
UserInfo userInfo = userInfoService.findUserInfo(Integer.parseInt(id));
String json = JSON.encode(userInfo);
System.out.println(json);
//向前端返回数据
response.getWriter().write(json);
}
@RequestMapping("/deleteUserInfo")
public void deleteUserInfo(HttpServletRequest request,HttpServletResponse response) throws Exception{
String userids = request.getParameter("userids");
String[] ids = userids.split(",");
for(int i = 0; i<ids.length;i++){
int id = Integer.parseInt(ids[i]);
int result = userInfoService.deleteUserInfo(id);
}
}
@RequestMapping("/userLogin")
public void userLogin(HttpServletRequest request,HttpServletResponse response) throws Exception{
String username = request.getParameter("username");
String pwd = request.getParameter("pwd");
UserInfo userInfo =new UserInfo();
userInfo.setPassword(pwd);
userInfo.setUserno(username);
UserInfo u = userInfoService.login(userInfo);
if(u!=null){
response.getWriter().write("success");
}else{
response.getWriter().write("fail");
}
}
}
UserInfoMapper.java:
package com.hyg.im.mapper;
import java.util.HashMap;
import java.util.List;
import com.hyg.im.model.UserInfo;
import com.sun.javafx.collections.MappingChange.Map;
public interface UserInfoMapper {
int deleteByPrimaryKey(int id);
int insert(UserInfo record);
int insertSelective(UserInfo record);
UserInfo selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(UserInfo record);
int updateByPrimaryKey(UserInfo record);
List<UserInfo> findUserInfoList(HashMap mapParam);
int findUserInfoCount();
UserInfo userLogin(UserInfo userInfo);
}
UserInfoMapper.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.hyg.im.mapper.UserInfoMapper" >
<resultMap id="BaseResultMap" type="com.hyg.im.model.UserInfo" >
<id column="userId" property="userid" jdbcType="BIGINT" />
<result column="userNo" property="userno" jdbcType="VARCHAR" />
<result column="password" property="password" jdbcType="VARCHAR" />
<result column="userName" property="username" jdbcType="VARCHAR" />
<result column="age" property="age" jdbcType="INTEGER" />
<result column="sex" property="sex" jdbcType="VARCHAR" />
<result column="address" property="address" jdbcType="VARCHAR" />
<result column="phone" property="phone" jdbcType="VARCHAR" />
<result column="role" property="role" jdbcType="INTEGER" />
<result column="createTime" property="createtime" jdbcType="TIMESTAMP" />
</resultMap>
<sql id="Base_Column_List" >
userId, userNo, password, userName, age, sex, address, phone, role, createTime
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
select
<include refid="Base_Column_List" />
from user_info
where userId = #{userid,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
delete from user_info
where userId = #{userid,jdbcType=BIGINT}
</delete>
<insert id="insert" parameterType="com.hyg.im.model.UserInfo" >
insert into user_info (userId, userNo, password,
userName, age, sex,
address, phone, role,
createTime)
values (#{userid,jdbcType=BIGINT}, #{userno,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},
#{username,jdbcType=VARCHAR}, #{age,jdbcType=INTEGER}, #{sex,jdbcType=VARCHAR},
#{address,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, #{role,jdbcType=INTEGER},
#{createtime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="com.hyg.im.model.UserInfo" >
insert into user_info
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="userid != null" >
userId,
</if>
<if test="userno != null" >
userNo,
</if>
<if test="password != null" >
password,
</if>
<if test="username != null" >
userName,
</if>
<if test="age != null" >
age,
</if>
<if test="sex != null" >
sex,
</if>
<if test="address != null" >
address,
</if>
<if test="phone != null" >
phone,
</if>
<if test="role != null" >
role,
</if>
<if test="createtime != null" >
createTime,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="userid != null" >
#{userid,jdbcType=BIGINT},
</if>
<if test="userno != null" >
#{userno,jdbcType=VARCHAR},
</if>
<if test="password != null" >
#{password,jdbcType=VARCHAR},
</if>
<if test="username != null" >
#{username,jdbcType=VARCHAR},
</if>
<if test="age != null" >
#{age,jdbcType=INTEGER},
</if>
<if test="sex != null" >
#{sex,jdbcType=VARCHAR},
</if>
<if test="address != null" >
#{address,jdbcType=VARCHAR},
</if>
<if test="phone != null" >
#{phone,jdbcType=VARCHAR},
</if>
<if test="role != null" >
#{role,jdbcType=INTEGER},
</if>
<if test="createtime != null" >
#{createtime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.hyg.im.model.UserInfo" >
update user_info
<set >
<if test="userno != null" >
userNo = #{userno,jdbcType=VARCHAR},
</if>
<if test="password != null" >
password = #{password,jdbcType=VARCHAR},
</if>
<if test="username != null" >
userName = #{username,jdbcType=VARCHAR},
</if>
<if test="age != null" >
age = #{age,jdbcType=INTEGER},
</if>
<if test="sex != null" >
sex = #{sex,jdbcType=VARCHAR},
</if>
<if test="address != null" >
address = #{address,jdbcType=VARCHAR},
</if>
<if test="phone != null" >
phone = #{phone,jdbcType=VARCHAR},
</if>
<if test="role != null" >
role = #{role,jdbcType=INTEGER},
</if>
<if test="createtime != null" >
createTime = #{createtime,jdbcType=TIMESTAMP},
</if>
</set>
where userId = #{userid,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.hyg.im.model.UserInfo" >
update user_info
set userNo = #{userno,jdbcType=VARCHAR},
password = #{password,jdbcType=VARCHAR},
userName = #{username,jdbcType=VARCHAR},
age = #{age,jdbcType=INTEGER},
sex = #{sex,jdbcType=VARCHAR},
address = #{address,jdbcType=VARCHAR},
phone = #{phone,jdbcType=VARCHAR},
role = #{role,jdbcType=INTEGER},
createTime = #{createtime,jdbcType=TIMESTAMP}
where userId = #{userid,jdbcType=BIGINT}
</update>
<select id="findUserInfoList" resultMap="BaseResultMap" parameterType="map" >
select
<include refid="Base_Column_List" />
from user_info
<if test="username != null" >
where username like "%"#{username,jdbcType=VARCHAR}"%"
</if> limit #{rowNum},#{pageSize}
</select>
<select id="findUserInfoCount" resultType="java.lang.Integer" parameterType="map">
select count(*) from user_info
</select>
<select id="userLogin" resultMap="BaseResultMap" parameterType="com.hyg.im.model.UserInfo" >
select
<include refid="Base_Column_List" />
from user_info
where userNo = #{userno,jdbcType=VARCHAR} and password = #{password,jdbcType=VARCHAR}
</select>
</mapper>
UserInfoService.java:
package com.hyg.im.service;
import java.util.HashMap;
import java.util.List;
import com.hyg.im.model.UserInfo;
public interface UserInfoService {
/**
* 查询所有用户信息
*/
List<UserInfo> findUserInfoList(HashMap mapParam);
/*
*
*/
public int findUserInfoCount();
int addUserInfo(UserInfo userInfo);
UserInfo findUserInfo(int id);
int deleteUserInfo(int id);
UserInfo login(UserInfo userInfo);
}
UserInfoServiceImpl.java:
package com.hyg.im.service.impl;
import java.util.HashMap;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.hyg.im.mapper.UserInfoMapper;
import com.hyg.im.model.UserInfo;
import com.hyg.im.service.UserInfoService;
import com.sun.javafx.collections.MappingChange.Map;
@Service
@Transactional //此处不再进行创建SqlSession和提交事务,都已交由spring去管理了。
public class UserInfoServiceImpl implements UserInfoService {
@Resource
private UserInfoMapper mapper;
@Override
public List<UserInfo> findUserInfoList(HashMap mapParam) {
return mapper.findUserInfoList(mapParam);
}
@Override
public int findUserInfoCount() {
return mapper.findUserInfoCount();
}
@Override
public int addUserInfo(UserInfo userInfo) {
// TODO Auto-generated method stub
if(userInfo.getUserid()==0){
return mapper.insertSelective(userInfo);
}else{
return mapper.updateByPrimaryKeySelective(userInfo);
}
}
@Override
public UserInfo findUserInfo(int id) {
// TODO Auto-generated method stub
return mapper.selectByPrimaryKey(id);
}
@Override
public int deleteUserInfo(int id) {
// TODO Auto-generated method stub
return mapper.deleteByPrimaryKey(id);
}
@Override
public UserInfo login(UserInfo userInfo) {
// TODO Auto-generated method stub
return mapper.userLogin(userInfo);
}
}
UserInfo.java:
package com.hyg.im.model;
import java.util.Date;
public class UserInfo {
private Long userid;
private String userno;
private String password;
private String username;
private Integer age;
private String sex;
private String address;
private String phone;
private Integer role;
private Date createtime;
public Long getUserid() {
return userid;
}
public void setUserid(Long userid) {
this.userid = userid;
}
public String getUserno() {
return userno;
}
public void setUserno(String userno) {
this.userno = userno == null ? null : userno.trim();
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password == null ? null : password.trim();
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username == null ? null : username.trim();
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex == null ? null : sex.trim();
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address == null ? null : address.trim();
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone == null ? null : phone.trim();
}
public Integer getRole() {
return role;
}
public void setRole(Integer role) {
this.role = role;
}
public Date getCreatetime() {
return createtime;
}
public void setCreatetime(Date createtime) {
this.createtime = createtime;
}
}
功能展示:
上一篇: Linux运维之道(8)——用户和组管理
下一篇: Linux基础之用户和用户组管理
推荐阅读
-
Laravel 框架基于自带的用户系统实现登录注册及错误处理功能分析
-
Laravel 框架基于自带的用户系统实现登录注册及错误处理功能分析
-
荐 四十一、Vue项目上手 | 用户管理系统 实现用户修改和删除功能(完成篇)
-
四十、Vue项目上手 | 用户管理系统 实现弹窗,搜索和详细页功能(下篇)
-
四十一、Vue项目上手 | 用户管理系统 实现用户修改和删除功能(完成篇)
-
(一)SpringMvc设备管理系统全程笔记 -----框架搭建 login登录功能实现
-
.NET快速信息化系统开发框架 V3.2 -> “用户管理”主界面使用多表头展示、增加打印功能
-
实训日志2 SSM框架了解和实现简单用户管理系统的增删改查
-
系统功能初步实现(学生管理系统v0.1——增加用户登录功能)
-
ssm框架-图书管理系统用户界面功能实现