SpringMVC快速入门(4)SpringMVC整合Mybatis,SpringMVC参数绑定

《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》点击传送门,即可获取!


– Table structure for user


DROP TABLE IF EXISTS user;

CREATE TABLE user (

id int(11) NOT NULL AUTO_INCREMENT,

username varchar(32) NOT NULL COMMENT ‘用户名称’,

birthday date DEFAULT NULL COMMENT ‘生日’,

sex char(1) DEFAULT NULL COMMENT ‘性别’,

address varchar(256) DEFAULT NULL COMMENT ‘地址’,

uuid2 varchar(128) DEFAULT NULL COMMENT ‘uuid2’,

PRIMARY KEY (id)

) ENGINE=InnoDB AUTO_INCREMENT=47 DEFAULT CHARSET=utf8;


– Records of user


INSERT INTO user VALUES (‘1’, ‘admin’, ‘2014-07-10’, ‘2’, ‘呼和浩特’, null);

INSERT INTO user VALUES (‘10’, ‘王五’, ‘2014-07-10’, ‘1’, ‘哈哈哈’, null);

INSERT INTO user VALUES (‘16’, ‘王五’, ‘2014-07-10’, ‘1’, ‘略略略’, null);

INSERT INTO user VALUES (‘22’, ‘张娜’, ‘2014-07-10’, ‘1’, ‘河北’, null);

INSERT INTO user VALUES (‘24’, ‘张三’, ‘2014-07-10’, ‘1’, ‘内蒙古’, null);

INSERT INTO user VALUES (‘25’, ‘李四’, ‘2014-07-10’, ‘1’, ‘河南’, null);

INSERT INTO user VALUES (‘26’, ‘赵六’, ‘2014-07-10’, ‘2’, ‘广东’, null);

INSERT INTO user VALUES (‘27’, ‘张飞’, ‘2021-01-26’, ‘1’, ‘四川’, null);

INSERT INTO user VALUES (‘28’, ‘张飞’, ‘2021-01-29’, ‘1’, ‘四川’, null);

INSERT INTO user VALUES (‘29’, ‘张飞2’, ‘2021-01-29’, ‘1’, ‘四川’, null);

INSERT INTO user VALUES (‘30’, ‘张角’, ‘2021-01-29’, ‘1’, ‘四川’, null);

INSERT INTO user VALUES (‘31’, ‘张飞5’, ‘2021-01-29’, ‘1’, ‘四川’, null);

INSERT INTO user VALUES (‘32’, ‘张飞7’, ‘2021-01-29’, ‘1’, ‘四川’, ‘a5e55878-6207-11eb-877e-6045cbbd3ae1’);

INSERT INTO user VALUES (‘34’, ‘张飞7’, ‘2021-01-29’, ‘1’, ‘四川’, ‘2240280a-6208-11eb-877e-6045cbbd3ae1’);

INSERT INTO user VALUES (‘35’, ‘张飞7’, ‘2021-01-29’, ‘1’, ‘四川’, null);

INSERT INTO user VALUES (‘36’, ‘张飞1111’, ‘2021-01-30’, ‘2’, ‘深圳2121’, null);

INSERT INTO user VALUES (‘37’, ‘张飞1111’, ‘2021-01-30’, ‘2’, ‘深圳2121’, null);

INSERT INTO user VALUES (‘38’, ‘张飞1111’, ‘2021-03-09’, ‘2’, ‘深圳2121’, null);

INSERT INTO user VALUES (‘39’, ‘张飞1111’, ‘2021-03-12’, ‘2’, ‘深圳2121’, null);

INSERT INTO user VALUES (‘40’, ‘张飞1111’, ‘2021-03-12’, ‘2’, ‘深圳2121’, null);

INSERT INTO user VALUES (‘41’, ‘张飞1111’, ‘2021-03-12’, ‘2’, ‘2121’, null);

INSERT INTO user VALUES (‘42’, ‘张飞1111’, ‘2021-03-12’, ‘2’, ‘深圳2121’, null);

INSERT INTO user VALUES (‘43’, ‘张飞1111’, ‘2021-03-13’, ‘2’, ‘深圳2121’, null);

INSERT INTO user VALUES (‘44’, ‘张飞1111’, ‘2021-03-16’, ‘2’, ‘深圳2121’, null);

INSERT INTO user VALUES (‘45’, ‘张飞1111’, ‘2021-03-16’, ‘2’, ‘深圳2121’, null);

INSERT INTO user VALUES (‘46’, ‘诸葛亮’, null, ‘1’, ‘三国蜀国’, null);

一、Dao层


0、创建Item类

在这里插入图片描述

package com.itzheng.springmvc.pojo;

import java.util.Date;

public class Item {

private Integer id;

private String name;

private Float price;

private String detail;

private String pic;

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 == null ? null : name.trim();

}

public Float getPrice() {

return price;

}

public void setPrice(Float price) {

this.price = price;

}

public String getDetail() {

return detail;

}

public void setDetail(String detail) {

this.detail = detail == null ? null : detail.trim();

}

public String getPic() {

return pic;

}

public void setPic(String pic) {

this.pic = pic == null ? null : pic.trim();

}

public Date getCreatetime() {

return createtime;

}

public void setCreatetime(Date createtime) {

this.createtime = createtime;

}

@Override

public String toString() {

return “Item [id=” + id + “, name=” + name + “, price=” + price + “, detail=” + detail + “, pic=” + pic

  • “, createtime=” + createtime + “]”;

}

}

