[ibatis][springMVC]ibatis的配置和测试,ibatis与springMVC集成后的配置与测试(一)

开源租赁小程序全栈开发实战:从环境搭建到部署上线 这次我们来看一个开源租赁小程序项目。对于很多想快速搭建租赁业务线上平台的开发者来说,从零开发一套完整的小程序,涉及前端、后端、数据库、支付、部署等多个环节,耗时耗力。这个开源项目提供了一个完整的、可直接二次开发的租赁小程序解决方案,旨在降低开发门槛,让开发者能快速拥有一个功能完备的租赁平台。 本文将带你从零开始,完成这个开源租赁小程序的本地环境搭建、功能体验、代码结构解析以及部署上线全流程。无论你是想学习小程序全栈开发,还是急需一个租赁业务的线上工具,这个项目都值得一试。我们会重点关注它的技术栈选择、核心功 阅读详情

一、ibatis的配置和测试

ibatis的配置和测试的项目的结构图如下:



步骤如下:

1. 先创建一个web项目Z_ibatisTest.导入mysql和ibatis的相应jar包,我这边用的是(mysql-connector-java-5.1.15-bin.jar,ibatis-2.3.4.726\lib\ibatis-2.3.4.726.jar).


2. 在mysql数据库中创建相应的表,并创建相应的实体类Student.java

create table student(
	id int primary key auto_increment,
	name varchar(20),
	password varchar(20),
	birthday date,
	create_time datetime
);

insert into student (name,password,birthday,create_time)
values('aa','aa',now(),now());
insert into student (name,password,birthday,create_time)
values('bb','bb',now(),now());
insert into student (name,password,birthday,create_time)
values('cc','cc',now(),now());


package com.wendellup.entity;

import java.util.Date;

public class Student {
	private Integer id;
	private String name;
	private String password;
	private Date birthday;
	private Date createTime;
	
	
	public Integer getId() {
		return id;
	}

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

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public String toString(){
		return "id:"+id+", name:"
			+name+", password:"+password
			+", birthday:"+birthday
			+", creatTime:"+createTime;
	}
	
}

3. 创建与ibatis相关的数据源配置文件db.properties,SqlMapConfig.xml,Student.xml

driver=com.mysql.jdbc.Driver
url=jdbc\:mysql\://localhost\:3306/train_demo2
username=root
password=root

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE sqlMapConfig      
    PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"      
    "http://ibatis.apache.org/dtd/sql-map-config-2.dtd">

<sqlMapConfig>
	<properties resource="ibatis/db.properties" />	
	 <settings cacheModelsEnabled="true" enhancementEnabled="true"
		lazyLoadingEnabled="true" errorTracingEnabled="true" maxRequests="32"
		maxSessions="10" maxTransactions="5" useStatementNamespaces="true" />
		
	<transactionManager type="JDBC">
		<dataSource type="SIMPLE">
			<property name="JDBC.Driver" value="${driver}" />
			<property name="JDBC.ConnectionURL"	value="${url}" />
			<property name="JDBC.Username" value="${username}" />
			<property name="JDBC.Password" value="${password}" />
			<property name="Pool.MaximumActiveConnections" value="10" />
			<property name="Pool.MaximumIdleConnections" value="5" />
			<property name="Pool.MaximumCheckoutTime" value="120000" />
			<property name="Pool.TimeToWait" value="500" />
			<property name="Pool.PingEnabled" value="false" />
			<property name="Pool.PingConnectionsOlderThan" value="1" />
			<property name="Pool.PingConnectionsNotUsedFor" value="1" />
		</dataSource>
	</transactionManager>
	
	<sqlMap resource="ibatis/Student.xml" />
</sqlMapConfig>

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap      
    PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"      
    "http://ibatis.apache.org/dtd/sql-map-2.dtd">

