目录
用户管理
前端:jquery、bootstrap、jsp
后端:ssm框架+springboot
1、API
(1)用户注册 注册
(2)用户管理 分页查询,修改,删除
2、后端实现
(1)实体类(略)
(2)dao层UserDao
public interface UserDao{
int insert(User user);
User login(@Param("userName") String userName,@Param("password") String password);
User queryById(@Param("userId") Long userId);
User queryByUserName(@Param("userName") String userName);
int getCount(@Param("queryDto")UserQueryDto queryDto);//用户总数
int update(User user);
/*
*分页查询
*@Param UserQueryDto 查询dto类,直接用实体User其实也可以
*/
List<User> queryForList(@Param("queryDto")UserQueryDto
queryDto,@Param("pageInfo")PageInfo pageInfo);
int delete(@Param("userId") long userId);
}
数据库使用mysql,采用mybatis框架,通过xml映射实现dao接口,具体配置略。如果采用Jpa需要通过继承JpaRepository,这里不对Jpa技术进行描述。
mybaitis-config.xml配置<!-- 驼峰命名映射 --> <setting name="mapUnderscoreToCamelCase" value="true" />
application.properties配置
mybatis.config-location=classpath:mybatis-config.xml
mybatis.mapper-locations=classpath:sqlmap/*.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">
<!--这块等于dao接口的实现 namespace必须和接口的类路径一样 -->
<mapper namespace="com.lixuepei.blog.dao.UserDao">
<insert id="insert">
insert into t_user (time_create,user_name,password,nick_name,phone_no,email)
values (now(), #{userName}, #{password},#{nickName},#{phoneNo},#{email})
</insert>
<sql id="selects">
select
user_id,
time_create,
time_modify,
user_name,
password,
nick_name,
phone_no,
email,
photo,
role_name,
time_last_login
from t_user
</sql>
<select id="login" resultType="com.lixuepei.blog.pojo.User">
<include refid="selects" />
where user_name = #{userName}
and password = #{password}
</select>
<select id="queryById" resultType="com.lixuepei.blog.pojo.User">
<include refid="selects" />
where user_id = #{userId}
</select>
<select id="getCount" resultType="int">
select count(*) from t_user
</select>
<update id="update">
update t_user set time_modify = now(),
<if test="null != nickName and '' != nickName">
nick_name = #{nickName},
</if>
<if test="null != phoneNo and '' != phoneNo">
phone_no = #{phoneNo},
</if>
<if test="null != email and '' != email">
email = #{email},
</if>
<if test="null != photo and '' != photo">
photo = #{photo},
</if>
user_id = #{userId}
where user_id = #{userId}
</update>
<select id="queryByUserName" resultType="com.lixuepei.blog.pojo.User">
<include refid="selects" />
where user_name = #{userName}
</select>
<select id="queryForList" resultType="com.lixuepei.blog.pojo.User">
<include refid="selects" />
where 1=1
<if test="null!=queryDto.nickName and ''!=queryDto.nickName" >
and nick_name like CONCAT('%', #{queryDto.nickName}, '%')
</if>
order by user_id DESC
limit #{pageInfo.startIndex},#{pageInfo.pageSize}
</select>
<delete id="delete">
delete from t_user where user_id=#{userId}
</delete>
</mapper>
(3)service和serviceimpl
@Service("userServiceImpl")
public class UserServiceImpl implements UserService{
@Autowired
private UserDao userDao;
@Override
public int insert(User user) {
return this.userDao.insert(user);
}