1、创建ItemExample类

在这里插入图片描述

package com.itzheng.springmvc.pojo;

import java.util.ArrayList;

import java.util.Date;

import java.util.List;

public class ItemExample {

protected String orderByClause;

protected boolean distinct;

protected List oredCriteria;

public ItemExample() {

oredCriteria = new ArrayList();

}

public void setOrderByClause(String orderByClause) {

this.orderByClause = orderByClause;

}

public String getOrderByClause() {

return orderByClause;

}

public void setDistinct(boolean distinct) {

this.distinct = distinct;

}

public boolean isDistinct() {

return distinct;

}

public List getOredCriteria() {

return oredCriteria;

}

public void or(Criteria criteria) {

oredCriteria.add(criteria);

}

public Criteria or() {

Criteria criteria = createCriteriaInternal();

oredCriteria.add(criteria);

return criteria;

}

public Criteria createCriteria() {

Criteria criteria = createCriteriaInternal();

if (oredCriteria.size() == 0) {

oredCriteria.add(criteria);

}

return criteria;

}

protected Criteria createCriteriaInternal() {

Criteria criteria = new Criteria();

return criteria;

}

public void clear() {

oredCriteria.clear();

orderByClause = null;

distinct = false;

}

protected abstract static class GeneratedCriteria {

protected List criteria;

protected GeneratedCriteria() {

super();

criteria = new ArrayList();

}

public boolean isValid() {

return criteria.size() > 0;

}

public List getAllCriteria() {

return criteria;

}

public List getCriteria() {

return criteria;

}

protected void addCriterion(String condition) {

if (condition == null) {

throw new RuntimeException(“Value for condition cannot be null”);

}

criteria.add(new Criterion(condition));

}

protected void addCriterion(String condition, Object value, String property) {

if (value == null) {

throw new RuntimeException(“Value for " + property + " cannot be null”);

}

criteria.add(new Criterion(condition, value));

}

protected void addCriterion(String condition, Object value1, Object value2, String property) {

if (value1 == null || value2 == null) {

throw new RuntimeException(“Between values for " + property + " cannot be null”);

}

criteria.add(new Criterion(condition, value1, value2));

}

public Criteria andIdIsNull() {

addCriterion(“id is null”);

return (Criteria) this;

}

public Criteria andIdIsNotNull() {

addCriterion(“id is not null”);

return (Criteria) this;

}

public Criteria andIdEqualTo(Integer value) {

addCriterion(“id =”, value, “id”);

return (Criteria) this;

}

public Criteria andIdNotEqualTo(Integer value) {

addCriterion(“id <>”, value, “id”);

return (Criteria) this;

}

public Criteria andIdGreaterThan(Integer value) {

addCriterion(“id >”, value, “id”);

return (Criteria) this;

}

public Criteria andIdGreaterThanOrEqualTo(Integer value) {

addCriterion(“id >=”, value, “id”);

return (Criteria) this;

}

public Criteria andIdLessThan(Integer value) {

addCriterion(“id <”, value, “id”);

return (Criteria) this;

}

public Criteria andIdLessThanOrEqualTo(Integer value) {

addCriterion(“id <=”, value, “id”);

return (Criteria) this;

}

public Criteria andIdIn(List values) {

addCriterion(“id in”, values, “id”);

return (Criteria) this;

}

public Criteria andIdNotIn(List values) {

addCriterion(“id not in”, values, “id”);

return (Criteria) this;

}

public Criteria andIdBetween(Integer value1, Integer value2) {

addCriterion(“id between”, value1, value2, “id”);

return (Criteria) this;

}

public Criteria andIdNotBetween(Integer value1, Integer value2) {

addCriterion(“id not between”, value1, value2, “id”);

return (Criteria) this;

}

public Criteria andNameIsNull() {

addCriterion(“name is null”);

return (Criteria) this;

}

public Criteria andNameIsNotNull() {

addCriterion(“name is not null”);

return (Criteria) this;

}

public Criteria andNameEqualTo(String value) {

addCriterion(“name =”, value, “name”);

return (Criteria) this;

}

public Criteria andNameNotEqualTo(String value) {

addCriterion(“name <>”, value, “name”);

return (Criteria) this;

}

public Criteria andNameGreaterThan(String value) {

addCriterion(“name >”, value, “name”);

return (Criteria) this;

}

public Criteria andNameGreaterThanOrEqualTo(String value) {

addCriterion(“name >=”, value, “name”);

return (Criteria) this;

}

public Criteria andNameLessThan(String value) {

addCriterion(“name <”, value, “name”);

return (Criteria) this;

}

public Criteria andNameLessThanOrEqualTo(String value) {

addCriterion(“name <=”, value, “name”);

return (Criteria) this;

}

public Criteria andNameLike(String value) {

addCriterion(“name like”, value, “name”);

return (Criteria) this;

}

public Criteria andNameNotLike(String value) {

addCriterion(“name not like”, value, “name”);

return (Criteria) this;

}

public Criteria andNameIn(List values) {

addCriterion(“name in”, values, “name”);

return (Criteria) this;

}

public Criteria andNameNotIn(List values) {

addCriterion(“name not in”, values, “name”);

return (Criteria) this;

}

public Criteria andNameBetween(String value1, String value2) {

addCriterion(“name between”, value1, value2, “name”);

return (Criteria) this;

}

public Criteria andNameNotBetween(String value1, String value2) {

addCriterion(“name not between”, value1, value2, “name”);

return (Criteria) this;

}

public Criteria andPriceIsNull() {

addCriterion(“price is null”);

return (Criteria) this;

}

public Criteria andPriceIsNotNull() {

addCriterion(“price is not null”);

return (Criteria) this;

}

public Criteria andPriceEqualTo(Float value) {

addCriterion(“price =”, value, “price”);

return (Criteria) this;

}

public Criteria andPriceNotEqualTo(Float value) {

addCriterion(“price <>”, value, “price”);

return (Criteria) this;

}

public Criteria andPriceGreaterThan(Float value) {

addCriterion(“price >”, value, “price”);

return (Criteria) this;

}

public Criteria andPriceGreaterThanOrEqualTo(Float value) {

addCriterion(“price >=”, value, “price”);

return (Criteria) this;

}

public Criteria andPriceLessThan(Float value) {

addCriterion(“price <”, value, “price”);

return (Criteria) this;

}

public Criteria andPriceLessThanOrEqualTo(Float value) {

addCriterion(“price <=”, value, “price”);

return (Criteria) this;

}

public Criteria andPriceIn(List values) {

addCriterion(“price in”, values, “price”);

return (Criteria) this;

}

public Criteria andPriceNotIn(List values) {

addCriterion(“price not in”, values, “price”);

return (Criteria) this;

}

public Criteria andPriceBetween(Float value1, Float value2) {

addCriterion(“price between”, value1, value2, “price”);

return (Criteria) this;

}

public Criteria andPriceNotBetween(Float value1, Float value2) {

addCriterion(“price not between”, value1, value2, “price”);

return (Criteria) this;

}

public Criteria andDetailIsNull() {

addCriterion(“detail is null”);

return (Criteria) this;

}

public Criteria andDetailIsNotNull() {

addCriterion(“detail is not null”);

return (Criteria) this;

}

public Criteria andDetailEqualTo(String value) {

addCriterion(“detail =”, value, “detail”);

return (Criteria) this;

}

public Criteria andDetailNotEqualTo(String value) {

addCriterion(“detail <>”, value, “detail”);

return (Criteria) this;

}

public Criteria andDetailGreaterThan(String value) {

addCriterion(“detail >”, value, “detail”);

return (Criteria) this;

}

public Criteria andDetailGreaterThanOrEqualTo(String value) {

addCriterion(“detail >=”, value, “detail”);

return (Criteria) this;

}

public Criteria andDetailLessThan(String value) {

addCriterion(“detail <”, value, “detail”);

return (Criteria) this;

}

public Criteria andDetailLessThanOrEqualTo(String value) {

addCriterion(“detail <=”, value, “detail”);

return (Criteria) this;

}

public Criteria andDetailLike(String value) {

addCriterion(“detail like”, value, “detail”);

return (Criteria) this;

}

public Criteria andDetailNotLike(String value) {

addCriterion(“detail not like”, value, “detail”);

return (Criteria) this;

}

public Criteria andDetailIn(List values) {

addCriterion(“detail in”, values, “detail”);

return (Criteria) this;

}

public Criteria andDetailNotIn(List values) {

addCriterion(“detail not in”, values, “detail”);

return (Criteria) this;

}

public Criteria andDetailBetween(String value1, String value2) {

addCriterion(“detail between”, value1, value2, “detail”);

return (Criteria) this;

}

public Criteria andDetailNotBetween(String value1, String value2) {

addCriterion(“detail not between”, value1, value2, “detail”);

return (Criteria) this;

}

public Criteria andPicIsNull() {

addCriterion(“pic is null”);

return (Criteria) this;

}

public Criteria andPicIsNotNull() {

addCriterion(“pic is not null”);

return (Criteria) this;

}

public Criteria andPicEqualTo(String value) {

addCriterion(“pic =”, value, “pic”);

return (Criteria) this;

}

public Criteria andPicNotEqualTo(String value) {

addCriterion(“pic <>”, value, “pic”);

return (Criteria) this;

}

public Criteria andPicGreaterThan(String value) {

addCriterion(“pic >”, value, “pic”);

return (Criteria) this;

}

public Criteria andPicGreaterThanOrEqualTo(String value) {

addCriterion(“pic >=”, value, “pic”);

return (Criteria) this;

}

public Criteria andPicLessThan(String value) {

addCriterion(“pic <”, value, “pic”);

return (Criteria) this;

}

public Criteria andPicLessThanOrEqualTo(String value) {

addCriterion(“pic <=”, value, “pic”);

return (Criteria) this;

}

public Criteria andPicLike(String value) {

addCriterion(“pic like”, value, “pic”);

return (Criteria) this;

}

public Criteria andPicNotLike(String value) {

addCriterion(“pic not like”, value, “pic”);

return (Criteria) this;

}

public Criteria andPicIn(List values) {

addCriterion(“pic in”, values, “pic”);

return (Criteria) this;

}

public Criteria andPicNotIn(List values) {

addCriterion(“pic not in”, values, “pic”);

return (Criteria) this;

}

public Criteria andPicBetween(String value1, String value2) {

addCriterion(“pic between”, value1, value2, “pic”);

return (Criteria) this;

}

public Criteria andPicNotBetween(String value1, String value2) {

addCriterion(“pic not between”, value1, value2, “pic”);

return (Criteria) this;

}

public Criteria andCreatetimeIsNull() {

addCriterion(“createtime is null”);

return (Criteria) this;

}

public Criteria andCreatetimeIsNotNull() {

addCriterion(“createtime is not null”);

return (Criteria) this;

}

public Criteria andCreatetimeEqualTo(Date value) {

addCriterion(“createtime =”, value, “createtime”);

return (Criteria) this;

}

public Criteria andCreatetimeNotEqualTo(Date value) {

addCriterion(“createtime <>”, value, “createtime”);

return (Criteria) this;

}

public Criteria andCreatetimeGreaterThan(Date value) {

addCriterion(“createtime >”, value, “createtime”);

return (Criteria) this;

}

public Criteria andCreatetimeGreaterThanOrEqualTo(Date value) {

addCriterion(“createtime >=”, value, “createtime”);

return (Criteria) this;

}

public Criteria andCreatetimeLessThan(Date value) {

addCriterion(“createtime <”, value, “createtime”);

return (Criteria) this;

}

public Criteria andCreatetimeLessThanOrEqualTo(Date value) {

addCriterion(“createtime <=”, value, “createtime”);

return (Criteria) this;

}

public Criteria andCreatetimeIn(List values) {

addCriterion(“createtime in”, values, “createtime”);

return (Criteria) this;

}

public Criteria andCreatetimeNotIn(List values) {

addCriterion(“createtime not in”, values, “createtime”);

return (Criteria) this;

}

public Criteria andCreatetimeBetween(Date value1, Date value2) {

addCriterion(“createtime between”, value1, value2, “createtime”);

return (Criteria) this;

}

public Criteria andCreatetimeNotBetween(Date value1, Date value2) {

addCriterion(“createtime not between”, value1, value2, “createtime”);

return (Criteria) this;

}

}

public static class Criteria extends GeneratedCriteria {

protected Criteria() {

super();

}

}

public static class Criterion {

private String condition;

private Object value;

private Object secondValue;

private boolean noValue;

private boolean singleValue;

private boolean betweenValue;

private boolean listValue;

private String typeHandler;

public String getCondition() {

return condition;

}

public Object getValue() {

return value;

}

public Object getSecondValue() {

return secondValue;

}

public boolean isNoValue() {

return noValue;

}

public boolean isSingleValue() {

return singleValue;

}

public boolean isBetweenValue() {

return betweenValue;

}

public boolean isListValue() {

return listValue;

}

public String getTypeHandler() {

return typeHandler;

}

protected Criterion(String condition) {

super();

this.condition = condition;

this.typeHandler = null;

this.noValue = true;

}

protected Criterion(String condition, Object value, String typeHandler) {

super();

this.condition = condition;

this.value = value;

this.typeHandler = typeHandler;

if (value instanceof List<?>) {

this.listValue = true;

} else {

this.singleValue = true;

}

}

protected Criterion(String condition, Object value) {

this(condition, value, null);

}

protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {

super();

this.condition = condition;

this.value = value;

this.secondValue = secondValue;

this.typeHandler = typeHandler;

this.betweenValue = true;

}

protected Criterion(String condition, Object value, Object secondValue) {

this(condition, value, secondValue, null);

}

}

}

