基于Spring MVC + Spring + MyBatis的【物流系统 - 公司信息管理】

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

练习点设计:模糊查询、删除、新增

一、语言和环境

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

二、实现功能

使用 SSM(Spring+SpringMVC+MyBatis)框架开发物流系统 - 公司信息管理模块,具体实现如下功能:

1,首页显示所有公司信息,如图 1 所示。

图 1 首页显示所有的公司信息

2,实现按公司名称模糊查询功能:在输入框中输入要查询的公司名称,点击“查找”按钮,显示相关的公司信息。

图2  按公司名称模糊搜索效果

3,实现删除功能,删除之前弹出“删除确认”提示,删除成功后显示最新数据。效果图如图3所示。

图3  删除确认效果图

4,实现增加公司信息的功能:点击首页上的“添加公司信息”,跳转到添加公司信息页面,页面效果如图4所示,完成增加功能,公司编号和公司名称必须输入。

图 2  添加公司信息页面

三、数据库设计

1.创建数据库(logisticsDB)。

2.创建公司信息(tb_company)表,结构见表 1。
表1 公司信息表结构

在这里插入图片描述

四、推荐实现步骤

  1. 建立数据库和数据表,并且添加测试数据(至少添加5条测试数据)。

  2. 打开 Eclipse 或 Idea,创建 Web 工程,并创建相应包。

  3. 为工程添加 Spring、SpringMVC 和 MyBatis 支持。

  4. 在工程中创建实体类和与实体对应的 MyBatis 映射文件,正确配置MySQL 的 SQL 映射文件。

  5. 创建 Mapper映射器、业务类。在 映射器或映射文件中 编写 SQL 语句实现查询和增加操作。

  6. 创建 Controller 类,正确配置 SpringMVC 的配置文件。

  7. 正确配置 Spring 的配置文件,并有效管理 SQLSessionFactory。

五、实现代码

1、mysql代码

1.创建数据库(logisticsDB)。

2.创建公司信息(tb_company)表。

在这里插入图片描述

