1.从前台传递一个String类型的参数到后台进行查询,如果牵涉到模糊查询会报错,应该把参数封装到对象中再进行传递然后进行模糊查询 2.一个查询框,多个查询条件 <if test="customer !=null and customer !=''"> and t.customer_name like '%#{customer}%' or t.contact_information like '%#{customer}%' </if>…
SQL映射文件 单条件查询 1. 在UserMapper接口添加抽象方法 //根据用户名模糊查询 List<User> getUserListByName(); 2. 在UserMapper.xml里添加SQL <!--根据用户名模糊查询--> <select id="getUserListByName" resultType="User" parameterType="String"> select * fr…
MyBatis入门 1.MyBatis前身是iBatis,是Apache的一个开源项目,2010年这个项目迁移到了Google Code,改名为MyBatis,2013年迁移到GitHub.是一个基于DAO层ORM框架      ORM:Object Relational Mapping 对象关系映射 在mybatis中指的是sql语句与实体类之间的映射 2.MyBatis的优缺点优点:减少代码量,小巧并且简单易学,SQL语句从程序代码中彻底分离,降低耦合度,便于管理和优化,并可重用,支持编写动…
方法一: <!-- 根据hid,hanme,grade,模糊查询医院信息--> 方法一: List<Hospital> getHospitalLike(@Param("selectword") String selectword);<select id="getHospitalLike" resultType="com.hand.hand.domain.Hospital"> SELECT * FROM hosp…
一.手动映射 当实体类属性与数据库字段名不同时,无法自动映射,导致查询出空值,这时候可以使用手动映射 在select节点添加resultMap属性与resultMap节点建立关系…
前提:需要的包log4j.jar,mybatis-3.4.1.jar,mysql-connector-java-5.1.37-bin.jar 1.基本类 员工类 package com.hand.mybatis.bean; public class Employee {        private Integer eId;    private String eName;    private Integer gender;    private String email;    privat…
1.单个参数: 非自定义对象 传参:getStuById(Integer id): 取值:#{id} 单个基本类型参数,随便取值都行:#{ok} 对象: 传参:saveStudent(Student student) 取值:#{属性名} 2.多个参数: 传参:getStudentByLastNameAndAge(String lastName,Integer age) 取值:#{参数名}不好使:报错提示可用的参数是[0,1,param1,param2] 可用的取值方式: 1)#{参数索引} #{…
有一个需求是可以选择多个设备进行删除,于是想到将多个设备id拼成字符串作为参数,以逗号隔开,如:"123,234,456". SQL如下: <delete id="deleteLineEquip" parameterType="String">     delete from AXX_LINE_EQUIP e where e.EQUIP_ID in (${ids}) </delete> 但是系统在执行时老是报错,提示数据类…
1.场景 1把钥匙带1把锁 JavaBean:private Lock lock;//当前钥匙能开哪个锁: 1). interface KeyDao: public Key getKeyByIdSimple(Integer id);//步一 interface LockDao: public Lock getLockByIdSimple(Integer id);//步二 2). KeyDao.xml: <!--     id  keyname     lockid   --> <sele…
1.级联属性的方式封装查出1-1 查钥匙的时候顺别把对应的级联的那把锁也查出来 1).两个JavaBean,Key里有对应的Lock(private Lock lock;//当前钥匙能开哪个锁:) 2).建两张表key表和lock表,key表里加外键 外键好处,安全性:单纯删key表里的一行记录删不掉,只有删除key表记录才行 3).sql语句要对两个表两个相同名字id起别名, id  keyname  lockid  “lid”  lockname -        -           …