2、创建QueryVo类

在这里插入图片描述

package com.itzheng.springmvc.pojo;

/**

  • @author Steven

*/

public class QueryVo {

private Item item;

public Item getItem() {

return item;

}

public void setItem(Item item) {

this.item = item;

}

}

3、创建User类

在这里插入图片描述

package com.itzheng.springmvc.pojo;

import java.util.Date;

public class User {

private Integer id;

private String username;

private Date birthday;

private String sex;

private String address;

public Integer getId() {

return id;

}

public void setId(Integer id) {

this.id = id;

}

public String getUsername() {

return username;

}

public void setUsername(String username) {

this.username = username == null ? null : username.trim();

}

public Date getBirthday() {

return birthday;

}

public void setBirthday(Date birthday) {

this.birthday = birthday;

}

public String getSex() {

return sex;

}

public void setSex(String sex) {

this.sex = sex == null ? null : sex.trim();

}

public String getAddress() {

return address;

}

public void setAddress(String address) {

this.address = address == null ? null : address.trim();

}

}

4、创建UserExample类

在这里插入图片描述

package com.itzheng.springmvc.pojo;

import java.util.ArrayList;

import java.util.Date;

import java.util.Iterator;

import java.util.List;

public class UserExample {

protected String orderByClause;

protected boolean distinct;

protected List oredCriteria;

public UserExample() {

oredCriteria = new ArrayList();

}

public void setOrderByClause(String orderByClause) {

this.orderByClause = orderByClause;

}

public String getOrderByClause() {

return orderByClause;

}

public void setDistinct(boolean distinct) {

this.distinct = distinct;

}

public boolean isDistinct() {

return distinct;

}

public List getOredCriteria() {

return oredCriteria;

}

public void or(Criteria criteria) {

oredCriteria.add(criteria);

}

public Criteria or() {

Criteria criteria = createCriteriaInternal();

oredCriteria.add(criteria);

return criteria;

}

public Criteria createCriteria() {

Criteria criteria = createCriteriaInternal();

if (oredCriteria.size() == 0) {

oredCriteria.add(criteria);

}

return criteria;

}

protected Criteria createCriteriaInternal() {

Criteria criteria = new Criteria();

return criteria;

}

public void clear() {

oredCriteria.clear();

orderByClause = null;

distinct = false;

}

protected abstract static class GeneratedCriteria {

protected List criteria;

protected GeneratedCriteria() {

super();

criteria = new ArrayList();

}

public boolean isValid() {

return criteria.size() > 0;

}

public List getAllCriteria() {

return criteria;

}

public List getCriteria() {

return criteria;

}

protected void addCriterion(String condition) {

if (condition == null) {

throw new RuntimeException(“Value for condition cannot be null”);

}

criteria.add(new Criterion(condition));

}

protected void addCriterion(String condition, Object value, String property) {

if (value == null) {

throw new RuntimeException(“Value for " + property + " cannot be null”);

}

criteria.add(new Criterion(condition, value));

}

protected void addCriterion(String condition, Object value1, Object value2, String property) {

if (value1 == null || value2 == null) {

throw new RuntimeException(“Between values for " + property + " cannot be null”);

}

criteria.add(new Criterion(condition, value1, value2));

}

protected void addCriterionForJDBCDate(String condition, Date value, String property) {

if (value == null) {

throw new RuntimeException(“Value for " + property + " cannot be null”);

}

addCriterion(condition, new java.sql.Date(value.getTime()), property);

}

protected void addCriterionForJDBCDate(String condition, List values, String property) {

if (values == null || values.size() == 0) {

throw new RuntimeException(“Value list for " + property + " cannot be null or empty”);

}

List<java.sql.Date> dateList = new ArrayList<java.sql.Date>();

Iterator iter = values.iterator();

while (iter.hasNext()) {

dateList.add(new java.sql.Date(iter.next().getTime()));

}

addCriterion(condition, dateList, property);

}

protected void addCriterionForJDBCDate(String condition, Date value1, Date value2, String property) {

if (value1 == null || value2 == null) {

throw new RuntimeException(“Between values for " + property + " cannot be null”);

}

addCriterion(condition, new java.sql.Date(value1.getTime()), new java.sql.Date(value2.getTime()), property);

}

public Criteria andIdIsNull() {

addCriterion(“id is null”);

return (Criteria) this;

}

public Criteria andIdIsNotNull() {

addCriterion(“id is not null”);

return (Criteria) this;

}

public Criteria andIdEqualTo(Integer value) {

addCriterion(“id =”, value, “id”);

return (Criteria) this;

}

public Criteria andIdNotEqualTo(Integer value) {

addCriterion(“id <>”, value, “id”);

return (Criteria) this;

}

public Criteria andIdGreaterThan(Integer value) {

addCriterion(“id >”, value, “id”);

return (Criteria) this;

}

public Criteria andIdGreaterThanOrEqualTo(Integer value) {

addCriterion(“id >=”, value, “id”);

return (Criteria) this;

}

public Criteria andIdLessThan(Integer value) {

addCriterion(“id <”, value, “id”);

return (Criteria) this;

}

public Criteria andIdLessThanOrEqualTo(Integer value) {

addCriterion(“id <=”, value, “id”);

return (Criteria) this;

}

public Criteria andIdIn(List values) {

addCriterion(“id in”, values, “id”);

return (Criteria) this;

}

public Criteria andIdNotIn(List values) {

addCriterion(“id not in”, values, “id”);

return (Criteria) this;

}

public Criteria andIdBetween(Integer value1, Integer value2) {

addCriterion(“id between”, value1, value2, “id”);

return (Criteria) this;

}

public Criteria andIdNotBetween(Integer value1, Integer value2) {

addCriterion(“id not between”, value1, value2, “id”);

return (Criteria) this;

}

public Criteria andUsernameIsNull() {

addCriterion(“username is null”);

return (Criteria) this;

}

public Criteria andUsernameIsNotNull() {

addCriterion(“username is not null”);

return (Criteria) this;

}

public Criteria andUsernameEqualTo(String value) {

addCriterion(“username =”, value, “username”);

return (Criteria) this;

}

public Criteria andUsernameNotEqualTo(String value) {

addCriterion(“username <>”, value, “username”);

return (Criteria) this;

}

public Criteria andUsernameGreaterThan(String value) {

addCriterion(“username >”, value, “username”);

return (Criteria) this;

}

public Criteria andUsernameGreaterThanOrEqualTo(String value) {

addCriterion(“username >=”, value, “username”);

return (Criteria) this;

}

public Criteria andUsernameLessThan(String value) {

addCriterion(“username <”, value, “username”);

return (Criteria) this;

}

public Criteria andUsernameLessThanOrEqualTo(String value) {

addCriterion(“username <=”, value, “username”);

return (Criteria) this;

}

public Criteria andUsernameLike(String value) {

addCriterion(“username like”, value, “username”);

return (Criteria) this;

}

public Criteria andUsernameNotLike(String value) {

addCriterion(“username not like”, value, “username”);

return (Criteria) this;

}

public Criteria andUsernameIn(List values) {

addCriterion(“username in”, values, “username”);

return (Criteria) this;

}

public Criteria andUsernameNotIn(List values) {

addCriterion(“username not in”, values, “username”);

return (Criteria) this;

}

public Criteria andUsernameBetween(String value1, String value2) {

addCriterion(“username between”, value1, value2, “username”);

return (Criteria) this;

}

public Criteria andUsernameNotBetween(String value1, String value2) {

addCriterion(“username not between”, value1, value2, “username”);

return (Criteria) this;

}

public Criteria andBirthdayIsNull() {

addCriterion(“birthday is null”);

return (Criteria) this;

}

public Criteria andBirthdayIsNotNull() {

addCriterion(“birthday is not null”);

return (Criteria) this;

}

public Criteria andBirthdayEqualTo(Date value) {

addCriterionForJDBCDate(“birthday =”, value, “birthday”);

return (Criteria) this;

}

public Criteria andBirthdayNotEqualTo(Date value) {

addCriterionForJDBCDate(“birthday <>”, value, “birthday”);

return (Criteria) this;

}

public Criteria andBirthdayGreaterThan(Date value) {

addCriterionForJDBCDate(“birthday >”, value, “birthday”);

return (Criteria) this;

}

public Criteria andBirthdayGreaterThanOrEqualTo(Date value) {

addCriterionForJDBCDate(“birthday >=”, value, “birthday”);

return (Criteria) this;

}

public Criteria andBirthdayLessThan(Date value) {

addCriterionForJDBCDate(“birthday <”, value, “birthday”);

return (Criteria) this;

}

public Criteria andBirthdayLessThanOrEqualTo(Date value) {

addCriterionForJDBCDate(“birthday <=”, value, “birthday”);

return (Criteria) this;

}

public Criteria andBirthdayIn(List values) {

addCriterionForJDBCDate(“birthday in”, values, “birthday”);

return (Criteria) this;

}

public Criteria andBirthdayNotIn(List values) {

addCriterionForJDBCDate(“birthday not in”, values, “birthday”);

return (Criteria) this;

}

public Criteria andBirthdayBetween(Date value1, Date value2) {

addCriterionForJDBCDate(“birthday between”, value1, value2, “birthday”);

return (Criteria) this;

}

public Criteria andBirthdayNotBetween(Date value1, Date value2) {

addCriterionForJDBCDate(“birthday not between”, value1, value2, “birthday”);

return (Criteria) this;

}

public Criteria andSexIsNull() {

addCriterion(“sex is null”);

return (Criteria) this;

}

public Criteria andSexIsNotNull() {

addCriterion(“sex is not null”);

return (Criteria) this;

}

public Criteria andSexEqualTo(String value) {

addCriterion(“sex =”, value, “sex”);

return (Criteria) this;

}

public Criteria andSexNotEqualTo(String value) {

addCriterion(“sex <>”, value, “sex”);

return (Criteria) this;

}

public Criteria andSexGreaterThan(String value) {

addCriterion(“sex >”, value, “sex”);

return (Criteria) this;

}

public Criteria andSexGreaterThanOrEqualTo(String value) {

addCriterion(“sex >=”, value, “sex”);

return (Criteria) this;

}

public Criteria andSexLessThan(String value) {

addCriterion(“sex <”, value, “sex”);

return (Criteria) this;

}

public Criteria andSexLessThanOrEqualTo(String value) {

addCriterion(“sex <=”, value, “sex”);

return (Criteria) this;

}

public Criteria andSexLike(String value) {

addCriterion(“sex like”, value, “sex”);

return (Criteria) this;

}

public Criteria andSexNotLike(String value) {

addCriterion(“sex not like”, value, “sex”);

return (Criteria) this;

}

public Criteria andSexIn(List values) {

addCriterion(“sex in”, values, “sex”);

return (Criteria) this;

}

public Criteria andSexNotIn(List values) {

addCriterion(“sex not in”, values, “sex”);

return (Criteria) this;

}

public Criteria andSexBetween(String value1, String value2) {

addCriterion(“sex between”, value1, value2, “sex”);

return (Criteria) this;

}

public Criteria andSexNotBetween(String value1, String value2) {

addCriterion(“sex not between”, value1, value2, “sex”);

return (Criteria) this;

}

public Criteria andAddressIsNull() {

addCriterion(“address is null”);

return (Criteria) this;

}

public Criteria andAddressIsNotNull() {

addCriterion(“address is not null”);

return (Criteria) this;

}

public Criteria andAddressEqualTo(String value) {

addCriterion(“address =”, value, “address”);

return (Criteria) this;

}

public Criteria andAddressNotEqualTo(String value) {

addCriterion(“address <>”, value, “address”);

return (Criteria) this;

}

public Criteria andAddressGreaterThan(String value) {

addCriterion(“address >”, value, “address”);

return (Criteria) this;

}

public Criteria andAddressGreaterThanOrEqualTo(String value) {

addCriterion(“address >=”, value, “address”);

return (Criteria) this;

}

public Criteria andAddressLessThan(String value) {

addCriterion(“address <”, value, “address”);

return (Criteria) this;

}

public Criteria andAddressLessThanOrEqualTo(String value) {

addCriterion(“address <=”, value, “address”);

return (Criteria) this;

}

public Criteria andAddressLike(String value) {

addCriterion(“address like”, value, “address”);

return (Criteria) this;

}

public Criteria andAddressNotLike(String value) {

addCriterion(“address not like”, value, “address”);

return (Criteria) this;

}

public Criteria andAddressIn(List values) {

addCriterion(“address in”, values, “address”);

return (Criteria) this;

}

public Criteria andAddressNotIn(List values) {

addCriterion(“address not in”, values, “address”);

return (Criteria) this;

}

public Criteria andAddressBetween(String value1, String value2) {

addCriterion(“address between”, value1, value2, “address”);

return (Criteria) this;

}

public Criteria andAddressNotBetween(String value1, String value2) {

addCriterion(“address not between”, value1, value2, “address”);

return (Criteria) this;

}

}

public static class Criteria extends GeneratedCriteria {

protected Criteria() {

super();

}

}

public static class Criterion {

private String condition;

private Object value;

private Object secondValue;

private boolean noValue;

private boolean singleValue;

private boolean betweenValue;

private boolean listValue;

private String typeHandler;

public String getCondition() {

return condition;

}

public Object getValue() {

return value;

}

public Object getSecondValue() {

return secondValue;

}

public boolean isNoValue() {

return noValue;

}

public boolean isSingleValue() {

return singleValue;

}

public boolean isBetweenValue() {

return betweenValue;

}

public boolean isListValue() {

return listValue;

}

public String getTypeHandler() {

return typeHandler;

}

protected Criterion(String condition) {

super();

this.condition = condition;

this.typeHandler = null;

this.noValue = true;

}

protected Criterion(String condition, Object value, String typeHandler) {

super();

this.condition = condition;

this.value = value;

this.typeHandler = typeHandler;

if (value instanceof List<?>) {

this.listValue = true;

} else {

this.singleValue = true;

}

}

protected Criterion(String condition, Object value) {

this(condition, value, null);

}

protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {

super();

this.condition = condition;

this.value = value;

this.secondValue = secondValue;

this.typeHandler = typeHandler;

this.betweenValue = true;

}

protected Criterion(String condition, Object value, Object secondValue) {

this(condition, value, secondValue, null);

}

}

}

