会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 133622个问题
JAVA 全系列/第十八阶段:亿级高并发电商项目_架构/编码(旧)/电商:基于FastDFS+Nginx+Kinkeditor实现商品新增 18543楼

老师,我出现了下面的报错,请老师帮忙de一下bug

八月 06, 2021 11:34:56 上午 org.apache.coyote.AbstractProtocol init

信息: Initializing ProtocolHandler ["http-bio-8080"]

八月 06, 2021 11:34:56 上午 org.apache.catalina.core.StandardService startInternal

信息: Starting service Tomcat

八月 06, 2021 11:34:56 上午 org.apache.catalina.core.StandardEngine startInternal

信息: Starting Servlet Engine: Apache Tomcat/7.0.47

八月 06, 2021 11:34:58 上午 org.apache.catalina.core.ApplicationContext log

信息: No Spring WebApplicationInitializer types detected on classpath

八月 06, 2021 11:34:58 上午 org.apache.catalina.core.ApplicationContext log

信息: Initializing Spring root WebApplicationContext

log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).

log4j:WARN Please initialize the log4j system properly.

log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

八月 06, 2021 11:34:59 上午 org.apache.catalina.core.StandardContext listenerStart

严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://dubbo.apache.org/schema/dubbo]

Offending resource: file [D:\JavaStudyMaterials\dubbo\consumer\target\classes\spring\applicationContext-dubbo.xml]


at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:72)

at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:119)

at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:111)

at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:281)

at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1388)

at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1371)

at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:179)

at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:149)

at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:96)

at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:509)

at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:389)

at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)

at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:305)

at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)

at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:224)

at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:195)

at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)

at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)

at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:133)

at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:637)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:522)

at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:401)

at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:292)

at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103)

at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)

at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)

at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)

at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)

at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)

at java.util.concurrent.FutureTask.run(FutureTask.java:266)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

at java.lang.Thread.run(Thread.java:748)


八月 06, 2021 11:34:59 上午 org.apache.catalina.core.StandardContext startInternal

严重: Error listenerStart

八月 06, 2021 11:34:59 上午 org.apache.catalina.core.StandardContext startInternal

严重: Context [] startup failed due to previous errors

八月 06, 2021 11:34:59 上午 org.apache.catalina.core.ApplicationContext log

信息: Closing Spring root WebApplicationContext

八月 06, 2021 11:34:59 上午 org.apache.catalina.core.StandardContext listenerStop

严重: Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListener

java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext

at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:177)

at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1060)

at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1029)

at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:978)

at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:517)

at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:112)

at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4980)

at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5626)

at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)

at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)

at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)

at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)

at java.util.concurrent.FutureTask.run(FutureTask.java:266)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

at java.lang.Thread.run(Thread.java:748)


八月 06, 2021 11:34:59 上午 org.apache.coyote.AbstractProtocol start

信息: Starting ProtocolHandler ["http-bio-8080"]

image.png

dubbo.rar


JAVA 全系列/第十一阶段:分布式RPC调用和分布式文件存储/Dubbo 18544楼
JAVA 全系列/第十一阶段:分布式RPC调用和分布式文件存储/Dubbo 18546楼
人工智能/第二阶段:人工智能基础-Python基础/Python基础语法-旧 18548楼
JAVA 全系列/第十八阶段:亿级高并发电商项目_架构/编码(旧)/电商:基于FastDFS+Nginx+Kinkeditor实现商品新增 18549楼
JAVA 全系列/第十一阶段:分布式RPC调用和分布式文件存储/Dubbo 18550楼
JAVA 全系列/第十八阶段:亿级高并发电商项目_架构/编码(旧)/电商:使用Nginx实现负载均衡及整体环境部署 18551楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/容器(旧) 18552楼

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


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

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


那么现在,我的项目就是:基于请求转发时,没操作功能时可以正常的返回主页面,但是一旦操作了一个功能后页面就会报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实战案例 18553楼


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 18554楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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