会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 134088个问题
JAVA 全系列/第十一阶段:分布式RPC调用和分布式文件存储/Dubbo 18677楼
人工智能/第二阶段:人工智能基础-Python基础/Python基础语法-旧 18679楼
JAVA 全系列/第十八阶段:亿级高并发电商项目_架构/编码(旧)/电商:基于FastDFS+Nginx+Kinkeditor实现商品新增 18680楼
JAVA 全系列/第十一阶段:分布式RPC调用和分布式文件存储/Dubbo 18681楼
JAVA 全系列/第十八阶段:亿级高并发电商项目_架构/编码(旧)/电商:使用Nginx实现负载均衡及整体环境部署 18682楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/容器(旧) 18683楼

老师,有个路径访问的问题,一直出错,不知道如何解决,为了能让您更好地理解我的意思,内容可能会多,望老师能看完。


问题:我的项目出现了路径访问的错误,就是不能更好处理请求转发与重定向产生的资源路径访问问题。

首先,我知道的是,请求转发是需要在请求头中添加信息需要带会给客户端的时候是用它;重定向更好是在使用表单时使用。


那么现在,我的项目就是:基于请求转发时,没操作功能时可以正常的返回主页面,但是一旦操作了一个功能后页面就会报404错误;但是若是基于重定向的话,就不会出现这个问题,不管是执行完后,还是没执行功能前都可以返回上一层。


详情如下:就以添加用户为例:


image.png


image.png




image.png




image.png



但是,这一切,若是在重定向上,就完全没有问题.。


image.png

image.png



但是这样一来,却违背了我想将数据显示在同样的页面上的,要是使用重定向,将需要显示的数据放在另一个页面上,不太方便,就像很多图书管理系统,数据就显示到了当前的页面上。



所有的servlet代码:

package com.example.servlet.UserManager;

import com.example.exception.NotSearchUserResultException;
import com.example.pojo.Users;
import com.example.service.ServiceImpl.ServiceUserManagerClass;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.List;