5、创建SqlMapConfig.xml

在这里插入图片描述

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

6、创建spring文件夹并创建applicationContext-dao.xml

a)数据库连接池

b)SqlSessionFactory对象,需要spring和mybatis整合包下的。

c)配置mapper文件扫描器

在这里插入图片描述

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

<beans xmlns=“http://www.springframework.org/schema/beans”

xmlns:context=“http://www.springframework.org/schema/context” xmlns:p=“http://www.springframework.org/schema/p”

xmlns:aop=“http://www.springframework.org/schema/aop” xmlns:tx=“http://www.springframework.org/schema/tx”

xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd

http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd

http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">

<context:property-placeholder location=“classpath:jdbc.properties” />

<bean id=“dataSource” class=“org.apache.commons.dbcp.BasicDataSource”

destroy-method=“close”>

7、jdbc.properties和log4j.properties

在这里插入图片描述

jdbc.driver=com.mysql.jdbc.Driver

jdbc.url=jdbc:mysql://localhost:3306/mybatis?characterEncoding=utf-8

jdbc.username=root

jdbc.password=root

在这里插入图片描述

Global logging configuration

log4j.rootLogger=DEBUG, stdout

Console output…

log4j.appender.stdout=org.apache.log4j.ConsoleAppender

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

8、创建mapper文件夹以及对应的类和映射

