当前位置: 首页 > news >正文

(0基础保姆教程)-JavaEE开课啦!--11课程(初识Spring MVC + Vue2.0 + Mybatis)-实验9

一、什么是Spring MVC?

        Spring MVC 是一个基于 Java 的 Web 框架,遵循 MVC 设计模式,用于构建企业级应用程序。它通过控制器(Controller)处理用户请求,模型(Model)处理业务逻辑,视图(View)展示数据,实现了请求的分发、数据绑定、视图解析、异常处理等功能,并支持多种视图技术,以提高开发效率和代码的可维护性。

二、Spring MVC有哪些优点呢?

1. 无缝集成:与 Spring 生态系统紧密集成。
2. 灵活性:支持多种配置方式和视图技术。
3. 易于测试:控制器易于进行单元测试。
4. 数据绑定和验证:提供自动数据绑定和验证功能。
5. 拦截器和过滤器:支持拦截器和过滤器以扩展功能。
6. 国际化支持:简化多语言界面的开发。
7. 社区支持:拥有庞大的开发者社区和资源。
8. 可定制性:高度可定制以满足不同项目需求。

三、准备第一个Spring MVC项目

Example:

        编写客户信息(客户名称、客户单位、客户职位、客户生日、客户性别、客户联系方式)注册页面addcustom.jsp。要求:

        1.利用Mybatis框架将客户信息保存到数据库中;

        2.能够利用SpringMVC控制器将页面切换到该注册页面。

流程:

1.创建MySQL数据表customlist

2.创建SpringMvc项目,在pom文件引入相关依赖

3.创建spring-mvc.xml配置文件

4.创建web.xml配置文件

5.创建Entity-Custom客户实体类

6.创建db.properties/mybatis-config.xml配置文件

7.创建Mapper-CustomListMapper配置文件

8.创建applicationContext.xml配置文件

9.引入Vue2.0和Element-ui框架

10.创建Pages-customIndex.jsp和addcustom.jsp前端映射文件

11.创建controller-CustomController文件

12.配置tomcat服务器,运行项目

四、开始上操作

1.创建MySQL数据表customlist

