不灭的焱

革命尚未成功,同志仍须努力下载JDK17

作者:php-note.com  发布于:2022-04-05 10:53  分类:Java框架/系统  编辑

1.控制器:

文件:UserController.java

@Controller
public class UserController extends BaseController {
    @Resource
    SysUserMapper userMapper;
	
	/**
     * 用户管理
     */
    @RequestMapping(UrlConst.user_admin)
    public String index(Model model, UserAdminForm userAdminForm) {
		// ....
		Page<UserPO> userPageList = this.userMapper.getUserPageList(userAdminForm1, new Page<>(userAdminForm.getPageNum(), userAdminForm.getPageSize()));
		// ....
	}
}

2.Mapper接口

文件:SysUserMapper.java

package com.wanma.framework_web.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wanma.framework_web.entity.SysUser;
import com.wanma.framework_web.model.form.user.UserAdminForm;
import com.wanma.framework_web.model.po.UserPO;

/**
 * 用户表 Mapper 接口
 */
public interface SysUserMapper extends BaseMapper<SysUser> {
    Page<UserPO> getUserPageList(@Param("userAdminForm") UserAdminForm userAdminForm, @Param("page") Page<UserPO> page);
}

3.xml文件

文件:SysUserMapper.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.wanma.framework_web.mapper.SysUserMapper">

    <select id="getUserPageList" resultType="com.wanma.framework_web.model.po.UserPO">
        SELECT A.id, A.account, A.realname, B.role_names
        FROM sys_user A LEFT JOIN sys_user_ext B ON A.id = B.user_id
        <where>
            <if test="userAdminForm.account!=null and userAdminForm.account!=''">
                AND A.account LIKE CONCAT('%', #{userAdminForm.account, jdbcType=VARCHAR},'%')
            </if>
            <if test="userAdminForm.realname!=null and userAdminForm.realname!=''">
                AND A.realname LIKE CONCAT('%', #{userAdminForm.realname, jdbcType=VARCHAR},'%')
            </if>
        </where>
        ORDER BY A.id ASC
    </select>
</mapper>

 



 

1.控制器:

文件:WebUploaderWidget.java

/**
 * 文件上传 Widget
 */
@Slf4j
@Component
public class WebUploaderWidget<T> extends BaseWidget<T> {
	@Resource
    private SysUserFileMapper userFileMapper;
	
	@Override
    public String render(Model model, LinkedHashMap<String, Object> params, LinkedHashMap<T, Object> extParams) {
		// ......
		List<UserFilePO> userFileList = this.userFileMapper.getFileListByIds(userId, ufileIds);
		// ......
	}
}

2.Mapper接口

文件:SysUserFileMapper.java

/**
 * 用户文件表 Mapper 接口
 */
public interface SysUserFileMapper extends BaseMapper<SysUserFile> {
    List<UserFilePO> getFileListByIds(@Param("userId") int userId, @Param("ids") List<String> ids);
}

3.xml文件

文件:SysUserFileMapper.xml

参数userId为 必填

<?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.wanma.framework_web.mapper.SysUserFileMapper">
    <select id="getFileListByIds" resultType="com.wanma.framework_web.model.po.UserFilePO">
        SELECT A.id,A.file_name AS name, A.file_url AS url FROM user_file A LEFT JOIN base_file B ON A.file_id=B.id WHERE 
            <choose>
                <when test="userId lte 0">
                    1=2
                </when>
                <when test="ids==null or ids.size()==0">
                    1=3
                </when>
                <otherwise>
                    A.user_id=${userId} AND A.id IN
                    <foreach collection="ids" item="id" open="(" separator="," close=")">
                        ${id}
                    </foreach>                                                                                                                
                </otherwise>
            </choose>
    </select>
</mapper>

参数userId为 非必填

<?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.wanma.framework_web.mapper.SysUserFileMapper">
    <select id="getFileListByIds" resultType="com.wanma.framework_web.model.po.UserFilePO">
        SELECT A.id,A.file_name AS name, A.file_url AS url FROM sys_user_file A LEFT JOIN sys_file B ON A.file_id=B.id
            <where> 
                <choose>
                    <when test="ids==null or ids.size()==0">
                        1=3
                    </when>
                    <when test="userId > 0">
                        A.user_id=${userId} AND A.id IN
                        <foreach collection="ids" item="id" open="(" separator="," close=")">
                            ${id}
                        </foreach>
                    </when>
                    <otherwise>
                        A.id IN
                        <foreach collection="ids" item="id" open="(" separator="," close=")">
                            ${id}
                        </foreach>                                                                                                                
                    </otherwise>
                </choose>
            </where>
    </select>
</mapper>