(1)创建ItemMapper接口和对应的方法

在这里插入图片描述

package com.itzheng.springmvc.mapper;

import com.itzheng.springmvc.pojo.Item;

import com.itzheng.springmvc.pojo.ItemExample;

import java.util.List;

import org.apache.ibatis.annotations.Param;

public interface ItemMapper {

int countByExample(ItemExample example);

int deleteByExample(ItemExample example);

int deleteByPrimaryKey(Integer id);

int insert(Item record);

int insertSelective(Item record);

List selectByExample(ItemExample example);

Item selectByPrimaryKey(Integer id);

int updateByExampleSelective(@Param(“record”) Item record, @Param(“example”) ItemExample example);

int updateByExample(@Param(“record”) Item record, @Param(“example”) ItemExample example);

int updateByPrimaryKeySelective(Item record);

int updateByPrimaryKey(Item record);

}

(2)创建ItemMapper.xml

在这里插入图片描述

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

and ${criterion.condition}

and ${criterion.condition} #{criterion.value}

and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}

and ${criterion.condition}

#{listItem}

and ${criterion.condition}

and ${criterion.condition} #{criterion.value}

and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}

and ${criterion.condition}

#{listItem}

id, name, price, detail, pic, createtime

select

distinct

from item

order by ${orderByClause}