SET NAMES utf8mb4;SET FOREIGN_KEY_CHECKS = 0;-- ------------------------------ Table structure for customlist-- ----------------------------DROP TABLE IF EXISTS `customlist`;CREATE TABLE `customlist`  (`id` int NOT NULL AUTO_INCREMENT,`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,`company` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,`role` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,`birthday` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,`gender` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,`tel` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,PRIMARY KEY (`id`) USING BTREE) ENGINE = InnoDB AUTO_INCREMENT = 11 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin ROW_FORMAT = Dynamic;SET FOREIGN_KEY_CHECKS = 1;

2.创建SpringMvc项目,在pom文件引入相关依赖

项目结构:

 打开IDEA,创建项目-Maven Archetype-名称-位置-JDK-Archetype-创建

点击创建后需要等待较长时间构建项目,完成加载和构建后,会显示以下界面:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.ljl</groupId><artifactId>Spring_MVC_class9</artifactId><packaging>war</packaging><version>1.0-SNAPSHOT</version><name>Spring_MVC_class9 Maven Webapp</name><url>http://maven.apache.org</url><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>3.8.1</version><scope>test</scope></dependency><!--    Spring 基础配置--><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.3.10</version></dependency><!--    SpringMVC工具插件--><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>5.3.10</version></dependency><!--    servlet插件--><dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>3.1.0</version></dependency><dependency><groupId>javax.servlet.jsp</groupId><artifactId>jsp-api</artifactId><version>2.1</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.32</version></dependency><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.5.11</version></dependency><dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter</artifactId><version>RELEASE</version><scope>compile</scope></dependency><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-core</artifactId><version>2.15.4</version></dependency><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId><version>2.15.4</version></dependency></dependencies><build><finalName>Spring_MVC_class9</finalName></build>
</project>

3.创建spring-mvc.xml配置文件

<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/schema/beanshttps://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttps://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/mvchttps://www.springframework.org/schema/mvc/spring-mvc.xsd"><mvc:annotation-driven/><context:component-scan base-package="com.ljl.controller"/><bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" /><bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
<!--    配置视图解释器--><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/pages/"/><property name="suffix" value=".jsp"/></bean>
</beans>

4.创建web.xml配置文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaeehttp://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"version="3.1"><servlet><servlet-name>DispatcherServlet</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:spring-mvc.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>DispatcherServlet</servlet-name><url-pattern>/</url-pattern></servlet-mapping><filter><filter-name>chinese_encoder</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>chinese_encoder</filter-name><url-pattern>/*</url-pattern></filter-mapping>
</web-app>

5.创建Entity-Custom客户实体类

package com.ljl.Entity;public class Custom {private int id;private String name;private String company;private String role;private String birthday;private String gender;private String tel;public Custom() {}public Custom(int id, String name, String company, String role, String birthday, String gender, String tel) {this.id = id;this.name = name;this.company = company;this.role = role;this.birthday = birthday;this.gender = gender;this.tel = tel;}public int getId() {return id;}public void setId(int id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getCompany() {return company;}public void setCompany(String company) {this.company = company;}public String getRole() {return role;}public void setRole(String role) {this.role = role;}public String getBirthday() {return birthday;}public void setBirthday(String birthday) {this.birthday = birthday;}public String getGender() {return gender;}public void setGender(String gender) {this.gender = gender;}public String getTel() {return tel;}public void setTel(String tel) {this.tel = tel;}@Overridepublic String toString() {return "Custom{" +"id=" + id +", name='" + name + '\'' +", company='" + company + '\'' +", role='" + role + '\'' +", birthday='" + birthday + '\'' +", gender='" + gender + '\'' +", tel='" + tel + '\'' +'}';}
}

6.创建db.properties/mybatis-config.xml配置文件

mysql.driver=com.mysql.cj.jdbc.Driver
mysql.url=jdbc:mysql://localhost:3306/class9_springmvc?serverTimezone=UTC&\characterEncoding=utf-8&useUnicode=true&useSSl=false
mysql.username=root
mysql.password=pjl2003
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration><properties resource="db.properties"/>
<!--    设置实体别名--><typeAliases><package name="com.ljl.Entity"/></typeAliases><!-- 和spring整合后 environments配置将废除--><environments default="development"><environment id="development"><!-- 使用jdbc事务管理--><transactionManager type="JDBC" /><!-- 数据库连接池--><dataSource type="POOLED"><property name="driver" value="${mysql.driver}" /><property name="url" value="${mysql.url}" />
<!--                //数据库账号--><property name="username" value="${mysql.username}" />
<!--                //数据库密码--><property name="password" value="${mysql.password}" /></dataSource></environment></environments><!--声明类对应的sql操作文件--><mappers><mapper class="com.ljl.Mapper.CustomListMapper"/></mappers>
</configuration>

7.创建Mapper-CustomListMapper配置文件

package com.ljl.Mapper;import com.ljl.Entity.Custom;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;import java.util.List;public interface CustomListMapper {//TODO 增加客户信息@Insert("INSERT INTO customlist (name, company, role, birthday, gender, tel) values (#{name}, #{company}, #{role}, #{birthday}, #{gender}, #{tel})")int insertCustom(Custom custom);//TODO 查询客户信息-全部@Select("SELECT * FROM customlist")List<Custom> getAllCustomList();//TODO 查询订单信息-根据客户名称模糊查询@Select("SELECT * FROM customlist WHERE name LIKE CONCAT('%', #{name}, '%')")List<Custom> getOrderListByLikeCustomName(String name);//TODO 查询订单信息-根据客户名称详细查询@Select("SELECT * FROM customlist WHERE name = #{name}")List<Custom> getOrderListByCustomName(String name);
}

8.创建applicationContext.xml配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd"><!--    自动装配Bean--><context:component-scan base-package="com.ljl.controller"/>
</beans>

9.引入Vue2.0和Element-ui框架

<!-- import CSS -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css"><!-- import Vue before Element -->
<script src="https://unpkg.com/vue@2/dist/vue.js"></script>
<!-- import JavaScript -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>

10.创建index.jsp \ Pages-customIndex.jsp和addcustom.jsp前端映射文件

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head><title>CustomWelcome</title><!-- import CSS --><link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>
<body>
<div id="index" class="big_box"><H1 class="tittle">欢迎使用{{ sys_name }}客户管理系统</H1><el-row><el-button type="primary" round style="width: 14%" @click="gosystem">开始使用</el-button></el-row>
</div></body>
<!-- import Vue before Element -->
<script src="https://unpkg.com/vue@2/dist/vue.js"></script>
<!-- import JavaScript -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>new Vue({el: '#index',data: function() {return {sys_name:"岚精灵"}},methods: {gosystem(){this.$message.success("欢迎使用岚精灵员工系统!");// 跳转到指定的URL// 设置延迟1秒后跳转setTimeout(() => {window.location.href = 'http://localhost:8090/Spring_MVC_class9_war_exploded/customIndex';}, 1000); // 1000毫秒等于1秒}}})
</script>
<style>*{margin: 0;padding: 0;}body {background-color: rebeccapurple;}.big_box{width: 100%;text-align: center;margin: 0 auto;}.tittle{margin-top: 250px;font-size: 55px;color: beige;margin-bottom: 170px;}
</style>
</html>
<%--Created by IntelliJ IDEA.User: 26520Date: 2024/11/21Time: 13:40To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head><title>customSystem</title><!-- import CSS --><link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>
<body>
<div id="cindex" class="cindex">
<%--    搜索框--%><div style="margin-bottom: 40px;">
<%--        这里的键盘事件,由于使用了Element-ui,需要加上.native进行限制,因为在Element-ui中对active进行了封装,需要加上native进行限制--%><el-input placeholder="请输入客户名称" v-model="search" class="input-with-select" @keyup.enter.native="search_ks"><el-select v-model="select" slot="prepend" placeholder="请选择"><el-option label="模糊查询" value="1"></el-option><el-option label="准确查询" value="2"></el-option></el-select><el-button @click="search_ks" slot="append" icon="el-icon-search"  @keyup.enter.native="search_ks"></el-button></el-input></div>
<%--    内容展示框--%><el-table height="550" :data="tableData" style="width: 100%; text-align: center" :row-class-name="tableRowClassName"><el-table-columnprop="id"label="id"></el-table-column><el-table-columnprop="name"label="客户名称"></el-table-column><el-table-columnprop="company"label="客户单位"></el-table-column><el-table-columnprop="role"label="客户职位"></el-table-column><el-table-columnprop="birthday"label="客户生日"></el-table-column><el-table-columnprop="gender"label="客户性别"></el-table-column><el-table-columnprop="tel"label="联系方式"></el-table-column></el-table><div class="dibu_button"><el-row style="display: inline-block"><el-button type="primary" plain @click="addcustom">添加客户</el-button></el-row><el-row style="display: inline-block; margin-left: 30px"><el-button type="info" plain @click="go_out">退出系统</el-button></el-row></div></div></body>
<!-- import Vue before Element -->
<script src="https://unpkg.com/vue@2/dist/vue.js"></script>
<!-- import JavaScript -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>new Vue({el: '#cindex',data: function() {return {search: '',// 这里默认情况下是模糊查询select: '1',tableData: []}},methods: {handleEdit(index, row) {console.log(index, row);},handleDelete(index, row) {console.log(index, row);},tableRowClassName({row, rowIndex}) {if (rowIndex === 1) {return 'warning-row';} else if (rowIndex === 3) {return 'success-row';}return '';},addcustom(){this.$message.warning("加载中!");// 跳转到指定的URLsetTimeout(() => {window.location.href = 'http://localhost:8090/Spring_MVC_class9_war_exploded/goaddcustom';}, 300);},fetchData() {fetch('http://localhost:8090/Spring_MVC_class9_war_exploded/selectAllCustomList', {headers: {'Accept': 'application/json'}}).then(response => {if (!response.ok) {throw new Error('Network response was not ok ' + response.statusText);}return response.json();}).then(data => {this.tableData = data;}).catch(error => {console.error('There has been a problem with your fetch operation:', error);});},search_ks(){// 实现点击查询功能,先判断是模糊查询还是准确查询,查询出来的数据保存在tableData[]中//模糊查询if (this.search === ""){this.$message.error("请输入需要查询的客户姓名!")}else {if (this.select === "1"){fetch('http://localhost:8090/Spring_MVC_class9_war_exploded/selectCustomLikeName?CustomName=' + this.search, {method: 'POST', // 设置请求方法为 POSTheaders: {'Accept': 'application/json'}}).then(response => {if (!response.ok) {throw new Error('Network response was not ok ' + response.statusText);}return response.json();}).then(data => {this.$message.success("查询成功!")this.tableData = data;}).catch(error => {console.error('There has been a problem with your fetch operation:', error);});}else if (this.select === "2") {fetch('http://localhost:8090/Spring_MVC_class9_war_exploded/selectCustomByName?CustomName=' + this.search, {method: 'POST', // 设置请求方法为 POSTheaders: {'Accept': 'application/json'}}).then(response => {if (!response.ok) {throw new Error('Network response was not ok ' + response.statusText);}return response.json();}).then(data => {this.$message.success("查询成功!")this.tableData = data;}).catch(error => {console.error('There has been a problem with your fetch operation:', error);});}}},go_out(){this.$message.success("退出成功!")setTimeout(() => {window.location.href = 'http://localhost:8090/Spring_MVC_class9_war_exploded/';}, 300);}},created() {this.fetchData(); // 当组件创建后调用 fetchData 方法},})
</script>
<style>*{margin: 0;padding: 0;}body {background-color: #eaddf6;}.cindex{width: 70%;padding-top: 100px;text-align: center;margin: 0 auto;}.el-select .el-input {width: 130px;}.input-with-select .el-input-group__prepend {background-color: #fff;}.el-table .warning-row {background: oldlace;}.el-table .success-row {background: #f0f9eb;}.dibu_button{width: 100%;margin: 0 auto;margin-top: 30px;text-align: center;}
</style>
</html>
<%--Created by IntelliJ IDEA.User: 26520Date: 2024/11/21Time: 13:40To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head><title>customSystem</title><!-- import CSS --><link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>
<body>
<div id="addcustom" class="big"><div class="from"><h1 style="text-align: center;color: #9438ec;font-size: 35px;margin-bottom: 40px;margin-top: 40px">添加客户</h1><el-form ref="form" :model="form" :label-position="right" label-width="80px" action=""><el-form-item label="姓名"><el-input v-model="form.name"></el-input></el-form-item><el-form-item label="单位"><el-input v-model="form.company"></el-input></el-form-item><el-form-item label="职位"><el-input v-model="form.role"></el-input></el-form-item><el-form-item label="生日"><el-date-pickerv-model="form.birthday"type="date"style="width: 100%"placeholder="选择日期"></el-date-picker></el-form-item><el-form-item label="性别"><el-select style="width: 100%" v-model="form.gender" placeholder="请选择"><el-optionv-for="item in genderchange":key="item.value":label="item.label":value="item.value"></el-option></el-select></el-form-item><el-form-item label="电话"><el-input v-model="form.tel"></el-input></el-form-item><el-button type="primary" @click="add">立即创建</el-button><el-button type="danger" @click="back" style="margin-bottom: 40px">立即返回</el-button></el-form></div></div></body>
<!-- import Vue before Element -->
<script src="https://unpkg.com/vue@2/dist/vue.js"></script>
<!-- import JavaScript -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>new Vue({el: '#addcustom',data: function() {return {form: {name: '',company:"",role:"",birthday:"",gender:"",tel:""},pickerOptions: {disabledDate(time) {return time.getTime() > Date.now();},},genderchange: [{value: '男',label: '男'}, {value: '女',label: '女'}, {value: '其他',label: '其他'}],}},methods: {checkForm() {let allFilled = true;for (let key in this.form) {if (!this.form[key] && this.form[key] !== 0) { // 假设0是一个有效的值allFilled = false;break;}}return allFilled;},add(){if (!this.checkForm()) {this.$message.error("请填写所有必填字段");return;}// 格式化生日日期为 yyyy-mm-ddthis.form.birthday = this.form.birthday ? this.form.birthday.toISOString().split('T')[0] : '';// 创建URLSearchParams对象并添加数据const params = new URLSearchParams();params.append('name', this.form.name);params.append('company', this.form.company);params.append('role', this.form.role);params.append('birthday', this.form.birthday);params.append('gender', this.form.gender);params.append('tel', this.form.tel);// 发送POST请求fetch('http://localhost:8090/Spring_MVC_class9_war_exploded/addcustom', {method: 'POST',headers: {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'},body: params // URLSearchParams对象会自动转换为URL编码的字符串}).then(response => {if (response.ok) {return response.text(); // 或者 response.json() 如果响应是JSON格式}throw new Error('Network response was not ok.');}).then(data => {console.log(data);this.$message.success("数据添加成功!");setTimeout(() => {window.location.href = 'http://localhost:8090/Spring_MVC_class9_war_exploded/';}, 300); // 1000毫秒等于1秒}).catch(error => {console.error('Error:', error);this.$message.error("数据添加失败!");});},back(){this.$message.warning("请稍等!");// 跳转到指定的URL// 设置延迟1秒后跳转setTimeout(() => {window.location.href = 'http://localhost:8090/Spring_MVC_class9_war_exploded/customIndex';}, 300); // 1000毫秒等于1秒}}})
</script>
<style>*{margin: 0;padding: 0;}.big{width: 70%;padding-top: 100px;text-align: center;margin: 0 auto;}.from{width: 40%;padding-right: 40px;text-align: center;margin: 0 auto;border: 1px solid grey;border-radius: 8px;}
</style>
</html>

11.创建controller-CustomController文件

package com.ljl.controller;import com.fasterxml.jackson.core.JsonProcessingException;
import com.ljl.Entity.Custom;
import com.ljl.Mapper.CustomListMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;@Controller
@CrossOrigin(origins = "*")
public class CustomController {//主页@RequestMapping("/customIndex")public String customIndex() {return "customIndex";}//添加客户界面@RequestMapping("/goaddcustom")public String goaddcustom() {return "addcustom";}//添加客户到sql,再返回到主页@RequestMapping("/addcustom")public String addcustom(Custom custom) {if (custom.getName() != null) {SqlSessionFactory ssf = null;try {InputStream input = Resources.getResourceAsStream("mybatis-config.xml");ssf = new SqlSessionFactoryBuilder().build(input);} catch (IOException e) {e.printStackTrace();}SqlSession sqlSession = ssf.openSession();CustomListMapper customListMapper = sqlSession.getMapper(CustomListMapper.class);int result_code = customListMapper.insertCustom(custom);sqlSession.commit();if (result_code == 1) {System.out.println("新增客户成功!");}else {System.out.println("新增客户失败!");}}return "customIndex";}//获取全部客户信息@GetMapping(value = "selectAllCustomList", produces = "application/json")@ResponseBodypublic List<Custom> selectAllCustomList() {SqlSessionFactory ssf = null;try {InputStream input = Resources.getResourceAsStream("mybatis-config.xml");ssf = new SqlSessionFactoryBuilder().build(input);} catch (IOException e) {e.printStackTrace();}SqlSession sqlSession = ssf.openSession();CustomListMapper customListMapper = sqlSession.getMapper(CustomListMapper.class);List<Custom> custom = customListMapper.getAllCustomList();System.out.println("系统正在获取所有客户信息");return custom;}//模糊查询客户信息-根据name模糊查询@PostMapping(value = "selectCustomLikeName", produces = "application/json")@ResponseBodypublic List<Custom> selectCustomLikeName(HttpServletRequest request){SqlSessionFactory ssf = null;try {InputStream input = Resources.getResourceAsStream("mybatis-config.xml");ssf = new SqlSessionFactoryBuilder().build(input);} catch (IOException e) {e.printStackTrace();}SqlSession sqlSession = ssf.openSession();CustomListMapper customListMapper = sqlSession.getMapper(CustomListMapper.class);List<Custom> custom = customListMapper.getOrderListByLikeCustomName(request.getParameter("CustomName"));System.out.println("用户正在进行模糊查询");return custom;}//准确查询客户信息-根据name准确查询@PostMapping(value = "selectCustomByName", produces = "application/json")@ResponseBodypublic List<Custom> selectCustomByName(HttpServletRequest request){SqlSessionFactory ssf = null;try {InputStream input = Resources.getResourceAsStream("mybatis-config.xml");ssf = new SqlSessionFactoryBuilder().build(input);} catch (IOException e) {e.printStackTrace();}SqlSession sqlSession = ssf.openSession();CustomListMapper customListMapper = sqlSession.getMapper(CustomListMapper.class);List<Custom> custom = customListMapper.getOrderListByCustomName(request.getParameter("CustomName"));System.out.println("用户正在进行精确查询");return custom;}
}

12.配置tomcat服务器,运行项目

五、运行看效果

1.初始加载页面

2.进入系统主界面

3.模糊查询

4.精确查询

5.注册界面

6.注册成功返回主界面

相关文章:

(0基础保姆教程)-JavaEE开课啦!--11课程(初识Spring MVC + Vue2.0 + Mybatis)-实验9

一、什么是Spring MVC&#xff1f; Spring MVC 是一个基于 Java 的 Web 框架&#xff0c;遵循 MVC 设计模式&#xff0c;用于构建企业级应用程序。它通过控制器(Controller)处理用户请求&#xff0c;模型(Model)处理业务逻辑&#xff0c;视图(View)展示数据&#xff0c;实现了请…...

九、Spring Boot集成Spring Security之授权概述

文章目录 往期回顾&#xff1a;Spring Boot集成Spring Security专栏及各章节快捷入口前言一、授权概述二、用户权限三、用户授权流程三、Spring Security授权方式1、请求级别授权2、方法级别授权 往期回顾&#xff1a;Spring Boot集成Spring Security专栏及各章节快捷入口 Spr…...

QT:多ui界面显示

文章目录 1.多ui界面添加2.跳转函数3.返回函数4.Qt5源码工程5.模态显示 1.多ui界面添加 最终生成这个目录 2.跳转函数 void MainWindow::on_pushButton_clicked() {//this->setWindowModality(Qt::WindowModal);test1 *t1 new test1();t1->setParentData(this);this-…...

人工智能在医疗领域应用的案例参考

以下是一些人工智能在医疗领域应用的具体案例&#xff1a; 疾病诊断辅助 谷歌旗下DeepMind与伦敦大学学院医院合作 案例详情&#xff1a;利用人工智能系统对眼部疾病进行诊断&#xff0c;分析眼部扫描图像&#xff0c;快速准确地检测出眼部疾病的早期迹象&#xff0c;如青光眼…...

vue3 与 spring-boot 完成跨域访问

spring-boot&#xff0c;写一个接口用于前端访问&#xff0c;并且给接口设置跨域访问&#xff0c;这里我前端的域名为 localhost:5173 RestController CrossOrigin(origins "http://localhost:5173") public class Vue3Controller {GetMapping("/vue")pu…...

CSS clamp() 函数:构建更智能的响应式设计

在响应式设计中&#xff0c;我们经常需要处理元素大小的动态变化。CSS clamp() 函数提供了一个优雅的解决方案&#xff0c;让我们的设计更加灵活和智能。 clamp() 函数是什么&#xff1f; clamp() 函数接受三个参数&#xff1a; clamp(最小值, 首选值, 最大值)这三个参数分别…...

【C++笔记】数据结构进阶之二叉搜索树(BSTree)

【C笔记】数据结构进阶之二叉搜索树(BSTree) &#x1f525;个人主页&#xff1a;大白的编程日记 &#x1f525;专栏&#xff1a;C笔记 文章目录 【C笔记】数据结构进阶之二叉搜索树(BSTree)前言一.二叉搜索树的概念二.二叉搜索树的性能分析三.二叉搜索树的实现3.1二叉树的中序…...

c++设计模式模块与系统

c 中lambda 本质就是一个匿名(没有名)的函数&#xff1b; 可以用一个数组元素存储一个函数的指针&#xff1b; 通过数组下标来使用函数&#xff1b; 高内聚低耦合 如何理解设计模式中的高内聚低耦合 高内聚: 用于指导如何组织和划分软件设计。 **定义&#xff1a;**高内聚指的…...

【81-90期】Java核心面试问题深度解析:性能优化与高并发设计

&#x1f680; 作者 &#xff1a;“码上有前” &#x1f680; 文章简介 &#xff1a;Java &#x1f680; 欢迎小伙伴们 点赞&#x1f44d;、收藏⭐、留言&#x1f4ac; 文章题目&#xff1a;Java核心面试问题深度解析&#xff1a;性能优化与高并发设计 摘要&#xff1a; 本文聚…...

python实现TCP服务端,支持对所有客户端的数据收发,支持终端自定义命令操作,提供clear命令一键断开所有的客户端连接

前言 python实现TCP服务端&#xff0c;支持对所有客户端的数据收发&#xff0c;支持终端自定义命令操作&#xff0c;提供clear命令一键断开所有的客户端连接 简单易懂&#xff0c;直接上码 源码 import socket import threadingclass TCPServer:# 修改此处ip 端口def __ini…...

【R安装】R语言的详细安装及环境配置(2024年11月)

目录 R及Rstudio下载R下载Rstudio下载 R及Rstudio安装R安装Rtools 安装Rstudio安装 运行 RStudio通过RStudio配置使用特定的R版本 参考 R及Rstudio下载 R下载 R官网-The R Project for Statistical Computing 点击【download R】&#xff0c;进入下载界面&#xff1a; 选择…...

Android 12.0 通知--PendingIntent基本代码

一. PendingIntent 在 Android 通知中的使用场景 使用场景: Android 通知的 setContentIntent() 需要传入 PendingIntent , 即当点击通知时,执行 intent 的动作.如下例子: //1.创建Intent对象Intent intent new Intent(this, MainActivity1.class); //2.获取能启动 Activity 的…...

网络安全在数字时代保护库存数据中的作用

如今&#xff0c;通过软件管理库存已成为一种标准做法。企业使用数字工具来跟踪库存水平、管理供应链和规划财务。 然而&#xff0c;技术的便利性也带来了网络威胁的风险。黑客将库存数据视为有价值的目标。保护这些数据不仅重要&#xff0c;而且必不可少。 了解网络安全及其…...

文本搜索程序(Qt)

头文件 #ifndef TEXTFINDER_H #define TEXTFINDER_H#include <QWidget> #include <QFileDialog> #include <QFile> #include <QTextEdit> #include <QLineEdit> #include <QTextStream> #include <QPushButton> #include <QMess…...

云原生革命:构建未来应用的无限可能

在这个数字化飞速发展的时代&#xff0c;云原生技术如同一股不可阻挡的潮流&#xff0c;正深刻改变着软件开发和部署的方式。它不仅仅是一种技术变革&#xff0c;更是一场关于如何更高效、更灵活地构建和运行应用的革命。今天&#xff0c;我们就来深入探讨云原生的魅力所在&…...

【Ubuntu 24.04】How to Install and Use NVM

参考 下载 curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash激活 Activate NVM: Once the installation script completes, you need to either close and reopen the terminal or run the following command to use nvm immediately. exp…...

android12锁屏界面pin码或者图案解锁居中显示

设置pin码或者图案锁屏后&#xff0c;在锁屏界面向上划左边&#xff0c;图案解锁就在左边&#xff0c; 向上划右边图案就在右边&#xff0c;如何设置一直居中显示呢&#xff1f; diff --git a/packages/SystemUI/res/layout/super_notification_shade.xml b/packages/SystemUI…...

【VUE3】新版Vue3+ElementPlus全家桶开发视频项目实战

VUE 介绍 Vue (发音为 /vjuː/,类似 view) 是一款用于构建用户界面的 JavaScript 框架。它基于标准 HTML、CSS 和 JavaScript 构建,并提供了一套声明式的、组件化的编程模型,帮助你高效地开发用户界面。 Vue.js是一个MVVM(Model - View - ViewModel)的SPA框架。 Model:数…...

【UE5 C++课程系列笔记】05——组件和碰撞

效果 可以看到我们可以实现的功能是 &#xff08;1&#xff09;可以通过鼠标旋转视角 &#xff08;2&#xff09;通过使用Pawn移动组件来控制Pawn移动 &#xff08;3&#xff09;Pawn碰到物体会被阻挡然后逐渐滑动 &#xff08;4&#xff09;通过空格切换激活/关闭粒子效果…...

【docker 拉取镜像超时问题】

问题描述 在centosStream8上安装docker&#xff0c;使用命令sudo docker run hello-world 后出现以下错误&#xff1a; Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: request canceled while waiting for connection (Client.Ti…...

51-基于单片机的智能语音识别与处理系统设计

目录 一、主要功能 二、硬件资源 三、程序编程 四、实现现象 一、主要功能 基于51单片机&#xff0c;搞L298N驱动两个电机转动&#xff0c;然后搞LCD1602显示屏&#xff0c;弄个超声波传感器实时检测距离 通过LCD1602显示距离&#xff0c;如果距离小于阈值&#xff0c;则两…...

民安:助力提升城市安全水平

随着城市化进程的加速&#xff0c;平安城市的创建成为了社会治理的重要议题。为了解公众对平安城市创建的看法和评价&#xff0c;为提升城市安全水平提供参考&#xff0c;近期某市委托民安智库专业市场调查公司开展了一次安全感满意度调查。 本次调查围绕公共安全、个人安全、…...

类和对象--中--运算符重载、日期类实现(重要)

目录 1.运算符重载 2.日期类 1.运算符重载 2.1作用&#xff1a; 为了让C的新类型&#xff1a;类。也可以进行内置类型的运算符操作。所以就有了运算符重载。 2.2定义&#xff1a; 运算符重载是具有特殊名字的函数&#xff0c;他的名字是由operator和后⾯要定义的运算符共…...

个人回顾。

一鸡摸塔塔开! 2024/11/24 18:20:42 2019.6毕业。入职hg。到2020.6。入职一年。居住侨源山庄极小房间。月租一千。 一鸡摸塔塔开! 2024/11/24 18:21:15 期间也有保持学习。也玩游戏看小说。把大学缺失的补回来。 一鸡摸塔塔开! 2024/11/24 18:30:33 博客园随笔 学习笔记 100…...

前端面试题-1(详解事件循环)

1.了解浏览器的进程模型 1.什么是进程&#xff1f; 程序运行需要有它自己专属的内存空间&#xff0c;可以把这块内存空间简单的理解为进程 每个应用至少有一个进程&#xff0c;进程之间相互独立&#xff0c;即使要通信&#xff0c;也需要双方同意。 2.什么是线程&#xff1f…...

http的文件上传和下载原理

目录 一&#xff1a;上传 1&#xff1a;http请求格式 2&#xff1a;文件上传类型分析 1&#xff1a;md5秒传 2&#xff1a;分片上传 1. 什么是分片上传 2. 分片上传的场景 3&#xff1a;断点续传 1. 什么是断点续传 2. 应用场景 3. 实现断点续传的核心逻辑 4. 实现流…...

leetcode 212. 单词搜索 II

给定一个 m x n 二维字符网格 board 和一个单词&#xff08;字符串&#xff09;列表 words&#xff0c; 返回所有二维网格上的单词 。 单词必须按照字母顺序&#xff0c;通过 相邻的单元格 内的字母构成&#xff0c;其中“相邻”单元格是那些水平相邻或垂直相邻的单元格。同一…...

1、数据结构概述及顺序表(附:可以直接打印显示的源码)

《数据结构》概述&#xff1a; 数据结构&#xff1a;数据元素之间的关系&#xff08;逻辑关系&#xff09; 数据类型&#xff1a;高地电平 表示 1/0 要做大量的运算&#xff1a;诞生了基本数据类型&#xff1a;int double .....--》反应了数据的取值范围 &#xff08;int字…...

Redis

概述 Redis&#xff08;全称 REmote DIctionary Server&#xff09;是一个开源的内存数据存储系统&#xff0c;它被广泛应用于缓存、消息队列、实时数据存储等场景。Redis 是一个基于内存的数据结构存储&#xff0c;可以作为数据库、缓存和消息中间件使用 优点 高性能&#xf…...

Android 13 编译Android Studio版本的Launcher3

Android 13 Aosp源码 源码版本Android Studio版本Launcher3QuickStepLib (主要代码) Launcher3ResLib(主要资源)Launcher3IconLoaderLib(图...

【高等数学学习记录】微分中值定理

一、知识点 &#xff08;一&#xff09;罗尔定理 费马引理 设函数 f ( x ) f(x) f(x) 在点 x 0 x_0 x0​ 的某邻域 U ( x 0 ) U(x_0) U(x0​) 内有定义&#xff0c;并且在 x 0 x_0 x0​ 处可导&#xff0c;如果对任意的 x ∈ U ( x 0 ) x\in U(x_0) x∈U(x0​) &#xff0…...

百度 文心一言 vs 阿里 通义千问 哪个好?

背景介绍&#xff1a; 在当前的人工智能领域&#xff0c;随着大模型技术的快速发展&#xff0c;市场上涌现出了众多的大规模语言模型。然而&#xff0c;由于缺乏统一且权威的评估标准&#xff0c;很多关于这些模型能力的文章往往基于主观测试或自行设定的排行榜来评价模型性能…...

wordpress使用Markdown语法写的文章图片显示不正常,记录一次折腾之旅

wordpress使用Markdown语法写的文章图片显示不正常,记录一次折腾之旅 当我把wordpress站点地址改成域名之后,wordpress上写的文章是使用Markdown语法进行写作的,但是Markdown引用的图片就会加载不出来,但如果把站点地址改成局域网的IP,所有的一切都显示正常了。除非我把图…...

MTK 展锐 高通 sensorhub架构

一、MTK平台 MTK框架可以分为两部分&#xff0c;AP和SCP。 AP是主芯片&#xff0c;SCP是协处理器&#xff0c;他们一起工作来处理sensor数据。 SCP 是用来处理sensor和audio相关功能和其他客制化需求的一个协处理理器&#xff0c;MTK SCP选择freeRTOS作为操作系统&#xff0c…...

npm 最新国内淘宝镜像地址源 (旧版已不能用)

注意&#xff1a;原域名https://registry.npm.taobao.org/ 在 2022.06.30 号正式下线和停止 DNS 解析 最新地址&#xff1a; #最新地址 淘宝 NPM 镜像站喊你切换新域名啦! npm config set registry https://registry.npmmirror.com 查看镜像使用状态 npm config get registr…...

(超详细图文详情)Navicat 配置连接 Oracle

1、下载依赖文件 Oracle官网下载直链&#xff1a;https://www.oracle.com/database/technologies/instant-client/winx64-64-downloads.html 夸克网盘下载&#xff08;oracle19c版本&#xff09;&#xff1a;https://pan.quark.cn/s/5061e690debc 官网下载选择对应 Oracle 版…...

iOS 系统中使用 webView 打印 html 的打印边距问题

需求是使用系统提供的打印功能将HTML代码打印出来 1、使用CSS page 设置边距&#xff08;iOS不生效&#xff09; page {margin: 0;padding: 0;size: A6 portrait; }在 Android 中边距设置生效的&#xff0c;但是在 iOS 系统使用CSS page规则是不生效的 当从 iOS 系统打印网页…...

深度学习Pytorch中的模型保存与加载方法

深度学习:Pytorch中的模型保存与加载方法 在 PyTorch 中&#xff0c;模型的保存和加载对于模型的持久化和后续应用至关重要。这里详细介绍了两种主要方法&#xff1a;保存整个模型&#xff08;包括架构和参数&#xff09;和仅保存模型的状态字典。以下内容进一步完善了加载模型…...

(vue)启动项目报错The project seems to require pnpm but it‘s not installed

(vue)启动项目报错The project seems to require pnpm but it’s not installed 原因 该错误信息表明你的项目需要使用 pnpm 作为包管理工具&#xff0c;但系统中尚未安装 pnpm。 解决方法 【1】删除pnpm.lock 【2】npm install -g pnpm 之后再重新启动 yarn报错&#xff0…...

【Leetcode 每日一题】3250. 单调数组对的数目 I

问题背景 给你一个长度为 n n n 的 正 整数数组 n u m s nums nums。 如果两个 非负 整数数组 ( a r r 1 , a r r 2 ) (arr_1, arr_2) (arr1​,arr2​) 满足以下条件&#xff0c;我们称它们是 单调 数组对&#xff1a; 两个数组的长度都是 n n n。 a r r 1 arr_1 arr1​ 是…...

C++语法·叭

阁下何不乘风起&#xff0c;扶摇直上九万里。 qi fei 目录 内存管理 分区介绍 1.栈区&#xff1a; 2.内存映射段&#xff1a; 3.堆&#xff1a; 4.数据段&#xff1a; 5.代码段&#xff1a; 补充&#xff1a; C内存管理&#xff08;简略回忆&#xff09; C内存…...

ComfyUI | ComfyUI桌面版发布,支持winmac多平台体验,汉化共享等技巧!(内附安装包)

ComfyUI 桌面版正式推出&#xff0c;支持 Windows 与 macOS 等多平台&#xff0c;为 AI 绘画爱好者带来全新体验。其安装包便捷易用&#xff0c;开启了轻松上手之旅。汉化共享功能更是一大亮点&#xff0c;打破语言障碍&#xff0c;促进知识交流与传播。在操作上&#xff0c;它…...

探索Python词云库WordCloud的奥秘

文章目录 探索Python词云库WordCloud的奥秘1. 背景介绍&#xff1a;为何选择WordCloud&#xff1f;2. WordCloud库简介3. 安装WordCloud库4. 简单函数使用方法5. 应用场景示例6. 常见Bug及解决方案7. 总结 探索Python词云库WordCloud的奥秘 1. 背景介绍&#xff1a;为何选择Wo…...

用PHP抓取HTTPS资源时的常见问题与解决方法

概述 随着互联网的发展&#xff0c;HTTPS已经成为主流协议&#xff0c;网站的数据安全性得到了显著提升。然而&#xff0c;对于开发者来说&#xff0c;HTTPS的广泛应用也增加了数据抓取的复杂性。尤其是在PHP中实现HTTPS资源的抓取时&#xff0c;开发者可能会遇到以下问题&…...

spring知识点复习--针对面试的

前言 此内容是笔者通过B站的视频总结而来。原视频链接地址&#xff1a;6、Bean Factory与FactoryBean有什么区别_哔哩哔哩_bilibili 1.谈谈springIOC的理解&#xff0c;原理与实现 回答涉及到的点&#xff1a; 控制反转&#xff1a;是一种理论思想&#xff0c;原来的对象是由…...

Web前端学习_CSS盒子模型

content padding border margin <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><title>CSS盒子模型</title><style></style> </head> <body> <div class"demo&quo…...

ajax基础

一&#xff1a;express框架 在终端输入nodejs文件名 // 引入express const express require(express); //创建应用对象 const app express(); //创建路由规则 app.get(/,(request,response) > {//设置响应response.send(Hello Express); }); // 监听3000端口 app.lis…...

Python轴承故障诊断 (21)基于VMD-CNN-BiTCN的创新诊断模型

往期精彩内容&#xff1a; Python-凯斯西储大学&#xff08;CWRU&#xff09;轴承数据解读与分类处理 Pytorch-LSTM轴承故障一维信号分类(一)-CSDN博客 Pytorch-CNN轴承故障一维信号分类(二)-CSDN博客 Pytorch-Transformer轴承故障一维信号分类(三)-CSDN博客 三十多个开源…...

强化学习导论 -章9 基于函数逼近的同轨策略预测

基于函数逼近的同轨策略预测 我们前面已经完成了基于表格的学习任务&#xff0c;基于表格的就是每个s是独立学习的&#xff0c;基本上不考虑泛化的能力&#xff0c;但是也对于每个任务状态学习的非常好。考虑到状态空间越来越大&#xff0c;我们必须考虑到函数逼近的情况。 1…...

Ubuntu环境中RocketMQ安装教程

参考教程 https://blog.csdn.net/weixin_56219549/article/details/126143231 1、安装JDK&#xff0c;并配置环境变量&#xff08;略&#xff09; 2、下载RocketMQ安装包 RocketMQ下载地址&#xff0c;选择二进制包下载 unzip rocketmq-all-5.0.0-ALPHA-bin-release.zip 使…...