基于SSM的健身房管理系统 (3)

2 adminMapper

@Mapper @Component public interface AdminMapper{ //查询会员 List<User> queryUser(); //新增会员 int addUser(User user); //删除会员 int deleteUserById(int id); //更新会员 int updateUser(User user); //根据id查询一个会员 User queryUserById(int id); //根据姓名查询一个会员 User queryUserByName(String name); //login Admin adminLogin(Admin admin); //查询用户总数 int selectTotal(); // 分页 @Select("select * from gymms.user") @Results({ // 用户信息,只要指定id列与属性的映射关系,其他列会自动封装(属性与列一致) @Result(property = "id", column = "id"), // 信息 @Result(property = "id", column = "id"), @Result(property = "username", column = "username"), @Result(property = "password", column = "password"), @Result(property = "name", column = "name"), @Result(property = "sex", column = "sex"), @Result(property = "telephone", column = "telephone"), @Result(property = "age", column = "age"), @Result(property = "begintime", column = "begintime"), @Result(property = "endtime", column = "endtime"), @Result(property = "remainday", column = "remainday") }) List<User> findAll(); }

编写接口对应的 Mapper.xml 文件

1 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.cc.dao.UserMapper"> <select resultType="User"> select remainday from gymms.user where id = #{id} </select> <!-- 查询用户--> <select resultType="User"> select * from gymms.user where id = #{id} </select> <!--更新User--> <update parameterType="User"> update gymms.user set username = #{username},password = #{password} where id = #{id} </update> <!--根据账号密码查询,返回一个User--> <select resultType="User"> select * from gymms.user where username = #{username} and password = #{password} </select> <!-- 会员注册--> <!--增加一个会员--> <insert parameterType="User"> insert into gymms.user(username,password,name,sex,telephone,age,begintime,endtime,remainday) values (#{username},#{password},#{name},#{sex},#{telephone},#{age},#{begintime},#{endtime},#{remainday}) </insert> </mapper>

2 adminMapper.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.cc.dao.AdminMapper"> <!--增加一个会员--> <insert parameterType="User"> insert into gymms.user(username,password,name,sex,telephone,age,begintime,endtime,remainday) values (#{username},#{password},#{name},#{sex},#{telephone},#{age},#{begintime},#{endtime},#{remainday}) </insert> <!--根据id删除一个User--> <delete parameterType="int"> delete from gymms.user where id=#{id} </delete> <!--更新User--> <update parameterType="User"> update gymms.user set username = #{username},password = #{password},name = #{name},sex = #{sex},telephone = #{telephone}, age = #{age},endtime = #{endtime},remainday = #{remainday} where id = #{id} </update> <!--根据id查询,返回一个User--> <select resultType="User"> select * from gymms.user where id = #{id} </select> <!--根据姓名查询,返回一个User--> <select resultType="User"> select * from gymms.user where name = #{name} </select> <!--查询全部Book--> <select resultType="User"> SELECT * from gymms.user </select> <!--根据账号密码查询,返回一个Admin--> <select resultType="Admin"> select * from gymms.admin where username = #{username} and password = #{password} </select> <select resultType="int"> select count(*) from gymms.user </select> </mapper>

编写Service层的接口和实现类

1 userService

public interface UserService { // 查询到期时间 Date queryDateById(int id); //修改账号密码 int updateNP(User user); //login User userLogin(User user); //通过id查询 User queryUserById(int id); //会员注册 int userRegister(User user); }

2 adminService

public interface AdminService { //查询会员 List<User> queryUser(); //新增会员 int addUser(User user); //删除会员 int deleteUserById(int id); //更新会员 int updateUser(User user); //根据id查询一个会员 User queryUserById(int id); //根据姓名查询一个会员 User queryUserByName(String name); //login Admin adminLogin(Admin admin); //查询用户总数 int selectTotal(); // 分页 List<User> findAll(); /** * 分页查询 * @param pageNum 当然页 * @param pageSize 页大小 * @return 返回PageHelper提供的封装分页参数的PageInfo对象 */ PageInfo<User> findByPage(int pageNum, int pageSize); }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpwspg.html