select

from item

where id = #{id,jdbcType=INTEGER}

delete from item

where id = #{id,jdbcType=INTEGER}

delete from item

insert into item (id, name, price,

detail, pic, createtime

)

values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{price,jdbcType=REAL},

#{detail,jdbcType=VARCHAR}, #{pic,jdbcType=VARCHAR}, #{createtime,jdbcType=TIMESTAMP}

)

insert into item

id,

name,

price,

detail,

pic,

createtime,

#{id,jdbcType=INTEGER},

#{name,jdbcType=VARCHAR},

#{price,jdbcType=REAL},

#{detail,jdbcType=VARCHAR},

#{pic,jdbcType=VARCHAR},

#{createtime,jdbcType=TIMESTAMP},

select count(*) from item

update item

id = #{record.id,jdbcType=INTEGER},

name = #{record.name,jdbcType=VARCHAR},

price = #{record.price,jdbcType=REAL},

detail = #{record.detail,jdbcType=VARCHAR},

pic = #{record.pic,jdbcType=VARCHAR},

createtime = #{record.createtime,jdbcType=TIMESTAMP},

update item

set id = #{record.id,jdbcType=INTEGER},

name = #{record.name,jdbcType=VARCHAR},

price = #{record.price,jdbcType=REAL},

detail = #{record.detail,jdbcType=VARCHAR},