@WebServlet("/userManager.do")
public class UserManagerServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        /**
         * 我在这里面就对其用户管理进行全部操作
         */
        String flag = req.getParameter("flag");

        if ("addUser".equals(flag)) {
            /**
             * 执行添加用户函数
             */
            try {

                Users users = this.getUsersMessage(req);
                ServiceUserManagerClass serviceUserManagerClass = new ServiceUserManagerClass();
                serviceUserManagerClass.addUsers(users);
                List<Users> list = serviceUserManagerClass.allUsers();
                req.setAttribute("listAllUsers",list);
                req.setAttribute("addUserMessageSuccess","用户信息已经添加成功!");
                req.getRequestDispatcher("userManagerJsp/addUser.jsp").forward(req,resp);
                
              //resp.sendRedirect("userManagerJsp/addUser.jsp");

                /**
                 * 老师以上就是我刚才举得例子:
                 * 是基于请求转发的
                 */


            } catch (Exception e) {
                e.printStackTrace();
                resp.sendRedirect("error.jsp");
            }

        } else if ("deleteUser".equals(flag)) {
            /**
             * 执行删除用户函数
             */
            try {

                String userName = req.getParameter("userName");

                ServiceUserManagerClass serviceUserManagerClass = new ServiceUserManagerClass();
                serviceUserManagerClass.deleteUser(userName);
                List<Users> list = serviceUserManagerClass.allUsers();
                req.setAttribute("listAllUsers",list);
                req.setAttribute("deleteUserMessageSuccess","用户信息已经删除成功!");
                req.getRequestDispatcher("userManagerJsp/deleteUser.jsp").forward(req,resp);

            } catch (Exception e) {
                e.printStackTrace();
                resp.sendRedirect("error.jsp");
            }


        } else if ("updateUser".equals(flag)) {
            /**
             * 执行更新用户函数
             */
            try {

                /**
                 * 是从表单里面提取的新的数据,但是我还需要旧的,咋办???
                 */
                Users newUser = this.getUsersMessage(req);
                String oldUserID = req.getParameter("oldUserID");

                ServiceUserManagerClass serviceUserManagerClass = new ServiceUserManagerClass();
                serviceUserManagerClass.updateUsers(oldUserID, newUser);

                List<Users> list = serviceUserManagerClass.allUsers();
                req.setAttribute("listAllUsers",list);
                req.setAttribute("deleteUserMessageSuccess","用户信息已经修改成功!");
                req.getRequestDispatcher("userManagerJsp/userUpdate.jsp").forward(req,resp);

            } catch (Exception e) {
                e.printStackTrace();
                resp.sendRedirect("error.jsp");
            }

        } else if ("searchUser".equals(flag)){
            /**
             * 执行查找用户函数
             */
            try {
                String userName = req.getParameter("userName");
                ServiceUserManagerClass serviceUserManagerClass = new ServiceUserManagerClass();
                Users usersTemp = serviceUserManagerClass.searchUsers(userName);
                List<Users> list = serviceUserManagerClass.allUsers();
                if (usersTemp != null) {

                    req.setAttribute("userIdMsg",usersTemp.getUserID());
                    req.setAttribute("userNameMsg",usersTemp.getUserName());
                    req.setAttribute("userEmailMsg",usersTemp.getUserEmial());
                    req.setAttribute("listAllUsers",list);
                    req.setAttribute("searchUserResultMsgSuccess","成功查询结果信息");
                    req.getRequestDispatcher("userManagerJsp/findUser.jsp").forward(req,resp);

                } else {
                    throw new NotSearchUserResultException("查询结果信息不存在,请重新输入...");
                }
            } catch (NotSearchUserResultException e) {
                e.printStackTrace();
                req.setAttribute("searchUserResultMsg",e.getMessage());
                req.getRequestDispatcher("userManagerJsp/findUser.jsp").forward(req,resp);
            }
        }
    }

    /**
     * 获取来自前端的用户的数据
     */
    private Users getUsersMessage(HttpServletRequest req) {
        Users users = new Users();

        String userID = req.getParameter("userName");
        String userPwd = req.getParameter("userPwd");
        String userEmail = req.getParameter("userEmail");
        users.setUserID(userID);
        users.setUserName(userPwd);
        users.setUserEmial(userEmail);

        return users;
    }
}


老师,如果需要项目的话,我全部上传。

JAVA 全系列/第六阶段:JavaWeb开发/Web实战案例 18684楼


Error parsing Mapper XML. The XML location is 'com/bjsxt/mapper/UsersMapper.xml'. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.bjsxt.mapper.UsersMapper.BaseResultMap


使用这个插件 org.mybatis.generator 生成的xml文件,里面有多个id,相同

是什么回事

