SSM框架制作完整版增删改查以及文件上传、下载和批量删除功能
一、jar包依赖
pom.xml
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<!--1.mybatis-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.6</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.5</version>
</dependency>
<!--逆向生成带分页的插件-->
<dependency>
<groupId>com.itfsw</groupId>
<artifactId>mybatis-generator-plugin</artifactId>
<version>1.0.5</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
<!--2.spring-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!--springMvc-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!--pojo转换成 json -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.7.3</version>
</dependency>
<!--jstl和tablib-->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<!--图片上传依赖-->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<!-- fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.47</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>SSM03</finalName>
<!--<pluginManagement>--><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/</path>
<port>8080</port>
<uriEncoding>UTF-8</uriEncoding>
</configuration>
</plugin>
</plugins>
<!-- </pluginManagement>-->
</build>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<!--全局 监听 骑马 异步走 servlet优先补充维生素C-->
<!--全局配置 与 监听器连用-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>ce</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<async-supported>true</async-supported>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>ce</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>ds</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:mvc/SpringMVC.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>ds</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
main包下的resources包,mark为resources包,在该包下建mvc包,存放SpringMVC.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--suppress SpringFacetInspection -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.controller"></context:component-scan>
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<constructor-arg value="UTF-8"></constructor-arg>
</bean>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"></bean>
</mvc:message-converters>
</mvc:annotation-driven>
<mvc:default-servlet-handler/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
main包下的resources包,mark为resources包,在该包下建立myBatis包,包中存放sqlMapConfig.xml
<?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>
<!--引入外部文件的标签 -->
<properties resource="properties/db.properties"></properties>
<settings>
<!-- 可以在控制台输出日志信息:sql语句和参数 -->
<setting name="logImpl" value="STDOUT_LOGGING"/>
</settings>
<!-- 表示类型别名 库-->
<typeAliases>
<!-- 每一个类型的别名 type属性表示别名对应的类型地址 alias表示起的别名-->
<typeAlias type="java.util.List" alias="list"/>
<!-- package表示包,利用包的形式进行扫描包之下的所有的类,别名就是当前类名 -->
<package name="com.pojo"/>
</typeAliases>
<!-- 分页插件 -->
<!-- <plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor"> 3.3.0版本可用 - 分页参数合理化,默认false禁用
pageNum表示当前页 pages表示尾页
true启用合理化时,如果pageNum<1会查询第一页,如果pageNum>pages会查询最后一页 false禁用合理化时,如果pageNum<1或pageNum>pages会返回空数据
<property name="reasonable" value="true"/>
</plugin>
</plugins>
-->
<!-- 环境配置 作为连接数据库的环境 -->
<environments default="mysql">
<environment id="mysql">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="${jdbc.driver}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</dataSource>
</environment>
</environments>
<!-- mappers表示代理模式扫描 ,目的主要是在当前配置文件中扫描到sql映射文件-->
<!--核心配置文件 关联 映射文件 -->
<!-- <mappers>
<mapper resource="mapper/Mapper.xml"/>
</mappers>-->
</configuration>
main包下的resources包,mark为resources包,在该包下建立properties包,包中存放db.properties文件
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/k9503?zeroDateTimeBehavior=convertToNull
jdbc.username=root
jdbc.password=123456
main包下的resources包,mark为resources包,在该包下建立spring包,包中存放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"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!--1、开启service层的注解-->
<context:component-scan base-package="com.service"/>
<!--2、加载db.properties-->
<context:property-placeholder location="classpath:properties/db.properties"/>
<!--3、数据源-->
<bean id="ds" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driver}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<!--4、事务管理-->
<bean id="tx" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="ds"></property>
</bean>
<!--5、开启事务的注解@Transactional-->
<tx:annotation-driven transaction-manager="tx"/>
<!--6、spring管理MyBatis-->
<bean id="fb" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="ds"/>
<property name="configLocation" value="classpath:mybatis/sqlMapConfig.xml"></property>
<property name="mapperLocations" value="classpath:mybatis/mapper/*.xml"></property>
</bean>
<!--7、让mapper接口和mapper.xml关联,即使不在同一个文件夹下,依然可以使用包扫描的形式,加载所有的映射文件-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.mapper"/><!--指定mapper接口的路径-->
<property name="sqlSessionFactoryBeanName" value="fb"/>
</bean>
<!--8.文件上传的配置-->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8"></property>
<property name="maxUploadSizePerFile" value="1048576"/><!--单个文件最大1M-->
<property name="maxUploadSize" value="10485760"/><!--一次性最大10M-->
</bean>
</beans>
二、java代码
在main包下创建一个名为java的包,标记为resouce包,包中创建controller、service以及test包
(扩充)逆向生成:
在test包中创建一个测试类Test1
package com.test;
import org.junit.Test;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class Test1 {
@Test
public void create() throws Exception {
List<String> warnings = new ArrayList<String>();
boolean overwrite = true;
File configFile = new File("mbg.xml");
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(configFile);
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
myBatisGenerator.generate(null);
}
}
配置mbg.xml,用于逆向生成
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<!-- 生成配置文件 -->
<generatorConfiguration>
<context id="DB2Tables" targetRuntime="MyBatis3">
<!--分页插件-->
<plugin type="com.itfsw.mybatis.generator.plugins.LimitPlugin"/>
<commentGenerator>
<!-- 是否去除注释,true表示是,false否 -->
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!-- 1.连接数据库信息 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/k9503?characterEncoding=UTF-8"
userId="root"
password="123456">
</jdbcConnection>
<!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和
NUMERIC 类型解析为java.math.BigDecimal -->
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!-- 2.pojo类的生成配置 targetPackage表示目标文件夹
targetProject表示当前目标文件夹所放置的目标地址
-->
<javaModelGenerator targetPackage="com.pojo" targetProject=".\src\main\java">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!-- 3.sql映射文件生成配置 -->
<sqlMapGenerator targetPackage="mybatis/mapper" targetProject=".\src\main\resources">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!-- 4.mapper接口配置 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.mapper" targetProject=".\src\main\java">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!-- 5.数据库表和实体类映射 -->
<table tableName="emp" domainObjectName="Emp">
</table>
<table tableName="dept" domainObjectName="Dept">
</table>
</context>
</generatorConfiguration>
逆向生成的文件:
java包下:mapper包、pojo包。resources包下的myBatis包下:mapper包
mapper包下的DeptMapper接口
package com.mapper;
import com.pojo.Dept;
import com.pojo.DeptExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface DeptMapper {
long countByExample(DeptExample example);
int deleteByExample(DeptExample example);
int deleteByPrimaryKey(Integer deptid);
int insert(Dept record);
int insertSelective(Dept record);
List<Dept> selectByExample(DeptExample example);
Dept selectByPrimaryKey(Integer deptid);
int updateByExampleSelective(@Param("record") Dept record, @Param("example") DeptExample example);
int updateByExample(@Param("record") Dept record, @Param("example") DeptExample example);
int updateByPrimaryKeySelective(Dept record);
int updateByPrimaryKey(Dept record);
}
EmpMapper
package com.mapper;
import com.pojo.Emp;
import com.pojo.EmpExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface EmpMapper {
long countByExample(EmpExample example);
int deleteByExample(EmpExample example);
int deleteByPrimaryKey(Integer id);
int insert(Emp record);
int insertSelective(Emp record);
List<Emp> selectByExample(EmpExample example);
Emp selectByPrimaryKey(Integer id);
int updateByExampleSelective(@Param("record") Emp record, @Param("example") EmpExample example);
int updateByExample(@Param("record") Emp record, @Param("example") EmpExample example);
int updateByPrimaryKeySelective(Emp record);
int updateByPrimaryKey(Emp record);
}
pojo包下的Dept
package com.pojo;
public class Dept {
private Integer deptid;
private String dep;
public Integer getDeptid() {
return deptid;
}
public void setDeptid(Integer deptid) {
this.deptid = deptid;
}
public String getDep() {
return dep;
}
public void setDep(String dep) {
this.dep = dep == null ? null : dep.trim();
}
}
Emp
package com.pojo;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
public class Emp {
private Integer id;
private String name;
private Integer age;
private String sex;
private Double salary;
private Double bonus;
@DateTimeFormat(iso= DateTimeFormat.ISO.DATE)
private Date birth;
@DateTimeFormat(iso= DateTimeFormat.ISO.DATE)
private Date hiredate;
private Integer leader;
private Integer deptid;
private String imgurl;
private Dept dept;
public Dept getDept() {
return dept;
}
public void setDept(Dept dept) {
this.dept = dept;
}
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 Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex == null ? null : sex.trim();
}
public Double getSalary() {
return salary;
}
public void setSalary(Double salary) {
this.salary = salary;
}
public Double getBonus() {
return bonus;
}
public void setBonus(Double bonus) {
this.bonus = bonus;
}
public Date getBirth() {
return birth;
}
public void setBirth(Date birth) {
this.birth = birth;
}
public Date getHiredate() {
return hiredate;
}
public void setHiredate(Date hiredate) {
this.hiredate = hiredate;
}
public Integer getLeader() {
return leader;
}
public void setLeader(Integer leader) {
this.leader = leader;
}
public Integer getDeptid() {
return deptid;
}
public void setDeptid(Integer deptid) {
this.deptid = deptid;
}
public String getImgurl() {
return imgurl;
}
public void setImgurl(String imgurl) {
this.imgurl = imgurl == null ? null : imgurl.trim();
}
}
配置条件的EmpExample
package com.pojo;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
public class EmpExample {
protected String orderByClause;
protected boolean distinct;
protected List<Criteria> oredCriteria;
/**
* 这是Mybatis Generator拓展插件生成的属性(请勿删除).
* This field corresponds to the database table emp
*
* @mbg.generated
* @author hewei
*/
protected Integer offset;
/**
* 这是Mybatis Generator拓展插件生成的属性(请勿删除).
* This field corresponds to the database table emp
*
* @mbg.generated
* @author hewei
*/
protected Integer rows;
public EmpExample() {
oredCriteria = new ArrayList<Criteria>();
}
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<Criteria> 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;
rows = null;
offset = null;
}
/**
* 这是Mybatis Generator拓展插件生成的方法(请勿删除).
* This method corresponds to the database table emp
*
* @mbg.generated
* @author hewei
*/
public void setOffset(Integer offset) {
this.offset = offset;
}
/**
* 这是Mybatis Generator拓展插件生成的方法(请勿删除).
* This method corresponds to the database table emp
*
* @mbg.generated
* @author hewei
*/
public Integer getOffset() {
return offset;
}
/**
* 这是Mybatis Generator拓展插件生成的方法(请勿删除).
* This method corresponds to the database table emp
*
* @mbg.generated
* @author hewei
*/
public void setRows(Integer rows) {
this.rows = rows;
}
/**
* 这是Mybatis Generator拓展插件生成的方法(请勿删除).
* This method corresponds to the database table emp
*
* @mbg.generated
* @author hewei
*/
public Integer getRows() {
return rows;
}
/**
* 这是Mybatis Generator拓展插件生成的方法(请勿删除).
* This method corresponds to the database table emp
*
* @mbg.generated
* @author hewei
*/
public EmpExample limit(Integer rows) {
this.rows = rows;
return this;
}
/**
* 这是Mybatis Generator拓展插件生成的方法(请勿删除).
* This method corresponds to the database table emp
*
* @mbg.generated
* @author hewei
*/
public EmpExample limit(Integer offset, Integer rows) {
this.offset = offset;
this.rows = rows;
return this;
}
/**
* 这是Mybatis Generator拓展插件生成的方法(请勿删除).
* This method corresponds to the database table emp
*
* @mbg.generated
* @author hewei
*/
public EmpExample page(Integer page, Integer pageSize) {
this.offset = page * pageSize;
this.rows = pageSize;
return this;
}
protected abstract static class GeneratedCriteria {
protected List<Criterion> criteria;
protected GeneratedCriteria() {
super();
criteria = new ArrayList<Criterion>();
}
public boolean isValid() {
return criteria.size() > 0;
}
public List<Criterion> getAllCriteria() {
return criteria;
}
public List<Criterion> 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<Date> 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<Date> 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<Integer> values) {
addCriterion("id in", values, "id");
return (Criteria) this;
}
public Criteria andIdNotIn(List<Integer> 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<String> values) {
addCriterion("name in", values, "name");
return (Criteria) this;
}
public Criteria andNameNotIn(List<String> 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 andAgeIsNull() {
addCriterion("age is null");
return (Criteria) this;
}
public Criteria andAgeIsNotNull() {
addCriterion("age is not null");
return (Criteria) this;
}
public Criteria andAgeEqualTo(Integer value) {
addCriterion("age =", value, "age");
return (Criteria) this;
}
public Criteria andAgeNotEqualTo(Integer value) {
addCriterion("age <>", value, "age");
return (Criteria) this;
}
public Criteria andAgeGreaterThan(Integer value) {
addCriterion("age >", value, "age");
return (Criteria) this;
}
public Criteria andAgeGreaterThanOrEqualTo(Integer value) {
addCriterion("age >=", value, "age");
return (Criteria) this;
}
public Criteria andAgeLessThan(Integer value) {
addCriterion("age <", value, "age");
return (Criteria) this;
}
public Criteria andAgeLessThanOrEqualTo(Integer value) {
addCriterion("age <=", value, "age");
return (Criteria) this;
}
public Criteria andAgeIn(List<Integer> values) {
addCriterion("age in", values, "age");
return (Criteria) this;
}
public Criteria andAgeNotIn(List<Integer> values) {
addCriterion("age not in", values, "age");
return (Criteria) this;
}
public Criteria andAgeBetween(Integer value1, Integer value2) {
addCriterion("age between", value1, value2, "age");
return (Criteria) this;
}
public Criteria andAgeNotBetween(Integer value1, Integer value2) {
addCriterion("age not between", value1, value2, "age");
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<String> values) {
addCriterion("sex in", values, "sex");
return (Criteria) this;
}
public Criteria andSexNotIn(List<String> 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 andSalaryIsNull() {
addCriterion("salary is null");
return (Criteria) this;
}
public Criteria andSalaryIsNotNull() {
addCriterion("salary is not null");
return (Criteria) this;
}
public Criteria andSalaryEqualTo(Double value) {
addCriterion("salary =", value, "salary");
return (Criteria) this;
}
public Criteria andSalaryNotEqualTo(Double value) {
addCriterion("salary <>", value, "salary");
return (Criteria) this;
}
public Criteria andSalaryGreaterThan(Double value) {
addCriterion("salary >", value, "salary");
return (Criteria) this;
}
public Criteria andSalaryGreaterThanOrEqualTo(Double value) {
addCriterion("salary >=", value, "salary");
return (Criteria) this;
}
public Criteria andSalaryLessThan(Double value) {
addCriterion("salary <", value, "salary");
return (Criteria) this;
}
public Criteria andSalaryLessThanOrEqualTo(Double value) {
addCriterion("salary <=", value, "salary");
return (Criteria) this;
}
public Criteria andSalaryIn(List<Double> values) {
addCriterion("salary in", values, "salary");
return (Criteria) this;
}
public Criteria andSalaryNotIn(List<Double> values) {
addCriterion("salary not in", values, "salary");
return (Criteria) this;
}
public Criteria andSalaryBetween(Double value1, Double value2) {
addCriterion("salary between", value1, value2, "salary");
return (Criteria) this;
}
public Criteria andSalaryNotBetween(Double value1, Double value2) {
addCriterion("salary not between", value1, value2, "salary");
return (Criteria) this;
}
public Criteria andBonusIsNull() {
addCriterion("bonus is null");
return (Criteria) this;
}
public Criteria andBonusIsNotNull() {
addCriterion("bonus is not null");
return (Criteria) this;
}
public Criteria andBonusEqualTo(Double value) {
addCriterion("bonus =", value, "bonus");
return (Criteria) this;
}
public Criteria andBonusNotEqualTo(Double value) {
addCriterion("bonus <>", value, "bonus");
return (Criteria) this;
}
public Criteria andBonusGreaterThan(Double value) {
addCriterion("bonus >", value, "bonus");
return (Criteria) this;
}
public Criteria andBonusGreaterThanOrEqualTo(Double value) {
addCriterion("bonus >=", value, "bonus");
return (Criteria) this;
}
public Criteria andBonusLessThan(Double value) {
addCriterion("bonus <", value, "bonus");
return (Criteria) this;
}
public Criteria andBonusLessThanOrEqualTo(Double value) {
addCriterion("bonus <=", value, "bonus");
return (Criteria) this;
}
public Criteria andBonusIn(List<Double> values) {
addCriterion("bonus in", values, "bonus");
return (Criteria) this;
}
public Criteria andBonusNotIn(List<Double> values) {
addCriterion("bonus not in", values, "bonus");
return (Criteria) this;
}
public Criteria andBonusBetween(Double value1, Double value2) {
addCriterion("bonus between", value1, value2, "bonus");
return (Criteria) this;
}
public Criteria andBonusNotBetween(Double value1, Double value2) {
addCriterion("bonus not between", value1, value2, "bonus");
return (Criteria) this;
}
public Criteria andBirthIsNull() {
addCriterion("birth is null");
return (Criteria) this;
}
public Criteria andBirthIsNotNull() {
addCriterion("birth is not null");
return (Criteria) this;
}
public Criteria andBirthEqualTo(Date value) {
addCriterionForJDBCDate("birth =", value, "birth");
return (Criteria) this;
}
public Criteria andBirthNotEqualTo(Date value) {
addCriterionForJDBCDate("birth <>", value, "birth");
return (Criteria) this;
}
public Criteria andBirthGreaterThan(Date value) {
addCriterionForJDBCDate("birth >", value, "birth");
return (Criteria) this;
}
public Criteria andBirthGreaterThanOrEqualTo(Date value) {
addCriterionForJDBCDate("birth >=", value, "birth");
return (Criteria) this;
}
public Criteria andBirthLessThan(Date value) {
addCriterionForJDBCDate("birth <", value, "birth");
return (Criteria) this;
}
public Criteria andBirthLessThanOrEqualTo(Date value) {
addCriterionForJDBCDate("birth <=", value, "birth");
return (Criteria) this;
}
public Criteria andBirthIn(List<Date> values) {
addCriterionForJDBCDate("birth in", values, "birth");
return (Criteria) this;
}
public Criteria andBirthNotIn(List<Date> values) {
addCriterionForJDBCDate("birth not in", values, "birth");
return (Criteria) this;
}
public Criteria andBirthBetween(Date value1, Date value2) {
addCriterionForJDBCDate("birth between", value1, value2, "birth");
return (Criteria) this;
}
public Criteria andBirthNotBetween(Date value1, Date value2) {
addCriterionForJDBCDate("birth not between", value1, value2, "birth");
return (Criteria) this;
}
public Criteria andHiredateIsNull() {
addCriterion("hiredate is null");
return (Criteria) this;
}
public Criteria andHiredateIsNotNull() {
addCriterion("hiredate is not null");
return (Criteria) this;
}
public Criteria andHiredateEqualTo(Date value) {
addCriterionForJDBCDate("hiredate =", value, "hiredate");
return (Criteria) this;
}
public Criteria andHiredateNotEqualTo(Date value) {
addCriterionForJDBCDate("hiredate <>", value, "hiredate");
return (Criteria) this;
}
public Criteria andHiredateGreaterThan(Date value) {
addCriterionForJDBCDate("hiredate >", value, "hiredate");
return (Criteria) this;
}
public Criteria andHiredateGreaterThanOrEqualTo(Date value) {
addCriterionForJDBCDate("hiredate >=", value, "hiredate");
return (Criteria) this;
}
public Criteria andHiredateLessThan(Date value) {
addCriterionForJDBCDate("hiredate <", value, "hiredate");
return (Criteria) this;
}
public Criteria andHiredateLessThanOrEqualTo(Date value) {
addCriterionForJDBCDate("hiredate <=", value, "hiredate");
return (Criteria) this;
}
public Criteria andHiredateIn(List<Date> values) {
addCriterionForJDBCDate("hiredate in", values, "hiredate");
return (Criteria) this;
}
public Criteria andHiredateNotIn(List<Date> values) {
addCriterionForJDBCDate("hiredate not in", values, "hiredate");
return (Criteria) this;
}
public Criteria andHiredateBetween(Date value1, Date value2) {
addCriterionForJDBCDate("hiredate between", value1, value2, "hiredate");
return (Criteria) this;
}
public Criteria andHiredateNotBetween(Date value1, Date value2) {
addCriterionForJDBCDate("hiredate not between", value1, value2, "hiredate");
return (Criteria) this;
}
public Criteria andLeaderIsNull() {
addCriterion("leader is null");
return (Criteria) this;
}
public Criteria andLeaderIsNotNull() {
addCriterion("leader is not null");
return (Criteria) this;
}
public Criteria andLeaderEqualTo(Integer value) {
addCriterion("leader =", value, "leader");
return (Criteria) this;
}
public Criteria andLeaderNotEqualTo(Integer value) {
addCriterion("leader <>", value, "leader");
return (Criteria) this;
}
public Criteria andLeaderGreaterThan(Integer value) {
addCriterion("leader >", value, "leader");
return (Criteria) this;
}
public Criteria andLeaderGreaterThanOrEqualTo(Integer value) {
addCriterion("leader >=", value, "leader");
return (Criteria) this;
}
public Criteria andLeaderLessThan(Integer value) {
addCriterion("leader <", value, "leader");
return (Criteria) this;
}
public Criteria andLeaderLessThanOrEqualTo(Integer value) {
addCriterion("leader <=", value, "leader");
return (Criteria) this;
}
public Criteria andLeaderIn(List<Integer> values) {
addCriterion("leader in", values, "leader");
return (Criteria) this;
}
public Criteria andLeaderNotIn(List<Integer> values) {
addCriterion("leader not in", values, "leader");
return (Criteria) this;
}
public Criteria andLeaderBetween(Integer value1, Integer value2) {
addCriterion("leader between", value1, value2, "leader");
return (Criteria) this;
}
public Criteria andLeaderNotBetween(Integer value1, Integer value2) {
addCriterion("leader not between", value1, value2, "leader");
return (Criteria) this;
}
public Criteria andDeptidIsNull() {
addCriterion("deptId is null");
return (Criteria) this;
}
public Criteria andDeptidIsNotNull() {
addCriterion("deptId is not null");
return (Criteria) this;
}
public Criteria andDeptidEqualTo(Integer value) {
addCriterion("deptId =", value, "deptid");
return (Criteria) this;
}
public Criteria andDeptidNotEqualTo(Integer value) {
addCriterion("deptId <>", value, "deptid");
return (Criteria) this;
}
public Criteria andDeptidGreaterThan(Integer value) {
addCriterion("deptId >", value, "deptid");
return (Criteria) this;
}
public Criteria andDeptidGreaterThanOrEqualTo(Integer value) {
addCriterion("deptId >=", value, "deptid");
return (Criteria) this;
}
public Criteria andDeptidLessThan(Integer value) {
addCriterion("deptId <", value, "deptid");
return (Criteria) this;
}
public Criteria andDeptidLessThanOrEqualTo(Integer value) {
addCriterion("deptId <=", value, "deptid");
return (Criteria) this;
}
public Criteria andDeptidIn(List<Integer> values) {
addCriterion("deptId in", values, "deptid");
return (Criteria) this;
}
public Criteria andDeptidNotIn(List<Integer> values) {
addCriterion("deptId not in", values, "deptid");
return (Criteria) this;
}
public Criteria andDeptidBetween(Integer value1, Integer value2) {
addCriterion("deptId between", value1, value2, "deptid");
return (Criteria) this;
}
public Criteria andDeptidNotBetween(Integer value1, Integer value2) {
addCriterion("deptId not between", value1, value2, "deptid");
return (Criteria) this;
}
public Criteria andImgurlIsNull() {
addCriterion("imgUrl is null");
return (Criteria) this;
}
public Criteria andImgurlIsNotNull() {
addCriterion("imgUrl is not null");
return (Criteria) this;
}
public Criteria andImgurlEqualTo(String value) {
addCriterion("imgUrl =", value, "imgurl");
return (Criteria) this;
}
public Criteria andImgurlNotEqualTo(String value) {
addCriterion("imgUrl <>", value, "imgurl");
return (Criteria) this;
}
public Criteria andImgurlGreaterThan(String value) {
addCriterion("imgUrl >", value, "imgurl");
return (Criteria) this;
}
public Criteria andImgurlGreaterThanOrEqualTo(String value) {
addCriterion("imgUrl >=", value, "imgurl");
return (Criteria) this;
}
public Criteria andImgurlLessThan(String value) {
addCriterion("imgUrl <", value, "imgurl");
return (Criteria) this;
}
public Criteria andImgurlLessThanOrEqualTo(String value) {
addCriterion("imgUrl <=", value, "imgurl");
return (Criteria) this;
}
public Criteria andImgurlLike(String value) {
addCriterion("imgUrl like", value, "imgurl");
return (Criteria) this;
}
public Criteria andImgurlNotLike(String value) {
addCriterion("imgUrl not like", value, "imgurl");
return (Criteria) this;
}
public Criteria andImgurlIn(List<String> values) {
addCriterion("imgUrl in", values, "imgurl");
return (Criteria) this;
}
public Criteria andImgurlNotIn(List<String> values) {
addCriterion("imgUrl not in", values, "imgurl");
return (Criteria) this;
}
public Criteria andImgurlBetween(String value1, String value2) {
addCriterion("imgUrl between", value1, value2, "imgurl");
return (Criteria) this;
}
public Criteria andImgurlNotBetween(String value1, String value2) {
addCriterion("imgUrl not between", value1, value2, "imgurl");
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);
}
}
}
DeptExamper
package com.pojo;
import java.util.ArrayList;
import java.util.List;
public class DeptExample {
protected String orderByClause;
protected boolean distinct;
protected List<Criteria> oredCriteria;
/**
* 这是Mybatis Generator拓展插件生成的属性(请勿删除).
* This field corresponds to the database table dept
*
* @mbg.generated
* @author hewei
*/
protected Integer offset;
/**
* 这是Mybatis Generator拓展插件生成的属性(请勿删除).
* This field corresponds to the database table dept
*
* @mbg.generated
* @author hewei
*/
protected Integer rows;
public DeptExample() {
oredCriteria = new ArrayList<Criteria>();
}
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<Criteria> 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;
rows = null;
offset = null;
}
/**
* 这是Mybatis Generator拓展插件生成的方法(请勿删除).
* This method corresponds to the database table dept
*
* @mbg.generated
* @author hewei
*/
public void setOffset(Integer offset) {
this.offset = offset;
}
/**
* 这是Mybatis Generator拓展插件生成的方法(请勿删除).
* This method corresponds to the database table dept
*
* @mbg.generated
* @author hewei
*/
public Integer getOffset() {
return offset;
}
/**
* 这是Mybatis Generator拓展插件生成的方法(请勿删除).
* This method corresponds to the database table dept
*
* @mbg.generated
* @author hewei
*/
public void setRows(Integer rows) {
this.rows = rows;
}
/**
* 这是Mybatis Generator拓展插件生成的方法(请勿删除).
* This method corresponds to the database table dept
*
* @mbg.generated
* @author hewei
*/
public Integer getRows() {
return rows;
}
/**
* 这是Mybatis Generator拓展插件生成的方法(请勿删除).
* This method corresponds to the database table dept
*
* @mbg.generated
* @author hewei
*/
public DeptExample limit(Integer rows) {
this.rows = rows;
return this;
}
/**
* 这是Mybatis Generator拓展插件生成的方法(请勿删除).
* This method corresponds to the database table dept
*
* @mbg.generated
* @author hewei
*/
public DeptExample limit(Integer offset, Integer rows) {
this.offset = offset;
this.rows = rows;
return this;
}
/**
* 这是Mybatis Generator拓展插件生成的方法(请勿删除).
* This method corresponds to the database table dept
*
* @mbg.generated
* @author hewei
*/
public DeptExample page(Integer page, Integer pageSize) {
this.offset = page * pageSize;
this.rows = pageSize;
return this;
}
protected abstract static class GeneratedCriteria {
protected List<Criterion> criteria;
protected GeneratedCriteria() {
super();
criteria = new ArrayList<Criterion>();
}
public boolean isValid() {
return criteria.size() > 0;
}
public List<Criterion> getAllCriteria() {
return criteria;
}
public List<Criterion> 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 andDeptidIsNull() {
addCriterion("deptid is null");
return (Criteria) this;
}
public Criteria andDeptidIsNotNull() {
addCriterion("deptid is not null");
return (Criteria) this;
}
public Criteria andDeptidEqualTo(Integer value) {
addCriterion("deptid =", value, "deptid");
return (Criteria) this;
}
public Criteria andDeptidNotEqualTo(Integer value) {
addCriterion("deptid <>", value, "deptid");
return (Criteria) this;
}
public Criteria andDeptidGreaterThan(Integer value) {
addCriterion("deptid >", value, "deptid");
return (Criteria) this;
}
public Criteria andDeptidGreaterThanOrEqualTo(Integer value) {
addCriterion("deptid >=", value, "deptid");
return (Criteria) this;
}
public Criteria andDeptidLessThan(Integer value) {
addCriterion("deptid <", value, "deptid");
return (Criteria) this;
}
public Criteria andDeptidLessThanOrEqualTo(Integer value) {
addCriterion("deptid <=", value, "deptid");
return (Criteria) this;
}
public Criteria andDeptidIn(List<Integer> values) {
addCriterion("deptid in", values, "deptid");
return (Criteria) this;
}
public Criteria andDeptidNotIn(List<Integer> values) {
addCriterion("deptid not in", values, "deptid");
return (Criteria) this;
}
public Criteria andDeptidBetween(Integer value1, Integer value2) {
addCriterion("deptid between", value1, value2, "deptid");
return (Criteria) this;
}
public Criteria andDeptidNotBetween(Integer value1, Integer value2) {
addCriterion("deptid not between", value1, value2, "deptid");
return (Criteria) this;
}
public Criteria andDepIsNull() {
addCriterion("dep is null");
return (Criteria) this;
}
public Criteria andDepIsNotNull() {
addCriterion("dep is not null");
return (Criteria) this;
}
public Criteria andDepEqualTo(String value) {
addCriterion("dep =", value, "dep");
return (Criteria) this;
}
public Criteria andDepNotEqualTo(String value) {
addCriterion("dep <>", value, "dep");
return (Criteria) this;
}
public Criteria andDepGreaterThan(String value) {
addCriterion("dep >", value, "dep");
return (Criteria) this;
}
public Criteria andDepGreaterThanOrEqualTo(String value) {
addCriterion("dep >=", value, "dep");
return (Criteria) this;
}
public Criteria andDepLessThan(String value) {
addCriterion("dep <", value, "dep");
return (Criteria) this;
}
public Criteria andDepLessThanOrEqualTo(String value) {
addCriterion("dep <=", value, "dep");
return (Criteria) this;
}
public Criteria andDepLike(String value) {
addCriterion("dep like", value, "dep");
return (Criteria) this;
}
public Criteria andDepNotLike(String value) {
addCriterion("dep not like", value, "dep");
return (Criteria) this;
}
public Criteria andDepIn(List<String> values) {
addCriterion("dep in", values, "dep");
return (Criteria) this;
}
public Criteria andDepNotIn(List<String> values) {
addCriterion("dep not in", values, "dep");
return (Criteria) this;
}
public Criteria andDepBetween(String value1, String value2) {
addCriterion("dep between", value1, value2, "dep");
return (Criteria) this;
}
public Criteria andDepNotBetween(String value1, String value2) {
addCriterion("dep not between", value1, value2, "dep");
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);
}
}
}
pageBean
package com.pojo;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
public class PageBean {
private int currPage = 1;
private int totalPage;
private int size = 4;
private int count;
private String name;
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private Date startBirth;
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private Date endBirth;
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private Integer deptId;
public Integer getDeptId() {
return deptId;
}
public void setDeptId(Integer deptId) {
this.deptId = deptId;
}
public int getCurrPage() {
return currPage;
}
public void setCurrPage(int currPage) {
this.currPage = currPage;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name==null?null:name.trim();
}
public Date getStartBirth() {
return startBirth;
}
public void setStartBirth(Date startBirth) {
this.startBirth = startBirth;
}
public Date getEndBirth() {
return endBirth;
}
public void setEndBirth(Date endBirth) {
this.endBirth = endBirth;
}
}
mybatis包下的mapper包中逆向生成的EmpExample.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.mapper.EmpMapper">
<resultMap id="BaseResultMap" type="com.pojo.Emp">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="age" jdbcType="INTEGER" property="age" />
<result column="sex" jdbcType="VARCHAR" property="sex" />
<result column="salary" jdbcType="DOUBLE" property="salary" />
<result column="bonus" jdbcType="DOUBLE" property="bonus" />
<result column="birth" jdbcType="DATE" property="birth" />
<result column="hiredate" jdbcType="DATE" property="hiredate" />
<result column="leader" jdbcType="INTEGER" property="leader" />
<result column="deptId" jdbcType="INTEGER" property="deptid" />
<result column="imgUrl" jdbcType="VARCHAR" property="imgurl" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
id, name, age, sex, salary, bonus, birth, hiredate, leader, deptId, imgUrl
</sql>
<select id="selectByExample" parameterType="com.pojo.EmpExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from emp
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
<if test="rows != null">
<if test="offset != null">
limit ${offset}, ${rows}
</if>
<if test="offset == null">
limit ${rows}
</if>
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from emp
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from emp
where id = #{id,jdbcType=INTEGER}
</delete>
<delete id="deleteByExample" parameterType="com.pojo.EmpExample">
delete from emp
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="com.pojo.Emp">
insert into emp (id, name, age,
sex, salary, bonus, birth,
hiredate, leader, deptId,
imgUrl)
values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{age,jdbcType=INTEGER},
#{sex,jdbcType=VARCHAR}, #{salary,jdbcType=DOUBLE}, #{bonus,jdbcType=DOUBLE}, #{birth,jdbcType=DATE},
#{hiredate,jdbcType=DATE}, #{leader,jdbcType=INTEGER}, #{deptid,jdbcType=INTEGER},
#{imgurl,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.pojo.Emp">
insert into emp
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="name != null">
name,
</if>
<if test="age != null">
age,
</if>
<if test="sex != null">
sex,
</if>
<if test="salary != null">
salary,
</if>
<if test="bonus != null">
bonus,
</if>
<if test="birth != null">
birth,
</if>
<if test="hiredate != null">
hiredate,
</if>
<if test="leader != null">
leader,
</if>
<if test="deptid != null">
deptId,
</if>
<if test="imgurl != null">
imgUrl,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="age != null">
#{age,jdbcType=INTEGER},
</if>
<if test="sex != null">
#{sex,jdbcType=VARCHAR},
</if>
<if test="salary != null">
#{salary,jdbcType=DOUBLE},
</if>
<if test="bonus != null">
#{bonus,jdbcType=DOUBLE},
</if>
<if test="birth != null">
#{birth,jdbcType=DATE},
</if>
<if test="hiredate != null">
#{hiredate,jdbcType=DATE},
</if>
<if test="leader != null">
#{leader,jdbcType=INTEGER},
</if>
<if test="deptid != null">
#{deptid,jdbcType=INTEGER},
</if>
<if test="imgurl != null">
#{imgurl,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.pojo.EmpExample" resultType="java.lang.Long">
select count(*) from emp
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update emp
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=INTEGER},
</if>
<if test="record.name != null">
name = #{record.name,jdbcType=VARCHAR},
</if>
<if test="record.age != null">
age = #{record.age,jdbcType=INTEGER},
</if>
<if test="record.sex != null">
sex = #{record.sex,jdbcType=VARCHAR},
</if>
<if test="record.salary != null">
salary = #{record.salary,jdbcType=DOUBLE},
</if>
<if test="record.bonus != null">
bonus = #{record.bonus,jdbcType=DOUBLE},
</if>
<if test="record.birth != null">
birth = #{record.birth,jdbcType=DATE},
</if>
<if test="record.hiredate != null">
hiredate = #{record.hiredate,jdbcType=DATE},
</if>
<if test="record.leader != null">
leader = #{record.leader,jdbcType=INTEGER},
</if>
<if test="record.deptid != null">
deptId = #{record.deptid,jdbcType=INTEGER},
</if>
<if test="record.imgurl != null">
imgUrl = #{record.imgurl,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
update emp
set id = #{record.id,jdbcType=INTEGER},
name = #{record.name,jdbcType=VARCHAR},
age = #{record.age,jdbcType=INTEGER},
sex = #{record.sex,jdbcType=VARCHAR},
salary = #{record.salary,jdbcType=DOUBLE},
bonus = #{record.bonus,jdbcType=DOUBLE},
birth = #{record.birth,jdbcType=DATE},
hiredate = #{record.hiredate,jdbcType=DATE},
leader = #{record.leader,jdbcType=INTEGER},
deptId = #{record.deptid,jdbcType=INTEGER},
imgUrl = #{record.imgurl,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.pojo.Emp">
update emp
<set>
<if test="name != null">
name = #{name,jdbcType=VARCHAR},
</if>
<if test="age != null">
age = #{age,jdbcType=INTEGER},
</if>
<if test="sex != null">
sex = #{sex,jdbcType=VARCHAR},
</if>
<if test="salary != null">
salary = #{salary,jdbcType=DOUBLE},
</if>
<if test="bonus != null">
bonus = #{bonus,jdbcType=DOUBLE},
</if>
<if test="birth != null">
birth = #{birth,jdbcType=DATE},
</if>
<if test="hiredate != null">
hiredate = #{hiredate,jdbcType=DATE},
</if>
<if test="leader != null">
leader = #{leader,jdbcType=INTEGER},
</if>
<if test="deptid != null">
deptId = #{deptid,jdbcType=INTEGER},
</if>
<if test="imgurl != null">
imgUrl = #{imgurl,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.pojo.Emp">
update emp
set name = #{name,jdbcType=VARCHAR},
age = #{age,jdbcType=INTEGER},
sex = #{sex,jdbcType=VARCHAR},
salary = #{salary,jdbcType=DOUBLE},
bonus = #{bonus,jdbcType=DOUBLE},
birth = #{birth,jdbcType=DATE},
hiredate = #{hiredate,jdbcType=DATE},
leader = #{leader,jdbcType=INTEGER},
deptId = #{deptid,jdbcType=INTEGER},
imgUrl = #{imgurl,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
mybatis包下的mapper包中逆向生成的DeptExample.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.mapper.DeptMapper">
<resultMap id="BaseResultMap" type="com.pojo.Dept">
<id column="deptid" jdbcType="INTEGER" property="deptid" />
<result column="dep" jdbcType="VARCHAR" property="dep" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
deptid, dep
</sql>
<select id="selectByExample" parameterType="com.pojo.DeptExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from dept
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
<if test="rows != null">
<if test="offset != null">
limit ${offset}, ${rows}
</if>
<if test="offset == null">
limit ${rows}
</if>
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from dept
where deptid = #{deptid,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from dept
where deptid = #{deptid,jdbcType=INTEGER}
</delete>
<delete id="deleteByExample" parameterType="com.pojo.DeptExample">
delete from dept
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="com.pojo.Dept">
insert into dept (deptid, dep)
values (#{deptid,jdbcType=INTEGER}, #{dep,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.pojo.Dept">
insert into dept
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="deptid != null">
deptid,
</if>
<if test="dep != null">
dep,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="deptid != null">
#{deptid,jdbcType=INTEGER},
</if>
<if test="dep != null">
#{dep,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.pojo.DeptExample" resultType="java.lang.Long">
select count(*) from dept
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update dept
<set>
<if test="record.deptid != null">
deptid = #{record.deptid,jdbcType=INTEGER},
</if>
<if test="record.dep != null">
dep = #{record.dep,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
update dept
set deptid = #{record.deptid,jdbcType=INTEGER},
dep = #{record.dep,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.pojo.Dept">
update dept
<set>
<if test="dep != null">
dep = #{dep,jdbcType=VARCHAR},
</if>
</set>
where deptid = #{deptid,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.pojo.Dept">
update dept
set dep = #{dep,jdbcType=VARCHAR}
where deptid = #{deptid,jdbcType=INTEGER}
</update>
</mapper>
以上是逆向生成的文件
需自己建立的文件如下:
EmpController(controller包下)
package com.controller;
import com.pojo.Dept;
import com.pojo.Emp;
import com.pojo.PageBean;
import com.service.IEmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;
@Controller
@RequestMapping("/emp")
public class EmpController {
@Autowired
private IEmpService service;
@RequestMapping("/show")
public ModelAndView show(PageBean page, ModelAndView mav){
//取
//模糊分页条件查询所有员工
List<Emp> list=service.selectLikePage(page);
//查询下拉框中的所有部门
List<Dept> depts=service.selectDepts();
//存进request域中
mav.addObject("list",list);
mav.addObject("depts",depts);
mav.addObject("page",page);
//转
mav.setViewName("show");
return mav;
}
//新增页面跳转
@RequestMapping("/add1")
public String add1(Model m){
//查询所有的部门--中下拉框展示所有的部门
List<Dept> depts=service.selectDepts();
m.addAttribute("depts",depts);
return "add";
}
//实现新增
@RequestMapping("/add2")
public String add2(Emp emp){
int i=service.addEmp(emp);
return "redirect:/emp/show";//去show方法 重查
}
//1.查询单条 2.页面跳转
@RequestMapping("/update1/{id}")
public String update1(@PathVariable String id, Model m){
Emp e=service.selectById(Integer.parseInt(id));
m.addAttribute("emp",e);
//查询所有的部门--中下拉框展示所有的部门
List<Dept> depts=service.selectDepts();
m.addAttribute("depts",depts);
return "update";//转发到update.jsp
}
//执行修改
@RequestMapping("/update2")
public String update2(Emp emp){
int i=service.updateEmp(emp);
return "redirect:/emp/show";//去show方法 重查
}
@RequestMapping("/deleteById/{id}")
public String deleteById(@PathVariable String id){
int i=service.deleteById(Integer.parseInt(id));
//删除后重查数据库
return "redirect:/emp/show";//去show方法 重查
}
}
EmpController2(controller包下)
package com.controller;
import com.alibaba.fastjson.JSON;
import com.service.IEmpService;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.UUID;
@Controller
@RequestMapping("/emp2")
public class EmpController2 {
@Autowired
private IEmpService service;
//处理图片上传
@RequestMapping("/upload")
@ResponseBody
public String upload(MultipartFile mf, HttpSession session){
//1.图片上传放在哪里? 服务器路径
String realPath = session.getServletContext().getRealPath("/imgs");
System.out.println(realPath);
//2.获取图片的名称
String fname = mf.getOriginalFilename();
//3.加上唯一的前缀
fname=System.currentTimeMillis()+ UUID.randomUUID().toString()+fname;
//4.开始上传
try{
File f = new File(realPath, fname);
if(!f.exists()){
f.mkdirs();
}
mf.transferTo(f);//上传
}catch (Exception e){
System.out.println("图片上传失败");
System.out.println(e.getMessage());
}
session.setAttribute("imgurl","/imgs/"+fname);
//响应图片在服务器中的路径
return JSON.toJSONString("/imgs/"+fname);
}
@RequestMapping("/down")
public void down(String fname, HttpSession session, HttpServletResponse response) throws IOException {
try { //1、先找到图片的位置
String realPath = session.getServletContext().getRealPath("/imgs");
fname = fname.substring(5);
//一个头两个流
fname = new String(fname.getBytes("GBK"), "ISO-8859-1");//处理图片中的乱码
//头
response.setHeader("content-disposition", "attachment;filename" + fname);
FileInputStream is = new FileInputStream(realPath + fname);
ServletOutputStream os = response.getOutputStream();
IOUtils.copy(is, os);
}catch (Exception e){
response.sendRedirect("/");
}
}
//批量删除
@RequestMapping("/batDel")
@ResponseBody//回调函数不起作用
public void batDel(Integer[] ids){
service.batDel(ids);
}
}
IEmpService接口
package com.service;
import com.pojo.Dept;
import com.pojo.Emp;
import com.pojo.PageBean;
import java.util.List;
public interface IEmpService {
List<Emp> selectLikePage(PageBean page);
List<Dept> selectDepts();
int addEmp(Emp emp);
Emp selectById(int parseInt);
int updateEmp(Emp emp);
int deleteById(int parseInt);
void batDel(Integer[] ids);
}
EmpServiceImpl
package com.service.impl;
import com.mapper.DeptMapper;
import com.mapper.EmpMapper;
import com.pojo.Dept;
import com.pojo.Emp;
import com.pojo.EmpExample;
import com.pojo.PageBean;
import com.service.IEmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.List;
@Service
@Transactional
public class EmpServiceImpl implements IEmpService {
@Autowired
private EmpMapper empMapper;
@Autowired
private DeptMapper deptMapper;
@Override
public List<Emp> selectLikePage(PageBean page) {
EmpExample e = new EmpExample();
EmpExample.Criteria c = e.createCriteria();
if(page.getName()!=null){
c.andNameLike("%"+page.getName()+"%");
}
if(page.getStartBirth()!=null){
c.andBirthGreaterThanOrEqualTo(page.getStartBirth());
}
if(page.getEndBirth()!=null){
c.andBirthLessThanOrEqualTo(page.getEndBirth());
}
if(page.getDeptId()!=null&&page.getDeptId()!=0){
c.andDeptidEqualTo(page.getDeptId());
}
int count = (int) empMapper.countByExample(e);
int size = page.getSize();
int totalPage=(count%size==0)?(count/size):(count/size+1);
page.setCount(count);
page.setTotalPage(totalPage);
int startRow=(page.getCurrPage()-1)*size;
e.limit(startRow,size);
List<Emp> emps = empMapper.selectByExample(e);
for(Emp emp:emps){
Dept dept=deptMapper.selectByPrimaryKey(emp.getDeptid());
emp.setDept(dept);
}
return emps;
}
@Override
public List<Dept> selectDepts() {
return deptMapper.selectByExample(null);
}
@Override
public int addEmp(Emp emp) {
return empMapper.insertSelective(emp);
}
@Override
public Emp selectById(int id) {
return empMapper.selectByPrimaryKey(id);
}
@Override
public int updateEmp(Emp emp) {
return empMapper.updateByPrimaryKeySelective(emp);
}
@Override
public int deleteById(int id) {
return empMapper.deleteByPrimaryKey(id);
}
@Override
public void batDel(Integer[] ids) {
EmpExample e = new EmpExample();
EmpExample.Criteria c = e.createCriteria();
c.andIdIn(Arrays.asList(ids));
empMapper.deleteByExample(e);
}
}
三、jsp代码
show.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<title>Title</title>
<script src="/js/jquery-3.3.1.min.js"></script>
</head>
<body>
<%--1.条件查询--%>
<form id="myForm" action="/emp/show" method="post" style="text-align: center">
姓名:<input type="text" name="name" value="${page.name}">
生日:<input type="date" name="startBirth" value="<fmt:formatDate value='${page.startBirth}' pattern='yyyy-MM-dd'/>" >-
<input type="date" name="endBirth" value="<fmt:formatDate value='${page.endBirth}' pattern='yyyy-MM-dd'/>" >
部门:<select name="deptId" >
<option value="0">--请选择--</option>
<c:forEach var="dept" items="${depts}">
<option value="${dept.deptid}"
<c:if test="${dept.deptid==page.deptId}">selected=true</c:if>
>${dept.dep}</option>
</c:forEach>
</select>
<input type="hidden" id="pageNum" name="currPage" value="1">
<input type="submit" value="搜索">
</form>
<%--2.数据展示--%>
<table align="center" cellpadding="15" cellspacing="0" border="1">
<tr>
<td><input type="checkbox" id="checkAll">全选</td>
<td>编号</td>
<td>姓名</td>
<td>年龄</td>
<td>性别</td>
<td>工资</td>
<td>津贴</td>
<td>生日</td>
<td>入职日期</td>
<td>上级</td>
<td>部门</td>
<td>大头贴</td>
<td><input type="button" id="batchDel" value="批量删除">| <input type="button" οnclick="location.href='/emp/add1'" value="新增"></td>
</tr>
<c:if test="${not empty list}">
<c:forEach var="emp" items="${list}">
<tr>
<td><input class="checkNow" value="${emp.id}" type="checkbox"></td>
<td>${emp.id}</td>
<td>${emp.name}</td>
<td>${emp.age}</td>
<td>${emp.sex}</td>
<td>${emp.salary}</td>
<td>${emp.bonus}</td>
<td><fmt:formatDate value="${emp.birth}" pattern="yyyy-MM-dd"/></td>
<td><fmt:formatDate value="${emp.hiredate}" pattern="yyyy-MM-dd"/></td>
<td>${emp.leader}</td>
<td>${emp.dept.dep}</td>
<td><a href="/emp2/down?fname=${emp.imgurl}"><img src="${emp.imgurl}" alt="" width="100px" height="100px"></a></td>
<td><a href="/emp/deleteById/${emp.id}">删除</a>|
<a href="/emp/update1/${emp.id}">修改</a></td>
</tr>
</c:forEach>
</c:if>
</table>
<%--3.分页--%>
<table align="center" cellpadding="10" cellspacing="10" border="1">
<tr>
<td><a href="javascript:goPage(1)">首页</a></td>
<td><a href="javascript:goPage(${page.currPage-1})">上一页</a></td>
<c:forEach var="i" begin="1" end="${page.totalPage}">
<td><a href="javascript:goPage(${i})">${i}</a></td>
</c:forEach>
<td><a href="javascript:goPage(${page.currPage+1})">下一页</a></td>
<td><a href="javascript:toPage()">跳转</a>到第<input size="2" type="text" value="${page.currPage}" id="go">页</td>
<td><a href="javascript:goPage(${page.totalPage})">尾页</a></td>
</tr>
</table>
<!--js部分-->
<script>
//批量删除
$("#batchDel").click(function () {
//1.获取到选中的ids 2.ids数组 送到后台
var ids=new Array();
$(".checkNow:checked").each(function () {
var id=$(this).val()
ids.push(id);
});
$.post("/emp2/batDel",{ids:ids.toString()},function (data) {
location.href="/";
});
});
//prop和attr的区别?
//实现全选和全不选
$("#checkAll").click(function () {
if($(this).prop("checked")){
$(".checkNow").prop("checked",true)
}else {
$(".checkNow").prop("checked",false)
}
});
function goPage(page) {
var total=${page.totalPage};
if(page>total){
page=total;
}
if(page<1){
page=1;
}
$("#pageNum").val(page);
$("#myForm").submit()
}
function toPage() {
var page=$("#go").val();
goPage(page)
}
</script>
</body>
</html>
add.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>新增</title>
<script src="/js/jquery-3.3.1.min.js"></script>
<script src="/js/jquery.form.js"></script>
</head>
<body>
<%--<div align="ccenter">--%>
<form action="/emp/add2" method="post" id="form1">
姓名:<input type="text" name="name"/> <br>
年龄:<input type="text" name="age"/><br>
性别:<input type="text" name="sex"/><br>
工资:<input type="text" name="salary"><br>
津贴:<input type="text" name="bonus"><br>
生日:<input type="date" name="birth"><br>
入职日期:<input type="date" name="hiredate"><br>
上级:<input type="number" name="leader"><br>
部门:<select name="deptid">
<c:forEach var="dept" items="${depts}">
<option value="${dept.deptid}">${dept.dep}</option>
</c:forEach>
</select><br>
<%--大头贴:<input type="file" name="mf" id="up" ><br>
<img src="" id="img1" alt="" width="150px" height="150px"><br>
<input type="hidden" id="hd" name="imgurl" value="">
<input type="submit" value="提交">
</form>
</div>
</body>
<script>
$("#up").change(function () {
var f={
type:'post',
url:'/emp2/upload',
dataType:'json',
success:function (data) {
$("#img1").attr("src",data);
$("#hd").val(data);
}
};
alert(1)
$("#form1").ajaxSubmit(f)
});
</script>--%>
大头贴:<input type="file" name="mf" id="up" ><br>
<img src="" id="img1" alt="" width="150px" height="150px"><br>
<input type="hidden" id="hd" name="imgurl" value="">
<input type="submit" value="提交">
</form>
</body>
<script>
$("#up").change(function () {
var f={
type:'post',
url:'/emp2/upload',
dataType:'json',
success:function (data) {
$("#img1").attr("src",data);
$("#hd").val(data);
}
};
$("#form1").ajaxSubmit(f)
});
</script>
</html>
update.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<div align="center">
<form action="/emp/update2" method="post">
<input type="hidden" name="id" value="${emp.id}">
姓名:<input type="text" name="name" value="${emp.name}"/> <br>
年龄:<input type="text" name="age" value="${emp.age}"/><br>
性别:<input type="text" name="sex" value="${emp.sex}"/><br>
工资:<input type="text" name="salary" value="${emp.salary}"/><br>
津贴:<input type="text" name="bonus" value="${emp.bonus}"/><br>
生日:<input type="date" name="birth" value="${emp.birth}"/><br>
入职日期:<input type="date" name="hiredate" value="${emp.hiredate}"/><br>
上级:<input type="number" name="leader" value="${emp.leader}"/><br>
部门:<select name="deptid">
<c:forEach var="dept" items="${depts}">
<option value="${dept.deptid}">${dept.dep}</option>
</c:forEach>
</select><br>
<input type="submit" value="提交">
</form>
</div>
</body>
</html>
index.jsp
<html>
<body>
<jsp:forward page="/emp/show"/>
</body>
</html>