pic = #{record.pic,jdbcType=VARCHAR},

createtime = #{record.createtime,jdbcType=TIMESTAMP}

update item

name = #{name,jdbcType=VARCHAR},

price = #{price,jdbcType=REAL},

detail = #{detail,jdbcType=VARCHAR},

pic = #{pic,jdbcType=VARCHAR},

createtime = #{createtime,jdbcType=TIMESTAMP},

where id = #{id,jdbcType=INTEGER}

update item

set name = #{name,jdbcType=VARCHAR},

price = #{price,jdbcType=REAL},

detail = #{detail,jdbcType=VARCHAR},

pic = #{pic,jdbcType=VARCHAR},

createtime = #{createtime,jdbcType=TIMESTAMP}

where id = #{id,jdbcType=INTEGER}

(3)创建UserMapper.java

在这里插入图片描述

package com.itzheng.springmvc.mapper;

import com.itzheng.springmvc.pojo.User;

import com.itzheng.springmvc.pojo.UserExample;

import java.util.List;

import org.apache.ibatis.annotations.Param;

public interface UserMapper {

int countByExample(UserExample example);

int deleteByExample(UserExample example);

int deleteByPrimaryKey(Integer id);

int insert(User record);

int insertSelective(User record);

List selectByExample(UserExample example);

User selectByPrimaryKey(Integer id);

int updateByExampleSelective(@Param(“record”) User record, @Param(“example”) UserExample example);

int updateByExample(@Param(“record”) User record, @Param(“example”) UserExample example);

int updateByPrimaryKeySelective(User record);

int updateByPrimaryKey(User record);

}