/*
 Date: 25/07/2021 22:02:55
*/

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for tb_company
-- ----------------------------
DROP TABLE IF EXISTS `tb_company`;
CREATE TABLE `tb_company`  (
  `Company_id` int(11) NOT NULL AUTO_INCREMENT,
  `Company_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `Company_city` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `Company_phone` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `Company_fax` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `Company_adress` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `Company_remark` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`Company_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1006 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of tb_company
-- ----------------------------
INSERT INTO `tb_company` VALUES (1001, '长沙飞马传媒有限公司', '湖南湘潭', '0731-2784651', '0731-2784651', '望城', NULL);
INSERT INTO `tb_company` VALUES (1002, '长沙长奔汽车', '湖南株洲', '0731-2784555', '0731-2784555', '茶陵', NULL);
INSERT INTO `tb_company` VALUES (1003, '湖南汇通科技', '湖南长沙', '0731-2784777', '0731-2784777', '长沙', NULL);
INSERT INTO `tb_company` VALUES (1004, '长沙科技', '湖南长沙', '0731-2784651', '0731-2784651', '湘潭', NULL);

SET FOREIGN_KEY_CHECKS = 1;

2、项目Java代码

目录结构
Company

在这里插入图片描述

JAR包:

在这里插入图片描述

在这里插入图片描述

src

com.controller

CompanyController.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.TbCompany;
import com.service.CompanyService;

@Controller
public class CompanyController {
	@Resource
	CompanyService companyService;

	// 查询与模糊查询
	@RequestMapping("/CompanysList")
	public String CompanysList(Model model, String Company_name) {
		List<TbCompany> companyList = companyService.selectAll(Company_name);
		model.addAttribute("companyList", companyList);
		return "/company";
	}

	// 跳转到添加页面
	@RequestMapping("/insertInto")
	public String insertInto() {
		return "/addCompany";
	}

	// 添加
	@RequestMapping("/insertCompany")
	public String insertCompany(TbCompany tbCompany) {
		int insertCompany = companyService.insertCompany(tbCompany);
		return "redirect:/CompanysList.do";
	}

	// 删除
	@RequestMapping("/delCompany")
	public String delCompany(int companyId) {
		int delCompany = companyService.delCompany(companyId);
		return "redirect:/CompanysList.do";
	}

}

com.dao

TbCompanyMapper.java

package com.dao;

import com.entity.TbCompany;
import java.util.List;

import org.apache.ibatis.annotations.Param;

public interface TbCompanyMapper {
    int deleteByPrimaryKey(Integer companyId);

    int insert(TbCompany record);

    List<TbCompany> selectAll(@Param("Company_name")String Company_name);
 
}

TbCompanyMapper.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.TbCompanyMapper" >
  <resultMap id="BaseResultMap" type="com.entity.TbCompany" >
    <id column="Company_id" property="companyId" jdbcType="INTEGER" />
    <result column="Company_name" property="companyName" jdbcType="VARCHAR" />
    <result column="Company_city" property="companyCity" jdbcType="VARCHAR" />
    <result column="Company_phone" property="companyPhone" jdbcType="VARCHAR" />
    <result column="Company_fax" property="companyFax" jdbcType="VARCHAR" />
    <result column="Company_adress" property="companyAdress" jdbcType="VARCHAR" />
    <result column="Company_remark" property="companyRemark" jdbcType="VARCHAR" />
  </resultMap>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from tb_company
    where Company_id = #{companyId,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.entity.TbCompany" >
    insert into tb_company (Company_id, Company_name, Company_city, 
      Company_phone, Company_fax, Company_adress, 
      Company_remark)
    values (#{companyId,jdbcType=INTEGER}, #{companyName,jdbcType=VARCHAR}, #{companyCity,jdbcType=VARCHAR}, 
      #{companyPhone,jdbcType=VARCHAR}, #{companyFax,jdbcType=VARCHAR}, #{companyAdress,jdbcType=VARCHAR}, 
      #{companyRemark,jdbcType=VARCHAR})
  </insert>

  <select id="selectAll" resultMap="BaseResultMap" >
    select Company_id, Company_name, Company_city, Company_phone, Company_fax, Company_adress, 
    Company_remark
    from tb_company
    <where>
		<if test="Company_name!= null">Company_name like "%"#{Company_name}"%"   </if>
	</where>
  </select>
</mapper>

com.entity

TbCompany.java

package com.entity;

public class TbCompany {
    private Integer companyId;

    private String companyName;

    private String companyCity;

    private String companyPhone;

    private String companyFax;

    private String companyAdress;

    private String companyRemark;

    public Integer getCompanyId() {
        return companyId;
    }

    public void setCompanyId(Integer companyId) {
        this.companyId = companyId;
    }

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName == null ? null : companyName.trim();
    }

    public String getCompanyCity() {
        return companyCity;
    }

    public void setCompanyCity(String companyCity) {
        this.companyCity = companyCity == null ? null : companyCity.trim();
    }

    public String getCompanyPhone() {
        return companyPhone;
    }

    public void setCompanyPhone(String companyPhone) {
        this.companyPhone = companyPhone == null ? null : companyPhone.trim();
    }

    public String getCompanyFax() {
        return companyFax;
    }

    public void setCompanyFax(String companyFax) {
        this.companyFax = companyFax == null ? null : companyFax.trim();
    }

    public String getCompanyAdress() {
        return companyAdress;
    }

    public void setCompanyAdress(String companyAdress) {
        this.companyAdress = companyAdress == null ? null : companyAdress.trim();
    }

    public String getCompanyRemark() {
        return companyRemark;
    }

    public void setCompanyRemark(String companyRemark) {
        this.companyRemark = companyRemark == null ? null : companyRemark.trim();
    }
}

com.service

CompanyService.java

package com.service;

import java.util.List;

import com.entity.TbCompany;

public interface CompanyService {
	
	//查询
	List<TbCompany> selectAll(String Company_name);
	//添加
	int insertCompany(TbCompany tbCompany);
	//删除
	int  delCompany(int companyId);
}

com.serviceImpl

CompanyServiceImpl.java

package com.serviceImpl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.dao.TbCompanyMapper;
import com.entity.TbCompany;
import com.service.CompanyService;
@Service
public class CompanyServiceImpl implements CompanyService {

	@Resource
	TbCompanyMapper mapper;
	@Override
	public List<TbCompany> selectAll(String Company_name) {
		List<TbCompany> selectAll=mapper.selectAll(Company_name);
		return selectAll;
	}

	@Override
	public int insertCompany(TbCompany tbCompany) {
		int insertCompany=mapper.insert(tbCompany);
		return insertCompany;
	}

	@Override
	public int delCompany(int companyId) {
		int delCompany=mapper.deleteByPrimaryKey(companyId);
		return delCompany;
	}

}

mybatis

sqlMapConfig.xml.java

<?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:p="http://www.springframework.org/schema/p" 
	xmlns:context="http://www.springframework.org/schema/context" 
	xmlns:aop="http://www.springframework.org/schema/aop" 
	xmlns:tx="http://www.springframework.org/schema/tx" 
	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.xsd
	http://www.springframework.org/schema/mvc 
		http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd ">
	
	<!-- 指定spring容器读取db.properties文件 -->
	<context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder>
	<!-- 将连接池注册到bean容器中 -->
	<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
		<property name="driverClassName" value="${jdbc.driver}"></property>
		<property name="Url" value="${jdbc.url}"></property>
		<property name="username" value="${jdbc.username}"></property>
		<property name="password" value="${jdbc.password}"></property>
	</bean>
	<!-- 配置SqlSessionFactory -->
	<bean class="org.mybatis.spring.SqlSessionFactoryBean">
		<!-- 设置MyBatis核心配置文件 -->
		<property name="configLocation" value="classpath:mybatis/sqlMapConfig.xml" />
		<!-- 设置数据源 -->
		<property name="dataSource" ref="dataSource" />
	</bean>
	<!-- 配置Mapper扫描 -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<!-- 设置Mapper扫描包 -->
		<property name="basePackage"  value="com.dao" />
	</bean>
	<!-- 配置事务管理器 -->
		<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
			<property name="dataSource" ref="dataSource"></property>
		</bean>
		<!-- 开启注解方式管理AOP事务 -->
		<tx:annotation-driven transaction-manager="transactionManager" />
</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" />
</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" />
		<!-- 配置注解驱动 -->
		<mvc:annotation-driven />
		<!-- 配置视图解析器 -->
		<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
			<!-- 前缀 -->
			<property name="prefix" value="/WEB-INF/jsp/" />
			<!-- 后缀 -->
			<property name="suffix" value=".jsp" />
		</bean>
</beans>

jdbc.properties

jdbc.url=jdbc:mysql://localhost:3306/logisticsdb?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>Company</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>
  <!--spring容器  -->
  <context-param>
  	<param-name>contextConfigLocation</param-name>
  	<param-value>classpath:spring/applicationContext-*.xml</param-value>
  </context-param>
  <!-- 监听器,加载spring配置 -->
  <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>
	<!-- 设置post请求的字符编码过滤器 -->
  <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%>/CompanysList.do";
</script>
</body>
</html>

addCompany.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>添加公司信息</title>
<style type="text/css">
	.centen1 {
		width: 100%;
		height: 40px;
		color: white;
		line-height: 40px;
		background-color: #0098CB;
	}
	
	table {
		margin: auto;
	}
	
	span {
		color: red;
	}
</style>
</head>
<body>
	<div class="centen1">
		<h3>添加公司</h3>
	</div>

	<div class="centen2">
		<form action="insertCompany.do">

			<table border="0" cellspacing="10" cellpadding="6">
				<tr>
					<td>公司编号:&nbsp;&nbsp;&nbsp;&nbsp; <input type="text"
						name="companyId" required>&nbsp;&nbsp;<span>*</span>
					</td>
				</tr>

				<tr>
					<td>公司名称:&nbsp;&nbsp;&nbsp;&nbsp; <input type="text"
						name="companyName" required>&nbsp;&nbsp;<span>*</span>
					</td>
				</tr>

				<tr>
					<td>所在城市:&nbsp;&nbsp;&nbsp;&nbsp; <input type="text"
						name="companyCity">
					</td>
				</tr>
				<tr>
					<td>联系电话:&nbsp;&nbsp;&nbsp;&nbsp; <input type="text"
						name="companyPhone">
					</td>
				</tr>

				<tr>
					<td>传
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;真:&nbsp;&nbsp;&nbsp;&nbsp; <input
						type="text" name="companyFax">
					</td>
				</tr>

				<tr>
					<td>地
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;址:&nbsp;&nbsp;&nbsp;&nbsp; <input
						type="text" name="companyAdress">
					</td>
				</tr>
				<tr>
					<td>备
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注:&nbsp;&nbsp;&nbsp;&nbsp; <input
						type="text" name="companyRemark">
					</td>
				</tr>
				<tr>
					<td>
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input
						type="submit" value="保存" /> <input type="reset" value="重置" />
					</td>
				</tr>
			</table>
		</form>
	</div>
</body>
</html>

company.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<meta charset="utf-8">
<title>物流系统 - 公司信息管理</title>
<style type="text/css">
	.head {
		height: 40px;
		width: 100%;
		background-color: #F8F4FF;
	}
	
	.head1 {
		width: 250px;
		height: 100%;
		float: left;
	}
	
	.head2 {
		width: 450px;
		height: 100%;
		line-height: 36px;
		float: right;
	}
	
	.centen {
		color: white;
		font-size: 20px;
		width: 100%;
		height: 36px;
		background-color: #0098CB;
		margin-top: 20px;
		line-height: 36px;
	}
	
	.foot {
		margin-top: 20px;
	}
	
	table {
		text-align: center;
	}
</style>
</head>
<body>
	<div class="head">
		<div class="head1">
			<a href="insertInto.do">
				<button type="button"
					style="height: 36px; font-size: 20px; background-color: #D9F0FF; border: none;">添加公司信息</button>
			</a>
		</div>
		<div class="head2" style="font-size: 20px; text-align: center;">

			<form action="CompanysList.do" method="post">
				公司名称: <input type="text" placeholder="公司名称" name="Company_name"
					style="height: 26px; font-size: 15px; margin-bottom: 2px;" /> <input
					type="submit" value="查找" style="height: 30px; font-size: 15px;" />
			</form>
		</div>
	</div>
	<div class="centen">
		<h4>公司信息列表</h4>
	</div>
	<div class="foot">
		<table width="100%" border="1px" cellpadding="5" cellspacing="0">
			<tr>
				<th width="150px">公司名称</th>
				<th width="150px">城市</th>
				<th width="150px">电话</th>
				<th width="150px">传真</th>
				<th width="150px">地址</th>
				<th width="150px">操作</th>
			</tr>
			<c:forEach var="company" items="${companyList }" varStatus="item">
				<tr>
					<td width="150px">${company.companyName}</td>
					<td width="150px">${company.companyCity}</td>
					<td width="150px">${company.companyPhone}</td>
					<td width="150px">${company.companyFax}</td>
					<td width="150px">${company.companyAdress}</td>
					<td width="150px"><a
						href="javascript:if(confirm('确实要删除吗?'))location='delCompany.do?companyId=${company.companyId}'">删除</a>
					</td>
				</tr>
			</c:forEach>
		</table>
	</div>
</body>
</html>

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 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自增长无效如何解决”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这...