基于Spring MVC + Spring + MyBatis的【网上购物系统】

资源下载:https://download.csdn.net/download/weixin_44893902/45601185

练习点设计:修改、删除

一、语言和环境

  1. 实现语言:JAVA语言。
  2. 环境要求:MyEclipse/Eclipse + Tomcat + MySql。
  3. 使用技术:Jsp+Servlet+JavaBeanSpringMVC + Spring + Mybatis

二、实现功能

随着网上购物越来越多,电子订单也日益增多,特需要网上购物系统:
1.首页默认显示所有订单信息,如图所示。

图1 首页显示所有订单信息

2.正确显示订单状态和对应操作:1是已下单,操作为“发货和删除”;2是已发货,操作为“确认收获和删除”; 3是已收货,操作只有“删除”,如图所示。

在这里插入图片描述

图2 订单状态及对应操作
3.用户点击删除,则弹出提示框,用户点击确定后,删除选中数据并显示最新数据,如图所示。

图3 确认删除提示窗口

图4 数据删除后显示最新数据

4.用户点击“发货”操作链接,修改数据库中订单信息,且页面跳转到列表页面展示最新数据,如图所示。

图6  确定发货 提示框

 图7 展示最新数据

5.用户点击“确定收货”操作链接,修改数据库中订单信息,且页面跳转到列表页面展示最新数据,如图所示。

图8确定收货 提示窗口


图9 展示最新数据

三、具体要求及推荐实现步骤

  1. JSP版本的实现步骤如下:
    (1)按以上数据库要求建库、建表,并添加测试数据。
    (2)创建Web工程并创建各个包,导入工程所需的jar文件。
    (3)创建实体类。
    (4)创建Servlet获取用户不同的请求,并将这些请求转发至业务处理层相应的业务方法。
    (5)创建业务处理层,在其中定义业务方法实现系统需求,在这些业务方法中需要执行DAO方法。
    (6)创建BaseDAO工具类,使用JDBC完成数据表数据的查询、删除和添加。
    (7)编写JSP页面,展示数据的查询结果。

  2. SSM版本的实现步骤如下:
    (1)创建数据库和数据表,添加测试数据(至少添加5条测试数据)。
    (2)创建Web工程并创建各个包,导入工程所需的jar文件。
    (3)添加相关SSM框架支持。
    (4)配置项目所需要的各种配置文件(mybatis配置文件、spring配置文件、springMVC配置文件)。
    (5)创建实体类。
    (6)创建MyBatis操作数据库所需的Mapper接口及其Xml映射数据库操作语句文件。
    (7)创建业务逻辑相应的接口及其实现类,实现相应的业务,并在类中加入对DAO/Mapper的引用和注入。
    (8)创建Controller控制器类,在Controller中添加对业务逻辑类的引用和注入,并配置springMVC配置文件。
    (9)创建相关的操作页面,并使用CSS对页面进行美化。
    (10)实现页面的各项操作功能,并在相关地方进行验证,操作要人性化。
    (11)调试运行成功后导出相关的数据库文件并提交。

四、数据库设计

1.创建数据库(Shops)。
2.创建数据表(shop_db),结构如下。

/*
Date: 06/08/2021 19:33:22
*/

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for tb_dever
-- ----------------------------
DROP TABLE IF EXISTS `tb_dever`;
CREATE TABLE `tb_dever`  (
  `dev_id` int(11) NOT NULL AUTO_INCREMENT,
  `dev_name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `dev_level` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `dev_work_year` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `dev_in_year` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`dev_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 8 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of tb_dever
-- ----------------------------
INSERT INTO `tb_dever` VALUES (1, '张三', '高级', '40', '2021-08-02');
INSERT INTO `tb_dever` VALUES (2, '李四', '高级', '25', '2021-07-28');
INSERT INTO `tb_dever` VALUES (3, '王五', '中级', '40', '2020-11-13');
INSERT INTO `tb_dever` VALUES (4, '李梅', '高级', '35', '2021-05-12');
INSERT INTO `tb_dever` VALUES (5, '杨齐', '中级', '28', '2021-07-16');

SET FOREIGN_KEY_CHECKS = 1;

2、项目Java代码

目录结构
Shops

在这里插入图片描述

JAR包:

在这里插入图片描述

在这里插入图片描述

src

com.controller

ShopController.java

package com.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.entity.TbOrder;
import com.service.impl.ShopService;

@Controller
public class ShopController {
	@Resource
	ShopService shoppService;

	@RequestMapping("/selectAll")
	// 查询所有订单
	public String shooplist(Model model) {
		List<TbOrder> selectAll = shoppService.selectAll();
		model.addAttribute("selectAll", selectAll);
		return "/shopOrder";
	}

	// 订单由已下单1变为已发货2
	@RequestMapping("/update1b2")
	public String updateShopp1b2(int id) {
		int updateShop = shoppService.update1b2(id);
		return "redirect:/selectAll.do";
	}

	// 订单由已发货2变为已收货3
	@RequestMapping("/update2b3")
	public String updateShopp2b3(int id) {
		int updateShop = shoppService.update2b3(id);
		return "redirect:/selectAll.do";
	}

	// 删除订单
	@RequestMapping("/del")
	public String deleteShopp(int id) {
		int deldeteShopp = shoppService.del(id);
		return "redirect:/selectAll.do";
	}
}

com.dao

TbOrderMapper.java

package com.dao;

import java.util.List;

import com.entity.TbOrder;

public interface TbOrderMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(TbOrder record);

    TbOrder selectByPrimaryKey(Integer id);

    List<TbOrder> selectAll();

    int updateByPrimaryKey(TbOrder record);
    
    int update1b2(int id);
    
    int update2b3(int id);
}