<sqlMap>
	<typeAlias alias="Student" type="com.wendellup.entity.Student"/>
	
	<resultMap class="Student" id="studentResult">
		 <result property="id" column="ID"/>
		 <result property="name" column="NAME" 
		 	javaType="String" jdbcType="Varchar"/>
		 <result property="password" column="PASSWORD"
		 	javaType="String" jdbcType="Varchar"/>
		 <result property="birthday" column="BIRTHDAY"
		 	javaType="java.util.Date" jdbcType="Date"/>
		 <result property="createTime" column="CREATE_TIME"
		 	javaType="java.util.Date" jdbcType="datetime"/>
	</resultMap>
	
	<select id="selectAllStudent" resultMap="studentResult">
		select ID,NAME,PASSWORD,BIRTHDAY,CREATE_TIME from student;
	</select>
	
	<insert id="insertStudent" parameterClass="Student">
		<![CDATA[
			insert into student  
			  (NAME,PASSWORD,BIRTHDAY,CREATE_TIME)
			  values (#name#,#password#,#birthday#,#createTime#);
		]]>
		<selectKey resultClass="int" keyProperty="id"> 
			select max(id) from student;
		</selectKey>
	</insert>
</sqlMap>


4. 创建工具类IBatisUtil.java

package com.wendellup.util;

import java.io.InputStream;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

public class IbatisUtil {
	private static SqlMapClient client;
	static{
		InputStream inputStream = null;
		try{
			inputStream = Resources.class.getClassLoader().getResourceAsStream("ibatis/SqlMapConfig.xml");
		}catch (Exception e) {
			e.printStackTrace();
		}
		client = SqlMapClientBuilder.buildSqlMapClient(inputStream);
	}
	
	public static SqlMapClient getClient(){
		return client;
	}
	
	public static void main(String[] args) {
		System.out.println(IbatisUtil.getClient());
	}
}

5. 在项目中创建与表相应的数据访问对象接口类IStudentDAO.java,数据访问对象类StudentDAOImpl.java


package com.wendellup.dao;

import java.util.List;

import com.wendellup.entity.Student;

public interface IStudentDAO {
	/** 查询所有的学生信息 */
	public List<Student> queryAllStudent() throws Exception ;
	
	/** 插入一条学生信息 */
	public int addStudent(Student student) throws Exception; 
}

package com.wendellup.dao.impl;


import java.sql.SQLException;
import java.util.List;

import com.wendellup.dao.IStudentDAO;
import com.wendellup.entity.Student;
import com.wendellup.util.IbatisUtil;

public class StudentDAOImpl implements IStudentDAO{
	public List<Student> queryAllStudent() throws Exception {
		List<Student> studentList = null;
		try {
			studentList = IbatisUtil.getClient().queryForList("selectAllStudent");
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		return studentList;
	}
	
	public int addStudent(Student student) throws Exception {
		int key;
		try {
			key = (Integer) IbatisUtil.getClient().insert("insertStudent",student);
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		return key;
	}

}

6. 创建测试类TestStudentDAO.java

完成查询所有学生和插入一条学生的操作

package test.wendellup;

import java.util.Date;
import java.util.List;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import com.wendellup.dao.IStudentDAO;
import com.wendellup.dao.impl.StudentDAOImpl;
import com.wendellup.entity.Student;

public class TestStudentDAO {
	private IStudentDAO iStudentDAO = null;
	
	@Before
	public void setUp(){
		iStudentDAO = new StudentDAOImpl();
	}
	
	@Ignore
	@Test
	public void testQueryAllStudent() throws Exception{
		List<Student> studentList = iStudentDAO.queryAllStudent();
		for(Student stu : studentList){
			System.out.println(stu);
		}
	}
	
	@Test
	public void testInsertStudent()throws Exception{
		Student student = new Student();
		student.setName("wendellup");
		student.setPassword("xxx");
		student.setBirthday(new Date());
		student.setCreateTime(new Date());
		int key = iStudentDAO.addStudent(student);
		System.out.println(key);
	}
	
}


项目资源地址:

http://pan.baidu.com/share/link?shareid=139030&uk=3475027816


AI+小程序开发实战:从环境搭建到上线部署全流程指南 人工智能(AI)与小程序开发的融合,正成为技术应用创新的重要方向。其核心原理在于将AI的智能处理能力(如自然语言处理、计算机视觉)通过API调用或端侧模型,与小程序轻量、即用即走的特性相结合。这种融合的技术价值在于,它能以前端友好的交互形式,为用户提供更智能、个性化的服务,极大地拓展了小程序的边界。在应用场景上,无论是智能客服、图像识别工具,还是结合特定业务需求的智能推荐,AI都能为小程序注入新的活力。本文以实战为例,系统梳理了开发一个融合AI能力的小程序所需的技术栈、环境配置、核心功能实现及部署流程,并特 阅读详情

相关推荐

实战拆解打车小程序:从架构设计到性能优化全解析

小程序开发已成为连接线上与线下服务的重要技术载体,其核心在于构建高效、稳定的实时交互系统。从技术原理上看,这通常涉及WebSocket长连接实现双向通信、关系型与内存数据库的混合使用以支撑高并发读写,以及基于地理位置服务的智能调度算法。这些技术的工程价值在于能够为用户提供无缝的O2O体验,例如在出行、外卖等场景中实现订单的实时匹配与状态同步。本文以出行领域为例,深入探讨如何实现一个具备完整交易闭环的小程序应用。针对开发中常见的性能瓶颈,如“vendor.js调用栈溢出”和“Canvas卡顿”问题,本文将提供

weixin_34342992的博客 454

SpringMVC+ibatis

SpringMVC+Ibatis项目搭建 1 创建Maven项目    1.1 选择创建maven项目      2.2 选择创建web项目     本项目为web项目所以选择maven-archetype-webapp   2.3 配置项目参数,点击完成     2.4 添加servlet-api依赖    项目建立完成后,会发现报index.jsp文件报错,错误如下图  

qq_35537426的博客 476

网站被微信封禁怎么办?从自查到申诉的完整避坑指南

本文提供网站被微信封禁的全面解决方案,从快速诊断封禁类型与原因到详细申诉流程,再到构建微信生态合规体系的预防机制。特别针对误封和确实存在违规内容的情况,给出具体操作步骤和技术防护方案,帮助开发者有效应对和预防封禁问题。

weixin_30298497的博客 345

Spring MVC + Ibatis架构原理分析

<br />1: spring框架介绍<br />Spring框架是一个分层架构,由7个定义好的模块组成。Spring模块构建在核心容器上,核心容器定义了创建、配置和管理bean的方式。<br />每个模块的功能如下:<br />核心容器:核心容器提供Spring框架的基本功能。核心容器的主要组件是BeanFactory,它是工厂模式的实现,BeanFactory使用控制反转(IoC)模式将应用程序的配置和依赖性规范与实际的应用代码分开。<br />Spring上下文:Spring上下文是一个配置文件,向S

rongdajian的专栏 1万+

小程序内容安全审核实战:从API选型到性能优化的全链路指南

内容安全审核是互联网应用,特别是用户生成内容(UGC)平台的核心技术组件,它通过机器学习和自然语言处理等技术,自动识别文本、图片中的违规信息。其原理通常基于深度学习模型对海量标注数据进行训练,实现对敏感内容的分类与检测。这项技术的核心价值在于保障平台合规性、维护社区生态,并规避法律风险,是社交、电商、社区等场景的必备能力。在实际工程中,开发者常通过调用平台或第三方提供的API服务来快速集成此功能,这涉及API选型、异步处理、性能优化等关键实践。本文聚焦于小程序生态,深入探讨如何结合微信原生API与第三方服务

weixin_30251829的博客 402

城市漫步路线分享小程序开发实战:位置服务与轨迹采集详解

微信小程序开发是当前移动端轻应用的主流选择,而在众多应用场景中,位置服务类功能因其强依赖真实设备能力而备受关注。从用户授权到GPS打点,再到轨迹绘制与纠偏,完整的路线记录链路涉及多个技术环节。基于uniapp跨端框架,开发者可用一套代码快速构建微信小程序,同时借助HBuilderX实现高效调试与真机预览。而在实际工程中,微信小程序顶部导航栏高度适配、手机软键盘遮挡查询内容等问题也直接影响用户体验,需要结合系统API与自定义组件妥善处理。本文通过一个城市漫步路线分享小程序案例,系统介绍位置服务的技术原理、数据

weixin_33981932的博客 437

Spring集成SpringMVC与Ibatis

一、web.xml contextConfigLocation /WEB-INF/classes/spring-ibatis.xml,/WEB-INF/classes/spring-task.xml,/WEB-INF/classes/spring-servlet.xml org.springframework.web.context.Co

天涯倚墨 1624

微信小程序内容安全审核实战:手把手教你用security.msgSecCheck API搭建敏感词过滤

本文详细介绍了如何利用微信小程序的`security.msgSecCheck` API构建高效的内容安全审核系统,涵盖从云函数封装、性能优化到前端交互设计的全流程实战指南。特别针对社交、论坛等UGC场景,提供敏感词分级策略和异常监控方案,帮助开发者确保小程序内容合规性,避免违规风险。

weixin_28693447的博客 324

SpringMVC+Ibatis框架搭建

这是一个很简单的SpringMVC+Spring+Ibatis框架 ,下图是文件的基本配置 web.xml

屌丝程序员的奋斗之路 4362

豆包免费额度实测:6大登录渠道配额差异与优化策略

AI服务中的免费额度机制,本质是基于用户身份、设备环境与行为特征的动态资源配额系统。其底层依赖HTTP响应头(如X-RateLimit-Remaining)、会话标识(session_id)、设备指纹及网络上下文等多维信号进行实时计算,技术原理涉及滑动窗口限流、阶梯式惩罚算法与灰度策略分发。这类机制直接影响普通用户的可用性体验和企业级产品的成本控制,广泛应用于大模型前端服务、SaaS工具及嵌入式AI集成场景。本文聚焦豆包平台,通过真实抓包与跨渠道对比,揭示微信H5、飞书工作台、Mac客户端等6种入口在额度上

weixin_34319374的博客 412

发现一个宝藏开源商城项目,Spring Boot 4 + Vue 3 全链路,忍不住分享给你们

CorSiteHive是一个高质量的开源微服务商城项目,采用2026年最新技术栈(SpringBoot4.1、Vue3.5、TypeScript6.0等),架构规范严谨。项目包含完整的业务功能(商品、订单、支付、营销等)和多租户支持,模块划分清晰,代码注释完善,测试覆盖率高。技术亮点包括响应式网关、JWT认证、公共能力封装、异步解耦等设计,适合开发者学习或作为商业项目基础。采用Apache2.0协议

qq_17525509的博客 455

SpringMVC ibatis 搭建web应用

1、添加Maven project 【uitss】 添加依赖【pom.xml】 <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.

云博 1366

合规实现跨平台引流:基于企业微信客服的私域流量安全跳转方案

在互联网生态中,跨平台用户引流是运营和增长领域的关键技术挑战,其核心在于平衡平台规则与业务需求。从技术原理上看,合规的引流方案通常基于对官方开放接口的深度利用,通过创造用户主动行为来完成跳转,而非对抗平台风控。这种方案的技术价值在于,它能在不触发平台处罚机制的前提下,实现公域流量向私域阵地的安全、稳定迁移,为长效运营奠定基础。典型的应用场景包括知识付费、电商带货、本地生活服务及个人IP打造等领域的私域沉淀。本文聚焦于当前最主流且稳定的方案——利用企业微信客服组件,详细拆解了其从账号配置、H5落地页开发到安全

weixin_30915275的博客 438

spring mvc+ibatis+spring注解

系统采用spring2.5 + ibatis2.3.4,采用注解方式配置,非xml配置方式。包括分页排序查询、新增、修改、删除、登陆验证功能,数据库采用oracle。

SpringMVC+ibatis整合

这是SpringMVC和Ibatis的整合实例,内包含源码,导入MyEclipse即可

springMVC整合ibatis 配置详细

此案例有springMVC整合ibatis包含了springMVC的注解使用 spring管理ibatis的详细配置

SpringMvc+Ibatis框架

SpringMvc+ibatis框架实现,直接可上项目,简单实用,案例实现用户的增删查改

AD9371实战:如何用ZCU106搭建JESD204B TX时钟链(含关键参数计算)

本文详细解析了如何基于Xilinx ZCU106开发板为AD9371搭建JESD204B TX时钟链。文章从系统需求出发,逐步推导出从IQ采样率到GTH线速率的关键参数计算公式,并提供了在Vivado中配置GTH收发器(包括QPLL选择、分频比设置)的实战步骤与调试技巧,旨在帮助硬件工程师快速实现稳定可靠的JESD204B高速数据传输链路。

weixin_29164843的博客 293
上一篇: [spring]Spring <context:component-scan base-package="">和<context:annotation-config>
下一篇: [ibatis]ibatis的配置和测试,ibatis与springMVC集成后的配置与测试(二)
wendellup
博客等级 码龄16年 54粉丝 49原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值