(4)创建UserMapper.xml

在这里插入图片描述

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

最后

最后,强调几点:

  • 1. 一定要谨慎对待写在简历上的东西,一定要对简历上的东西非常熟悉。因为一般情况下,面试官都是会根据你的简历来问的; 能有一个上得了台面的项目也非常重要,这很可能是面试官会大量发问的地方,所以在面试之前好好回顾一下自己所做的项目;
  • 2. 和面试官聊基础知识比如设计模式的使用、多线程的使用等等,可以结合具体的项目场景或者是自己在平时是如何使用的;
  • 3. 注意自己开源的Github项目,面试官可能会挖你的Github项目提问;

我个人觉得面试也像是一场全新的征程,失败和胜利都是平常之事。所以,劝各位不要因为面试失败而灰心、丧失斗志。也不要因为面试通过而沾沾自喜,等待你的将是更美好的未来,继续加油!

以上面试专题的答小编案整理成面试文档了,文档里有答案详解,以及其他一些大厂面试题目。

面试答案

三面头条+四面阿里+五面腾讯拿offer分享面经总结,最终入职阿里

三面头条+四面阿里+五面腾讯拿offer分享面经总结,最终入职阿里

三面头条+四面阿里+五面腾讯拿offer分享面经总结,最终入职阿里

《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》点击传送门,即可获取!
if>

update item

set id = #{record.id,jdbcType=INTEGER},

name = #{record.name,jdbcType=VARCHAR},

price = #{record.price,jdbcType=REAL},

detail = #{record.detail,jdbcType=VARCHAR},

pic = #{record.pic,jdbcType=VARCHAR},

createtime = #{record.createtime,jdbcType=TIMESTAMP}

update item

name = #{name,jdbcType=VARCHAR},

price = #{price,jdbcType=REAL},

detail = #{detail,jdbcType=VARCHAR},

pic = #{pic,jdbcType=VARCHAR},

createtime = #{createtime,jdbcType=TIMESTAMP},

where id = #{id,jdbcType=INTEGER}

update item

set name = #{name,jdbcType=VARCHAR},

price = #{price,jdbcType=REAL},

detail = #{detail,jdbcType=VARCHAR},

pic = #{pic,jdbcType=VARCHAR},

createtime = #{createtime,jdbcType=TIMESTAMP}

where id = #{id,jdbcType=INTEGER}

(3)创建UserMapper.java

在这里插入图片描述

package com.itzheng.springmvc.mapper;

import com.itzheng.springmvc.pojo.User;

import com.itzheng.springmvc.pojo.UserExample;

import java.util.List;

import org.apache.ibatis.annotations.Param;

public interface UserMapper {

int countByExample(UserExample example);

int deleteByExample(UserExample example);

int deleteByPrimaryKey(Integer id);

int insert(User record);

int insertSelective(User record);

List selectByExample(UserExample example);

User selectByPrimaryKey(Integer id);

int updateByExampleSelective(@Param(“record”) User record, @Param(“example”) UserExample example);

int updateByExample(@Param(“record”) User record, @Param(“example”) UserExample example);

int updateByPrimaryKeySelective(User record);

int updateByPrimaryKey(User record);

}

(4)创建UserMapper.xml

在这里插入图片描述

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

最后

最后,强调几点:

  • 1. 一定要谨慎对待写在简历上的东西,一定要对简历上的东西非常熟悉。因为一般情况下,面试官都是会根据你的简历来问的; 能有一个上得了台面的项目也非常重要,这很可能是面试官会大量发问的地方,所以在面试之前好好回顾一下自己所做的项目;
  • 2. 和面试官聊基础知识比如设计模式的使用、多线程的使用等等,可以结合具体的项目场景或者是自己在平时是如何使用的;
  • 3. 注意自己开源的Github项目,面试官可能会挖你的Github项目提问;

我个人觉得面试也像是一场全新的征程,失败和胜利都是平常之事。所以,劝各位不要因为面试失败而灰心、丧失斗志。也不要因为面试通过而沾沾自喜,等待你的将是更美好的未来,继续加油!

以上面试专题的答小编案整理成面试文档了,文档里有答案详解,以及其他一些大厂面试题目。

面试答案

[外链图片转存中…(img-8m1GFAHZ-1714762770678)]

[外链图片转存中…(img-Y2ISbCth-1714762770678)]

[外链图片转存中…(img-fcOxxuT5-1714762770678)]

《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》点击传送门,即可获取!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值