<?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.bjsxt.mapper.UsersMapper">
  <resultMap id="BaseResultMap" type="com.bjsxt.pojo.Users">
    <result column="USER" jdbcType="CHAR" property="user" />
    <result column="CURRENT_CONNECTIONS" jdbcType="BIGINT" property="currentConnections" />
    <result column="TOTAL_CONNECTIONS" jdbcType="BIGINT" property="totalConnections" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    USER, CURRENT_CONNECTIONS, TOTAL_CONNECTIONS
  </sql>
  <select id="selectByExample" parameterType="com.bjsxt.pojo.UsersExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from users
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <delete id="deleteByExample" parameterType="com.bjsxt.pojo.UsersExample">
    delete from users
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.bjsxt.pojo.Users">
    insert into users (USER, CURRENT_CONNECTIONS, TOTAL_CONNECTIONS
      )
    values (#{user,jdbcType=CHAR}, #{currentConnections,jdbcType=BIGINT}, #{totalConnections,jdbcType=BIGINT}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.bjsxt.pojo.Users">
    insert into users
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="user != null">
        USER,
      </if>
      <if test="currentConnections != null">
        CURRENT_CONNECTIONS,
      </if>
      <if test="totalConnections != null">
        TOTAL_CONNECTIONS,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="user != null">
        #{user,jdbcType=CHAR},
      </if>
      <if test="currentConnections != null">
        #{currentConnections,jdbcType=BIGINT},
      </if>
      <if test="totalConnections != null">
        #{totalConnections,jdbcType=BIGINT},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.bjsxt.pojo.UsersExample" resultType="java.lang.Long">
    select count(*) from users
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update users
    <set>
      <if test="record.user != null">
        USER = #{record.user,jdbcType=CHAR},
      </if>
      <if test="record.currentConnections != null">
        CURRENT_CONNECTIONS = #{record.currentConnections,jdbcType=BIGINT},
      </if>
      <if test="record.totalConnections != null">
        TOTAL_CONNECTIONS = #{record.totalConnections,jdbcType=BIGINT},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update users
    set USER = #{record.user,jdbcType=CHAR},
      CURRENT_CONNECTIONS = #{record.currentConnections,jdbcType=BIGINT},
      TOTAL_CONNECTIONS = #{record.totalConnections,jdbcType=BIGINT}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <resultMap id="BaseResultMap" type="com.bjsxt.pojo.Users">
    <result column="username" jdbcType="VARCHAR" property="username" />
    <result column="password" jdbcType="VARCHAR" property="password" />
    <result column="salting" jdbcType="VARCHAR" property="salting" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    username, password, salting
  </sql>
  <select id="selectByExample" parameterType="com.bjsxt.pojo.UsersExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from users
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <delete id="deleteByExample" parameterType="com.bjsxt.pojo.UsersExample">
    delete from users
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.bjsxt.pojo.Users">
    insert into users (username, password, salting
      )
    values (#{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, #{salting,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.bjsxt.pojo.Users">
    insert into users
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="username != null">
        username,
      </if>
      <if test="password != null">
        password,
      </if>
      <if test="salting != null">
        salting,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="username != null">
        #{username,jdbcType=VARCHAR},
      </if>
      <if test="password != null">
        #{password,jdbcType=VARCHAR},
      </if>
      <if test="salting != null">
        #{salting,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.bjsxt.pojo.UsersExample" resultType="java.lang.Long">
    select count(*) from users
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update users
    <set>
      <if test="record.username != null">
        username = #{record.username,jdbcType=VARCHAR},
      </if>
      <if test="record.password != null">
        password = #{record.password,jdbcType=VARCHAR},
      </if>
      <if test="record.salting != null">
        salting = #{record.salting,jdbcType=VARCHAR},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update users
    set username = #{record.username,jdbcType=VARCHAR},
      password = #{record.password,jdbcType=VARCHAR},
      salting = #{record.salting,jdbcType=VARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <resultMap id="BaseResultMap" type="com.bjsxt.pojo.Users">
    <id column="userid" jdbcType="INTEGER" property="userid" />
    <result column="username" jdbcType="VARCHAR" property="username" />
    <result column="userage" jdbcType="INTEGER" property="userage" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    userid, username, userage
  </sql>
  <select id="selectByExample" parameterType="com.bjsxt.pojo.UsersExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from users
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from users
    where userid = #{userid,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from users
    where userid = #{userid,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="com.bjsxt.pojo.UsersExample">
    delete from users
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.bjsxt.pojo.Users">
    insert into users (userid, username, userage
      )
    values (#{userid,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR}, #{userage,jdbcType=INTEGER}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.bjsxt.pojo.Users">
    insert into users
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="userid != null">
        userid,
      </if>
      <if test="username != null">
        username,
      </if>
      <if test="userage != null">
        userage,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="userid != null">
        #{userid,jdbcType=INTEGER},
      </if>
      <if test="username != null">
        #{username,jdbcType=VARCHAR},
      </if>
      <if test="userage != null">
        #{userage,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.bjsxt.pojo.UsersExample" resultType="java.lang.Long">
    select count(*) from users
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update users
    <set>
      <if test="record.userid != null">
        userid = #{record.userid,jdbcType=INTEGER},
      </if>
      <if test="record.username != null">
        username = #{record.username,jdbcType=VARCHAR},
      </if>
      <if test="record.userage != null">
        userage = #{record.userage,jdbcType=INTEGER},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update users
    set userid = #{record.userid,jdbcType=INTEGER},
      username = #{record.username,jdbcType=VARCHAR},
      userage = #{record.userage,jdbcType=INTEGER}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.bjsxt.pojo.Users">
    update users
    <set>
      <if test="username != null">
        username = #{username,jdbcType=VARCHAR},
      </if>
      <if test="userage != null">
        userage = #{userage,jdbcType=INTEGER},
      </if>
    </set>
    where userid = #{userid,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.bjsxt.pojo.Users">
    update users
    set username = #{username,jdbcType=VARCHAR},
      userage = #{userage,jdbcType=INTEGER}
    where userid = #{userid,jdbcType=INTEGER}
  </update>
  <resultMap id="BaseResultMap" type="com.bjsxt.pojo.Users">
    <result column="username" jdbcType="VARCHAR" property="username" />
    <result column="password" jdbcType="VARCHAR" property="password" />
    <result column="salting" jdbcType="VARCHAR" property="salting" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    username, password, salting
  </sql>
  <select id="selectByExample" parameterType="com.bjsxt.pojo.UsersExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from users
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <delete id="deleteByExample" parameterType="com.bjsxt.pojo.UsersExample">
    delete from users
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.bjsxt.pojo.Users">
    insert into users (username, password, salting
      )
    values (#{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, #{salting,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.bjsxt.pojo.Users">
    insert into users
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="username != null">
        username,
      </if>
      <if test="password != null">
        password,
      </if>
      <if test="salting != null">
        salting,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="username != null">
        #{username,jdbcType=VARCHAR},
      </if>
      <if test="password != null">
        #{password,jdbcType=VARCHAR},
      </if>
      <if test="salting != null">
        #{salting,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.bjsxt.pojo.UsersExample" resultType="java.lang.Long">
    select count(*) from users
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update users
    <set>
      <if test="record.username != null">
        username = #{record.username,jdbcType=VARCHAR},
      </if>
      <if test="record.password != null">
        password = #{record.password,jdbcType=VARCHAR},
      </if>
      <if test="record.salting != null">
        salting = #{record.salting,jdbcType=VARCHAR},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update users
    set username = #{record.username,jdbcType=VARCHAR},
      password = #{record.password,jdbcType=VARCHAR},
      salting = #{record.salting,jdbcType=VARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
</mapper>


插件配置

<build>
    <plugins>
        <!-- generator  -->
        <plugin>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-maven-plugin</artifactId>
            <dependencies>
                <!-- 插件中引入依赖,只会去本地仓库中查找 -->
                <dependency>
                    <groupId>mysql</groupId>
                    <artifactId>mysql-connector-java</artifactId>
                    <version>8.0.22</version>
                </dependency>
            </dependencies>
            <configuration>
                <configurationFile>
                    ${project.basedir}/src/main/resources/generatorConfig.xml
                </configurationFile>
                <verbose>true</verbose>
                <overwrite>true</overwrite>
            </configuration>
        </plugin>
    </plugins>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
    </resources>
</build>

解决方法是,将相同的id删除,我就是想问一下,这个插件为什么会出现这种情况


JAVA 全系列/第八阶段:Linux入门到实战/Maven 18685楼
Python全系列/第一阶段:AI驱动的Python编程/编程基本概念 18686楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/智能电话本项目实战 18688楼
JAVA 全系列/第十一阶段:分布式RPC调用和分布式文件存储/FastDFS 18689楼
JAVA 全系列/第六阶段:项目管理与SSM框架/Mybatis 18690楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637