TbOrderMapper.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.dao.TbOrderMapper">
	<resultMap id="BaseResultMap" type="com.entity.TbOrder">
		<id column="id" property="id" jdbcType="INTEGER" />
		<result column="goodName" property="goodname" jdbcType="VARCHAR" />
		<result column="goodPrice" property="goodprice" jdbcType="VARCHAR" />
		<result column="count" property="count" jdbcType="INTEGER" />
		<result column="total" property="total" jdbcType="VARCHAR" />
		<result column="orderDate" property="orderdate" jdbcType="VARCHAR" />
		<result column="userName" property="username" jdbcType="VARCHAR" />
		<result column="state" property="state" jdbcType="VARCHAR" />
	</resultMap>
	<delete id="del" parameterType="java.lang.Integer">
		delete from tb_order
		where id = #{id,jdbcType=INTEGER}
	</delete>
	<insert id="insert" parameterType="com.entity.TbOrder">
		insert into tb_order (id, goodName, goodPrice,
		count, total, orderDate,
		userName, state)
		values (#{id,jdbcType=INTEGER}, #{goodname,jdbcType=VARCHAR},
		#{goodprice,jdbcType=VARCHAR},
		#{count,jdbcType=INTEGER}, #{total,jdbcType=VARCHAR}, #{orderdate,jdbcType=VARCHAR},
		#{username,jdbcType=VARCHAR}, #{state,jdbcType=VARCHAR})
	</insert>
	<update id="updateByPrimaryKey" parameterType="com.entity.TbOrder">
		update tb_order
		set goodName = #{goodname,jdbcType=VARCHAR},
		goodPrice = #{goodprice,jdbcType=VARCHAR},
		count = #{count,jdbcType=INTEGER},
		total = #{total,jdbcType=VARCHAR},
		orderDate = #{orderdate,jdbcType=VARCHAR},
		userName = #{username,jdbcType=VARCHAR},
		state = #{state,jdbcType=VARCHAR}
		where id = #{id,jdbcType=INTEGER}
	</update>
	<select id="selectByPrimaryKey" resultMap="BaseResultMap"
		parameterType="java.lang.Integer">
		select id, goodName, goodPrice, count, total, orderDate, userName, state
		from tb_order
		where id = #{id,jdbcType=INTEGER}
	</select>
	<select id="selectAll" resultMap="BaseResultMap">
		select id, goodName, goodPrice, count, total, orderDate, userName, state
		from tb_order
	</select>
	<update id="update1b2" parameterType="com.entity.TbOrder">
		update tb_order
		<trim prefix="set" suffixOverrides=",">
			<if test="state=1">
				state=2,
			</if>

		</trim>
		where id = #{id,jdbcType=INTEGER}
	</update>
	<update id="update2b3" parameterType="com.entity.TbOrder">
		update tb_order
		<trim prefix="set" suffixOverrides=",">

			<if test="state=2">
				state=3,
			</if>
		</trim>
		where id = #{id,jdbcType=INTEGER}
	</update>
</mapper>

com.entity

TbOrder.java

package com.entity;

public class TbOrder {
    private Integer id;

    private String goodname;

    private String goodprice;

    private Integer count;

    private String total;

    private String orderdate;

    private String username;

    private String state;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getGoodname() {
        return goodname;
    }

    public void setGoodname(String goodname) {
        this.goodname = goodname == null ? null : goodname.trim();
    }

    public String getGoodprice() {
        return goodprice;
    }

    public void setGoodprice(String goodprice) {
        this.goodprice = goodprice == null ? null : goodprice.trim();
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public String getTotal() {
        return total;
    }

    public void setTotal(String total) {
        this.total = total == null ? null : total.trim();
    }

    public String getOrderdate() {
        return orderdate;
    }

    public void setOrderdate(String orderdate) {
        this.orderdate = orderdate == null ? null : orderdate.trim();
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username == null ? null : username.trim();
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state == null ? null : state.trim();
    }
}

com.service.impl

ShopService.java

package com.service.impl;

import java.util.List;

import com.entity.TbOrder;

public interface ShopService {
	//查询所有
	List<TbOrder> selectAll();
	// 订单由已下单1变为已发货2
	int update1b2(int id);
	// 订单由已发货2变为已收货3
	int update2b3(int id);
	// 删除订单
	int del(Integer id);
}

ShopServiceImpl.java

package com.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.dao.TbOrderMapper;
import com.entity.TbOrder;
@Service
public class ShopServiceImpl implements ShopService {
	
	@Resource
	TbOrderMapper mapper;
	// 查询所有订单
	@Override
	public List<TbOrder> selectAll() {
		List<TbOrder> listShopp=mapper.selectAll();
		return listShopp;
	}
	// 删除订单
	@Override
	public int del(Integer id) {
		int deleteShoop=mapper.deleteByPrimaryKey(id);
		return deleteShoop;
	}
	// 订单由已下单1变为已发货2
	@Override
	public int update1b2(int id) {
		int updateshopp=mapper.update1b2(id);
		return updateshopp;
	}
	// 订单由已发货2变为已收货3
	@Override
	public int update2b3(int id) {
		int updateshopp1=mapper.update2b3(id);
		return updateshopp1;
	}

}

MyBatis

SqlMapConfig.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
	"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!-- 别名 -->
	<typeAliases>
		<package name="com.entity"/>
	</typeAliases>
</configuration>

spring

applicationContext-dao.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
		xmlns="http://www.springframework.org/schema/beans" 
		xmlns:context="http://www.springframework.org/schema/context" 
		xmlns:aop="http://www.springframework.org/schema/aop" 
		xmlns:tx="http://www.springframework.org/schema/tx" 
		xmlns:mvc="http://www.springframework.org/schema/mvc" 
		xsi:schemaLocation="http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans-4.2.xsd 
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context-4.2.xsd 
		http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop-4.2.xsd 
		http://www.springframework.org/schema/tx 
		http://www.springframework.org/schema/tx/spring-tx-4.2.xsd 
		http://www.springframework.org/schema/mvc 
		http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd ">
		<context:property-placeholder location="classpath:dataSource.properties"/>
		<!-- 数据源配置 -->
		<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
			<property name="driverClassName" value="${db.driverClass}"></property>
			<property name="Url" value="${db.jdbcUrl}"></property>
			<property name="username" value="${db.user}"></property>
			<property name="password" value="${db.password}"></property>
		</bean>
		<!-- 配置SqlSessionFactory -->
		<bean class="org.mybatis.spring.SqlSessionFactoryBean">
			<!-- 设置MyBatis核心配置文件 -->
			<property name="configLocation" value="classpath:MyBatis/SqlMapConfig.xml"></property>
			<!-- 设置数据源 -->
			<property name="dataSource" ref="dataSource"></property>
		</bean>
		<!-- 配置Mapper扫描 -->
		<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
			<!-- 设置Mapper扫描包 -->
			<property name="basePackage" value="com.dao"></property>
		</bean>	
</beans>

applicationContext-service.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
		xmlns="http://www.springframework.org/schema/beans" 
		xmlns:context="http://www.springframework.org/schema/context" 
		xmlns:aop="http://www.springframework.org/schema/aop" 
		xmlns:tx="http://www.springframework.org/schema/tx" 
		xmlns:mvc="http://www.springframework.org/schema/mvc" 
		xsi:schemaLocation="http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans-4.2.xsd 
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context-4.2.xsd 
		http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop-4.2.xsd 
		http://www.springframework.org/schema/tx 
		http://www.springframework.org/schema/tx/spring-tx-4.2.xsd 
		http://www.springframework.org/schema/mvc 
		http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd ">
	
	<!-- 配置Service层扫描 -->
	<context:component-scan base-package="com.service"></context:component-scan>	
	<!-- 配置事务管理层 -->
	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource"></property>
	</bean>
	<!-- 开启注解方式管理AOP事务 -->
	<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>

spring-mvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
		xmlns="http://www.springframework.org/schema/beans" 
		xmlns:context="http://www.springframework.org/schema/context" 
		xmlns:aop="http://www.springframework.org/schema/aop" 
		xmlns:tx="http://www.springframework.org/schema/tx" 
		xmlns:mvc="http://www.springframework.org/schema/mvc" 
		xsi:schemaLocation="http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans-4.2.xsd 
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context-4.2.xsd 
		http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop-4.2.xsd 
		http://www.springframework.org/schema/tx 
		http://www.springframework.org/schema/tx/spring-tx-4.2.xsd 
		http://www.springframework.org/schema/mvc 
		http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd ">
		
	<!-- 配置Controller层扫描包 -->	
		<context:component-scan base-package="com.controller"></context:component-scan>
	<!-- 配置注解驱动 -->
	<mvc:annotation-driven></mvc:annotation-driven>
	<!-- 配置视图解析器 -->
	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
				<property name="prefix" value="/WEB-INF/jsp"></property>
				<property name="suffix" value=".jsp"></property>
	</bean>
</beans>

dataSource.properties

jdbc.url=jdbc:mysql://localhost:3306/shop_db?useUnicode=true&characterEncoding=UTF-8&useSSL=false
jdbc.username=root
jdbc.password=123456
jdbc.driver=com.mysql.jdbc.Driver

WebContent

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>com.ssm.one</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring/applicationContext-*.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:spring/spring-mvc.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
  <filter>
    <filter-name>CharacterEncodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>CharacterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

JSP

index.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
    <%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"
		+request.getServerPort()+path;
%>
<html>
<head>
<meta charset="utf-8">
<title>登录</title>
</head>
<body>
<script type="text/javascript">
	window.location.href="<%=basePath%>/selectAll.do";
</script>
</body>
</html>

shopOrder.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<head>
<meta charset="utf-8">
<title>网上购物系统</title>

<style type="text/css">
		 h2{
			position:relative;
			left:40%;
		}
		table{
	
			text-align: center;
			
		}
		.foot{
			
			margin-right: 100px;
			float: right;
		}
		tr:hover{
		background: #EEEEEE;
	     }
	   a{
		text-decoration: none;
	   }
	  p{
		text-align: right;
	}
	 </style>
</head>
<body>

<h2>订单管理</h2>
 <form action="shooplists.do" method="post">
    <table width="100%" border="1px" cellpadding="3" cellspacing="0">
	 		  <tr style="background-color: #42B983;color:white">
	 		    <th width="80px">订单编号</th>
	 		    <th width="150px">商品名称</th>
	 		    <th width="150px">商品价格</th>
	 		    <th width="150px">购买数量</th>
	 		    <th width="150px">商品总价</th>
	 		    <th width="200px">下单时间</th>
	 		    <th width="150px">下单用户</th>
	 		    <th width="150px">订单状态</th>
	 		    <th width="200px">操作</th>
	 		  </tr>
	 		  <c:forEach var="list" items="${selectAll }" varStatus="item" >
	 		  	<tr>
	 			    <td width="150px">${list.id}</td>
	 			    <td width="150px">${list.goodname}</td>
	 			    <td width="150px">${list.goodprice}</td>
	 			    <td width="150px">${list.count}</td>
	 			    <td width="150px">${list.total}</td>
	 			    <td width="150px">${list.orderdate}</td>
	 			    <td width="150px">${list.username}</td>
	 			    <td width="150px">
	 			    	<c:if test="${list.state==1}">
	 			    		已下单
	 			    	</c:if>
	 			    	<c:if test="${list.state==2}">
	 			    		已发货
	 			    	</c:if>
	 			    	<c:if test="${list.state==3}">
	 			    		已收货
	 			    	</c:if>
	 			    </td>
	 			    <td width="160px">
	 			    
	 			    <c:if test="${list.state==1}">
	 			        <a href="javascript:if(confirm('该订单确定发货吗?'))location='update1b2.do?id=${list.id}'">发货</a>
	 			         &nbsp; &nbsp; &nbsp; &nbsp;
	 			    	<a href="javascript:if(confirm('确实要删除吗?'))location='del.do?id=${list.id}'">删除</a>
	 			    </c:if>
	 			    <c:if test="${list.state==2}">
	 			    	<a href="javascript:if(confirm('确定收货吗?'))location='update2b3.do?id=${list.id}'">确认收货</a>
	 			           &nbsp; &nbsp; &nbsp; &nbsp;
	 			    	 <a href="javascript:if(confirm('确实要删除吗?'))location='del.do?id=${list.id}'">删除</a>
	 			    </c:if>
	 			    <c:if test="${list.state==3}">
	 			    		 <a href="javascript:if(confirm('确实要删除吗?'))location='del.do?id=${list.id}'">删除</a>
	 			    </c:if>
	 			    </td>
	 		 	 </tr>
	 		  </c:forEach>
	 		</table>
</form>
</body>
</html>

原文地址:https://blog.csdn.net/weixin_44893902/article/details/121442083

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


1.pom.xml引入依赖 &lt;dependency&gt; &lt;groupId&gt;com.github.pagehelper&lt;/groupId&gt; &lt;artifactId&gt;pagehelper&lt;/artifactId&gt; &lt;version&gt;5
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt; &lt;!DOCTYPE configuration PUBLIC &quot;-//mybatis.org//DTD Config 3.0//EN&quot; &qu
准备工作 ① 创建数据库&amp;数据表 ## 创建数据库 CREATE DATABASE `dbtest1`; ## 创建数据表 CREATE TABLE `t_user` ( `id` INT NOT NULL AUTO_INCREMENT, `username` VARCHAR(20) DEF
MyBatis逆向工程是指根据数据库表结构自动生成对应的实体类、Mapper接口以及SQL映射文件的过程。这个过程可以通过MyBatis提供的逆向工程工具来完成,极大地方便了开发人员,避免了重复的代码编写,提高了开发效率。 创建逆向工程的步骤 1、添加依赖&amp;插件 &lt;!-- 控制Mave
MyBatis获取参数值的两种方式:${}和#{} ${}的本质就是字符串拼接,#{}的本质就是占位符赋值。 ${}使用字符串拼接的方式拼接sql,若为字符串类型或日期类型的字段进行赋值时,需要手动加单引号;但是#{}使用占位符赋值的方式拼接sql,此时为字符串类型或日期类型的字段进行赋值时,可以自
resultMap作用是处理数据表中字段与java实体类中属性的映射关系。 准备工作 ① 创建数据库&amp;数据表 CREATE DATABASE `dbtest1`; CREATE TABLE `t_emp` ( `emp_id` int NOT NULL AUTO_INCREMENT, `em
EHCache缓存针对于MyBatis的二级缓存。 MyBatis默认二级缓存是SqlSessionFactory级别的。 添加依赖 &lt;!-- MyBatis-EHCache整合包 --&gt; &lt;dependency&gt; &lt;groupId&gt;org.mybatis.cac
MyBatis 提供了一级缓存和二级缓存的支持,用于提高数据库查询的性能,减少不必要的数据库访问。 一级缓存(SqlSession 级别的缓存) 一级缓存是 MyBatis 中最细粒度的缓存,也称为本地缓存。它存在于每个 SqlSession 的生命周期中,当 SqlSession 被关闭或清空时,
动态SQL是 MyBatis 中非常强大且灵活的功能,允许你根据不同的条件构建SQL查询。 这主要通过 &lt;if&gt;、&lt;choose&gt;、&lt;when&gt;、&lt;otherwise&gt;、&lt;foreach&gt;等标签实现。 查询场景 /** * 根据条件查询员工
本教程操作系统:windows10系统、DELL G3电脑。 MyBatis 是一个优秀的持久层框架,它支持定制化 SQL、存储过程以及高级映射。在 MyBatis 中,配置数据库连接是非常重要的第一步。下面将详细介绍如何配置 MyBatis 的
今天小编给大家分享的是MyBatis批量查询、插入、更新、删除如何实现,相信很多人都不太了解,为了让大家更加了解,所以给大家总结了以下内容,一起往下看吧。
今天小编给大家分享的是Mybatis操作多数据源实现的方法,相信很多人都不太了解,为了让大家更加了解,所以给大家总结了以下内容,一起往下看吧。一定会有所收获...
本篇文章和大家了解一下mybatis集成到spring的方式有哪些。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。1 前言1.1 集成spring前使用mybat...
今天小编给大家分享的是mybatis-plus分页查询的3种方法,相信很多人都不太了解,为了让大家更加了解,所以给大家总结了以下内容,一起往下看吧。一定会有所收获...
本篇内容主要讲解“mybatis之BaseTypeHandler怎么使用”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“mybatis...
这篇文章主要介绍了mybatisforeach怎么传两个参数的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇mybatisforeach怎...
这篇“MyBatis映射文件中parameterType与resultType怎么使用”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的...
这篇文章主要介绍“MyBatis怎么获取自动生成的键值”,在日常操作中,相信很多人在MyBatis怎么获取自动生成的键值问题上存在疑惑,小编查阅了各式资料,整理出
这篇文章主要讲解了“怎么去掉IntelliJIDEA中mybatis对应的xml文件警告”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入...
这篇文章主要介绍“MybatisPlus使用@TableId主键id自增长无效如何解决”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这...