1. 创建maven项目
2. 编写父项目pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>SSM-test03</artifactId>
<groupId>com.qf.java2107</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>SSM-test033-web</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.qf.java2107</groupId>
<artifactId>SSM-test033-service</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<!-- servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- jsp-api-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
</dependencies>
<build>
<!-- 配置了很多插件 -->
<plugins>
<!-- jdk编译插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- tomcat插件 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>80</port>
<path>/</path>
<uriEncoding>UTF-8</uriEncoding>
<server>tomcat7</server>
</configuration>
</plugin>
</plugins>
</build>
</project>
3. 删除父项目的src等文件
4. 导入子项目
4.1 entity
ResultVO.java
package com.qf.java2107.entity;
import java.io.Serializable;
public class ResultVO<T> implements Serializable {
/**
* 响应状态码
* 200 : 成功响应
* 其他是失败
*/
private Integer code;
/**
* 响应消息
*/
private String message;
/**
* 附加数据
*/
private T data;
public ResultVO() {}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
public ResultVO(Integer code, String message) {
this.code = code;
this.message = message;
}
public ResultVO(Integer code, String message, T data) {
this.code = code;
this.message = message;
this.data = data;
}
/**
* 成功无附加数据
* @param message
* @param <T>
* @return
*/
public static <T> ResultVO<T> ok(String message){
return new ResultVO<>(200, message);
}
/**
* 成功有附加数据
* @param message
* @param data
* @param <T>
* @return
*/
public static <T> ResultVO<T> ok(String message, T data){
return new ResultVO<>(200, message, data);
}
/**
* 失败无附加数据
* @param message
* @param <T>
* @return
*/
public static <T> ResultVO<T> error(String message){
return new ResultVO<>(500, message);
}
/**
* 失败有附加数据
* @param message
* @param data
* @param <T>
* @return
*/
public static <T> ResultVO<T> error(String message, T data){
return new ResultVO<>(500, message, data);
}
/**
* {
* "code":200,
* "message": "用户注册成功",
* "data":null
* }
*
* {
* "code":500,
* "message": "用户注册失败",
* "data": "用户名已经存在,请更换"
* }
*
* {
* "code":200,
* "message": "查询用户信息成功",
* "data": json数据
* }
*/
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>SSM-test03</artifactId>
<groupId>com.qf.java2107</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>SSM-test033-entity</artifactId>
</project>
4.2 mapper
GoodsMapper
package com.qf.java2107.mapper;
import com.qf.java2107.pojo.Goods;
import com.qf.java2107.pojo.GoodsExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface GoodsMapper {
long countByExample(GoodsExample example);
int deleteByExample(GoodsExample example);
int deleteByPrimaryKey(Integer id);
int insert(Goods record);
int insertSelective(Goods record);
List<Goods> selectByExample(GoodsExample example);
Goods selectByPrimaryKey(Integer id);
int updateByExampleSelective(@Param("record") Goods record, @Param("example") GoodsExample example);
int updateByExample(@Param("record") Goods record, @Param("example") GoodsExample example);
int updateByPrimaryKeySelective(Goods record);
int updateByPrimaryKey(Goods record);
}
TypeMapper
package com.qf.java2107.mapper;
import com.qf.java2107.pojo.Type;
import com.qf.java2107.pojo.TypeExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface TypeMapper {
long countByExample(TypeExample example);
int deleteByExample(TypeExample example);
int deleteByPrimaryKey(Integer id);
int insert(Type record);
int insertSelective(Type record);
List<Type> selectByExample(TypeExample example);
Type selectByPrimaryKey(Integer id);
int updateByExampleSelective(@Param("record") Type record, @Param("example") TypeExample example);
int updateByExample(@Param("record") Type record, @Param("example") TypeExample example);
int updateByPrimaryKeySelective(Type record);
int updateByPrimaryKey(Type record);
}
GoodsMapper.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.qf.java2107.mapper.GoodsMapper">
<resultMap id="BaseResultMap" type="com.qf.java2107.pojo.Goods">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="description" jdbcType="VARCHAR" property="description" />
<result column="price" jdbcType="INTEGER" property="price" />
<result column="pro_date" jdbcType="DATE" property="proDate" />
<result column="ex_date" jdbcType="DATE" property="exDate" />
<result column="type_id" jdbcType="INTEGER" property="typeId" />
</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, description, price, pro_date, ex_date, type_id
</sql>
<select id="selectByExample" parameterType="com.qf.java2107.pojo.GoodsExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from s_goods
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from s_goods
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from s_goods
where id = #{id,jdbcType=INTEGER}
</delete>
<delete id="deleteByExample" parameterType="com.qf.java2107.pojo.GoodsExample">
delete from s_goods
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="com.qf.java2107.pojo.Goods">
insert into s_goods (id, name, description,
price, pro_date, ex_date, type_id
)
values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR},
#{price,jdbcType=INTEGER}, #{proDate,jdbcType=DATE}, #{exDate,jdbcType=DATE}, #{typeId,jdbcType=INTEGER}
)
</insert>
<insert id="insertSelective" parameterType="com.qf.java2107.pojo.Goods">
insert into s_goods
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="name != null">
name,
</if>
<if test="description != null">
description,
</if>
<if test="price != null">
price,
</if>
<if test="proDate != null">
pro_date,
</if>
<if test="exDate != null">
ex_date,
</if>
<if test="typeId != null">
type_id,
</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="description != null">
#{description,jdbcType=VARCHAR},
</if>
<if test="price != null">
#{price,jdbcType=INTEGER},
</if>
<if test="proDate != null">
#{proDate,jdbcType=DATE},
</if>
<if test="exDate != null">
#{exDate,jdbcType=DATE},
</if>
<if test="typeId != null">
#{typeId,jdbcType=INTEGER},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.qf.java2107.pojo.GoodsExample" resultType="java.lang.Long">
select count(*) from s_goods
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update s_goods
<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.description != null">
description = #{record.description,jdbcType=VARCHAR},
</if>
<if test="record.price != null">
price = #{record.price,jdbcType=INTEGER},
</if>
<if test="record.proDate != null">
pro_date = #{record.proDate,jdbcType=DATE},
</if>
<if test="record.exDate != null">
ex_date = #{record.exDate,jdbcType=DATE},
</if>
<if test="record.typeId != null">
type_id = #{record.typeId,jdbcType=INTEGER},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
update s_goods
set id = #{record.id,jdbcType=INTEGER},
name = #{record.name,jdbcType=VARCHAR},
description = #{record.description,jdbcType=VARCHAR},
price = #{record.price,jdbcType=INTEGER},
pro_date = #{record.proDate,jdbcType=DATE},
ex_date = #{record.exDate,jdbcType=DATE},
type_id = #{record.typeId,jdbcType=INTEGER}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.qf.java2107.pojo.Goods">
update s_goods
<set>
<if test="name != null">
name = #{name,jdbcType=VARCHAR},
</if>
<if test="description != null">
description = #{description,jdbcType=VARCHAR},
</if>
<if test="price != null">
price = #{price,jdbcType=INTEGER},
</if>
<if test="proDate != null">
pro_date = #{proDate,jdbcType=DATE},
</if>
<if test="exDate != null">
ex_date = #{exDate,jdbcType=DATE},
</if>
<if test="typeId != null">
type_id = #{typeId,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.qf.java2107.pojo.Goods">
update s_goods
set name = #{name,jdbcType=VARCHAR},
description = #{description,jdbcType=VARCHAR},
price = #{price,jdbcType=INTEGER},
pro_date = #{proDate,jdbcType=DATE},
ex_date = #{exDate,jdbcType=DATE},
type_id = #{typeId,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
TypeMapper.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.qf.java2107.mapper.TypeMapper">
<resultMap id="BaseResultMap" type="com.qf.java2107.pojo.Type">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="type_name" jdbcType="VARCHAR" property="typeName" />
</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, type_name
</sql>
<select id="selectByExample" parameterType="com.qf.java2107.pojo.TypeExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from s_type
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from s_type
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from s_type
where id = #{id,jdbcType=INTEGER}
</delete>
<delete id="deleteByExample" parameterType="com.qf.java2107.pojo.TypeExample">
delete from s_type
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="com.qf.java2107.pojo.Type">
insert into s_type (id, type_name)
values (#{id,jdbcType=INTEGER}, #{typeName,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.qf.java2107.pojo.Type">
insert into s_type
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="typeName != null">
type_name,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="typeName != null">
#{typeName,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.qf.java2107.pojo.TypeExample" resultType="java.lang.Long">
select count(*) from s_type
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update s_type
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=INTEGER},
</if>
<if test="record.typeName != null">
type_name = #{record.typeName,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
update s_type
set id = #{record.id,jdbcType=INTEGER},
type_name = #{record.typeName,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.qf.java2107.pojo.Type">
update s_type
<set>
<if test="typeName != null">
type_name = #{typeName,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.qf.java2107.pojo.Type">
update s_type
set type_name = #{typeName,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
jdbc.properties
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://1.116.232.227:4120/ssm01?useSSL=false&serverTimezone=UTC&characterEncoding=UTF8&useUnicode=true
jdbc.username=hrx
jdbc.password=XwithX@20211212
spring-mapper.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/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">
<context:property-placeholder location="classpath:properties/*.properties"/>
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="driverClassName" value="${jdbc.driver}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mapperLocations" value="classpath:mapper/*Mapper.xml"/>
<property name="typeAliasesPackage" value="com.qf.java2107.pojo"/>
<property name="configuration">
<bean class="org.apache.ibatis.session.Configuration">
<property name="mapUnderscoreToCamelCase" value="true"/>
</bean>
</property>
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageInterceptor">
<property name="properties">
<value>
helperDialect=mysql
reasonable=true
</value>
</property>
</bean>
</array>
</property>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.qf.java2107.mapper"/>
</bean>
</beans>
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>SSM-test03</artifactId>
<groupId>com.qf.java2107</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>SSM-test033-mapper</artifactId>
<dependencies>
<dependency>
<groupId>com.qf.java2107</groupId>
<artifactId>SSM-test033-pojo</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
</dependencies>
</project>
4.3 pojo
Goods
package com.qf.java2107.pojo;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
public class Goods {
private Integer id;
private String name;
private String description;
private Integer price;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date proDate;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date exDate;
private Integer typeId;
private Type type;
public Type getType() {
return type;
}
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 String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description == null ? null : description.trim();
}
public Integer getPrice() {
return price;
}
public void setPrice(Integer price) {
this.price = price;
}
public Date getProDate() {
return proDate;
}
public void setProDate(Date proDate) {
this.proDate = proDate;
}
public Date getExDate() {
return exDate;
}
public void setExDate(Date exDate) {
this.exDate = exDate;
}
public Integer getTypeId() {
return typeId;
}
public void setTypeId(Integer typeId) {
this.typeId = typeId;
}
public void setType(Type type) {
this.type = type;
}
}
GoodsExample
package com.qf.java2107.pojo;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
public class GoodsExample {
protected String orderByClause;
protected boolean distinct;
protected List<Criteria> oredCriteria;
public GoodsExample() {
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;
}
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 andDescriptionIsNull() {
addCriterion("description is null");
return (Criteria) this;
}
public Criteria andDescriptionIsNotNull() {
addCriterion("description is not null");
return (Criteria) this;
}
public Criteria andDescriptionEqualTo(String value) {
addCriterion("description =", value, "description");
return (Criteria) this;
}
public Criteria andDescriptionNotEqualTo(String value) {
addCriterion("description <>", value, "description");
return (Criteria) this;
}
public Criteria andDescriptionGreaterThan(String value) {
addCriterion("description >", value, "description");
return (Criteria) this;
}
public Criteria andDescriptionGreaterThanOrEqualTo(String value) {
addCriterion("description >=", value, "description");
return (Criteria) this;
}
public Criteria andDescriptionLessThan(String value) {
addCriterion("description <", value, "description");
return (Criteria) this;
}
public Criteria andDescriptionLessThanOrEqualTo(String value) {
addCriterion("description <=", value, "description");
return (Criteria) this;
}
public Criteria andDescriptionLike(String value) {
addCriterion("description like", value, "description");
return (Criteria) this;
}
public Criteria andDescriptionNotLike(String value) {
addCriterion("description not like", value, "description");
return (Criteria) this;
}
public Criteria andDescriptionIn(List<String> values) {
addCriterion("description in", values, "description");
return (Criteria) this;
}
public Criteria andDescriptionNotIn(List<String> values) {
addCriterion("description not in", values, "description");
return (Criteria) this;
}
public Criteria andDescriptionBetween(String value1, String value2) {
addCriterion("description between", value1, value2, "description");
return (Criteria) this;
}
public Criteria andDescriptionNotBetween(String value1, String value2) {
addCriterion("description not between", value1, value2, "description");
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(Integer value) {
addCriterion("price =", value, "price");
return (Criteria) this;
}
public Criteria andPriceNotEqualTo(Integer value) {
addCriterion("price <>", value, "price");
return (Criteria) this;
}
public Criteria andPriceGreaterThan(Integer value) {
addCriterion("price >", value, "price");
return (Criteria) this;
}
public Criteria andPriceGreaterThanOrEqualTo(Integer value) {
addCriterion("price >=", value, "price");
return (Criteria) this;
}
public Criteria andPriceLessThan(Integer value) {
addCriterion("price <", value, "price");
return (Criteria) this;
}
public Criteria andPriceLessThanOrEqualTo(Integer value) {
addCriterion("price <=", value, "price");
return (Criteria) this;
}
public Criteria andPriceIn(List<Integer> values) {
addCriterion("price in", values, "price");
return (Criteria) this;
}
public Criteria andPriceNotIn(List<Integer> values) {
addCriterion("price not in", values, "price");
return (Criteria) this;
}
public Criteria andPriceBetween(Integer value1, Integer value2) {
addCriterion("price between", value1, value2, "price");
return (Criteria) this;
}
public Criteria andPriceNotBetween(Integer value1, Integer value2) {
addCriterion("price not between", value1, value2, "price");
return (Criteria) this;
}
public Criteria andProDateIsNull() {
addCriterion("pro_date is null");
return (Criteria) this;
}
public Criteria andProDateIsNotNull() {
addCriterion("pro_date is not null");
return (Criteria) this;
}
public Criteria andProDateEqualTo(Date value) {
addCriterionForJDBCDate("pro_date =", value, "proDate");
return (Criteria) this;
}
public Criteria andProDateNotEqualTo(Date value) {
addCriterionForJDBCDate("pro_date <>", value, "proDate");
return (Criteria) this;
}
public Criteria andProDateGreaterThan(Date value) {
addCriterionForJDBCDate("pro_date >", value, "proDate");
return (Criteria) this;
}
public Criteria andProDateGreaterThanOrEqualTo(Date value) {
addCriterionForJDBCDate("pro_date >=", value, "proDate");
return (Criteria) this;
}
public Criteria andProDateLessThan(Date value) {
addCriterionForJDBCDate("pro_date <", value, "proDate");
return (Criteria) this;
}
public Criteria andProDateLessThanOrEqualTo(Date value) {
addCriterionForJDBCDate("pro_date <=", value, "proDate");
return (Criteria) this;
}
public Criteria andProDateIn(List<Date> values) {
addCriterionForJDBCDate("pro_date in", values, "proDate");
return (Criteria) this;
}
public Criteria andProDateNotIn(List<Date> values) {
addCriterionForJDBCDate("pro_date not in", values, "proDate");
return (Criteria) this;
}
public Criteria andProDateBetween(Date value1, Date value2) {
addCriterionForJDBCDate("pro_date between", value1, value2, "proDate");
return (Criteria) this;
}
public Criteria andProDateNotBetween(Date value1, Date value2) {
addCriterionForJDBCDate("pro_date not between", value1, value2, "proDate");
return (Criteria) this;
}
public Criteria andExDateIsNull() {
addCriterion("ex_date is null");
return (Criteria) this;
}
public Criteria andExDateIsNotNull() {
addCriterion("ex_date is not null");
return (Criteria) this;
}
public Criteria andExDateEqualTo(Date value) {
addCriterionForJDBCDate("ex_date =", value, "exDate");
return (Criteria) this;
}
public Criteria andExDateNotEqualTo(Date value) {
addCriterionForJDBCDate("ex_date <>", value, "exDate");
return (Criteria) this;
}
public Criteria andExDateGreaterThan(Date value) {
addCriterionForJDBCDate("ex_date >", value, "exDate");
return (Criteria) this;
}
public Criteria andExDateGreaterThanOrEqualTo(Date value) {
addCriterionForJDBCDate("ex_date >=", value, "exDate");
return (Criteria) this;
}
public Criteria andExDateLessThan(Date value) {
addCriterionForJDBCDate("ex_date <", value, "exDate");
return (Criteria) this;
}
public Criteria andExDateLessThanOrEqualTo(Date value) {
addCriterionForJDBCDate("ex_date <=", value, "exDate");
return (Criteria) this;
}
public Criteria andExDateIn(List<Date> values) {
addCriterionForJDBCDate("ex_date in", values, "exDate");
return (Criteria) this;
}
public Criteria andExDateNotIn(List<Date> values) {
addCriterionForJDBCDate("ex_date not in", values, "exDate");
return (Criteria) this;
}
public Criteria andExDateBetween(Date value1, Date value2) {
addCriterionForJDBCDate("ex_date between", value1, value2, "exDate");
return (Criteria) this;
}
public Criteria andExDateNotBetween(Date value1, Date value2) {
addCriterionForJDBCDate("ex_date not between", value1, value2, "exDate");
return (Criteria) this;
}
public Criteria andTypeIdIsNull() {
addCriterion("type_id is null");
return (Criteria) this;
}
public Criteria andTypeIdIsNotNull() {
addCriterion("type_id is not null");
return (Criteria) this;
}
public Criteria andTypeIdEqualTo(Integer value) {
addCriterion("type_id =", value, "typeId");
return (Criteria) this;
}
public Criteria andTypeIdNotEqualTo(Integer value) {
addCriterion("type_id <>", value, "typeId");
return (Criteria) this;
}
public Criteria andTypeIdGreaterThan(Integer value) {
addCriterion("type_id >", value, "typeId");
return (Criteria) this;
}
public Criteria andTypeIdGreaterThanOrEqualTo(Integer value) {
addCriterion("type_id >=", value, "typeId");
return (Criteria) this;
}
public Criteria andTypeIdLessThan(Integer value) {
addCriterion("type_id <", value, "typeId");
return (Criteria) this;
}
public Criteria andTypeIdLessThanOrEqualTo(Integer value) {
addCriterion("type_id <=", value, "typeId");
return (Criteria) this;
}
public Criteria andTypeIdIn(List<Integer> values) {
addCriterion("type_id in", values, "typeId");
return (Criteria) this;
}
public Criteria andTypeIdNotIn(List<Integer> values) {
addCriterion("type_id not in", values, "typeId");
return (Criteria) this;
}
public Criteria andTypeIdBetween(Integer value1, Integer value2) {
addCriterion("type_id between", value1, value2, "typeId");
return (Criteria) this;
}
public Criteria andTypeIdNotBetween(Integer value1, Integer value2) {
addCriterion("type_id not between", value1, value2, "typeId");
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);
}
}
}
Type
package com.qf.java2107.pojo;
public class Type {
private Integer id;
private String typeName;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getTypeName() {
return typeName;
}
public void setTypeName(String typeName) {
this.typeName = typeName == null ? null : typeName.trim();
}
@Override
public String toString() {
return "Type{" +
"id=" + id +
", typeName='" + typeName + '\'' +
'}';
}
}
TypeExample
package com.qf.java2107.pojo;
import java.util.ArrayList;
import java.util.List;
public class TypeExample {
protected String orderByClause;
protected boolean distinct;
protected List<Criteria> oredCriteria;
public TypeExample() {
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;
}
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 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 andTypeNameIsNull() {
addCriterion("type_name is null");
return (Criteria) this;
}
public Criteria andTypeNameIsNotNull() {
addCriterion("type_name is not null");
return (Criteria) this;
}
public Criteria andTypeNameEqualTo(String value) {
addCriterion("type_name =", value, "typeName");
return (Criteria) this;
}
public Criteria andTypeNameNotEqualTo(String value) {
addCriterion("type_name <>", value, "typeName");
return (Criteria) this;
}
public Criteria andTypeNameGreaterThan(String value) {
addCriterion("type_name >", value, "typeName");
return (Criteria) this;
}
public Criteria andTypeNameGreaterThanOrEqualTo(String value) {
addCriterion("type_name >=", value, "typeName");
return (Criteria) this;
}
public Criteria andTypeNameLessThan(String value) {
addCriterion("type_name <", value, "typeName");
return (Criteria) this;
}
public Criteria andTypeNameLessThanOrEqualTo(String value) {
addCriterion("type_name <=", value, "typeName");
return (Criteria) this;
}
public Criteria andTypeNameLike(String value) {
addCriterion("type_name like", value, "typeName");
return (Criteria) this;
}
public Criteria andTypeNameNotLike(String value) {
addCriterion("type_name not like", value, "typeName");
return (Criteria) this;
}
public Criteria andTypeNameIn(List<String> values) {
addCriterion("type_name in", values, "typeName");
return (Criteria) this;
}
public Criteria andTypeNameNotIn(List<String> values) {
addCriterion("type_name not in", values, "typeName");
return (Criteria) this;
}
public Criteria andTypeNameBetween(String value1, String value2) {
addCriterion("type_name between", value1, value2, "typeName");
return (Criteria) this;
}
public Criteria andTypeNameNotBetween(String value1, String value2) {
addCriterion("type_name not between", value1, value2, "typeName");
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);
}
}
}
pom
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>SSM-test03</artifactId>
<groupId>com.qf.java2107</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>SSM-test033-pojo</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
</dependencies>
</project>
4.4service
GoodsService
package com.qf.java2107.service;
import com.github.pagehelper.PageInfo;
import com.qf.java2107.pojo.Goods;
import java.util.Map;
public interface GoodsService {
PageInfo<Goods> findPage(Integer pageNum, Integer pageSize);
Map<String,Object> findByIdAndTypes(Integer id);
int update(Goods goods);
int insert(Goods goods);
int remove(Integer id);
int delete(Integer id);
}
GoodsServiceImpl
package com.qf.java2107.service.impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.java2107.mapper.GoodsMapper;
import com.qf.java2107.mapper.TypeMapper;
import com.qf.java2107.pojo.Goods;
import com.qf.java2107.pojo.Type;
import com.qf.java2107.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
@Transactional
public class GoodsServiceImpl implements GoodsService {
@Autowired
private GoodsMapper goodsMapper;
@Autowired
private TypeMapper typeMapper;
@Override
public PageInfo<Goods> findPage(Integer pageNum, Integer pageSize) {
PageHelper.startPage(pageNum,pageSize);
List<Goods> goodsList = goodsMapper.selectByExample(null);
for (Goods goods:goodsList) {
Type type = typeMapper.selectByPrimaryKey(goods.getTypeId());
goods.setType(type);
System.out.println(type);
}
return new PageInfo<>(goodsList);
}
@Override
public Map<String, Object> findByIdAndTypes(Integer id) {
Map<String, Object> map = new HashMap<>();
map.put("goods",goodsMapper.selectByPrimaryKey(id));
map.put("types",typeMapper.selectByExample(null));
return map;
}
@Override
public int update(Goods goods) {
return goodsMapper.updateByPrimaryKeySelective(goods);
}
@Override
public int insert(Goods goods) {
return goodsMapper.insert(goods);
}
@Override
public int remove(Integer id) {
return goodsMapper.deleteByPrimaryKey(id);
}
@Override
public int delete(Integer id) {
return goodsMapper.deleteByPrimaryKey(id);
}
}
spring-service.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/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">
<context:component-scan base-package="com.qf.java2107.service"/>
</beans>
spring-tx.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">
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>SSM-test03</artifactId>
<groupId>com.qf.java2107</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>SSM-test033-service</artifactId>
<dependencies>
<dependency>
<groupId>com.qf.java2107</groupId>
<artifactId>SSM-test033-mapper</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
</dependencies>
</project>
4.5 web
GoodsController
package com.qf.java2107.web.controller;
import com.qf.java2107.pojo.Goods;
import com.qf.java2107.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import java.util.HashMap;
import java.util.Map;
@Controller
@RequestMapping("goods")
public class GoodsController {
@Autowired
private GoodsService goodsService;
@GetMapping("/pagelist/{pageNum}/{pageSize}")
public ModelAndView findPage(@PathVariable("pageNum") Integer pageNum,
@PathVariable("pageSize") Integer pageSize){
ModelAndView mav = new ModelAndView("goods/pagelist");
mav.addObject("pageInfo",goodsService.findPage(pageNum,pageSize));
return mav;
}
@GetMapping("/{id}")
public ModelAndView findPage(@PathVariable("id") Integer id){
ModelAndView mav = new ModelAndView("goods/edit");
mav.addObject("goods",goodsService.findByIdAndTypes(id).get("goods"));
mav.addObject("types",goodsService.findByIdAndTypes(id).get("types"));
return mav;
}
@PostMapping("/update")
public ModelAndView update(Goods goods){
ModelAndView mav = new ModelAndView("redirect:/goods/pagelist/1/10");
goodsService.update(goods);
return mav;
}
@GetMapping("/save")
public ModelAndView save(){
ModelAndView mav = new ModelAndView("goods/insert");
Integer id = 1;
mav.addObject("goods",goodsService.findByIdAndTypes(id).get("goods"));
mav.addObject("types",goodsService.findByIdAndTypes(id).get("types"));
return mav;
}
@PostMapping("/insert")
public ModelAndView insert(Goods goods){
ModelAndView mav = new ModelAndView("redirect:/goods/pagelist/1/10");
goodsService.insert(goods);
return mav;
}
@PostMapping("/remove")
@ResponseBody
public String remove(Integer id){
String msg="";
int i = goodsService.delete(id);
if (i > 0){
msg = "yes";
}else {
msg = "no";
}
return msg;
}
}
edit.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" %>
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
<title>商品页面</title>
<!-- Bootstrap -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery,所以必须放在前边) -->
<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
</head>
<body>
<center>
<h1>商品编辑页面</h1>
<form action="/goods/update" method="post" class="form-horizontal" >
<input type="hidden" value="${goods.id}" name="id">
<div class="form-group">
<label for="inputName" class="col-sm-4 control-label">品名</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="inputName" placeholder="商品名称" value="${goods.name}" name="name">
</div>
</div>
<div class="form-group">
<label for="inputDescription" class="col-sm-4 control-label">描述</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="inputDescription" placeholder="商品描述" value="${goods.description}" name="description">
</div>
</div>
<div class="form-group">
<label for="inputPrice" class="col-sm-4 control-label">价格</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="inputPrice" placeholder="商品价格" value="${goods.price}" name="price">
</div>
</div>
<div class="form-group">
<label for="inputProDate" class="col-sm-4 control-label">生产日期</label>
<div class="col-sm-2">
<input type="text" readonly class="form-control" placeholder="生产日期" value="<fmt:formatDate value="${goods.proDate}" pattern="yyyy-MM-dd"/>" >
</div>
<div class="col-sm-2">
<input type="date" class="form-control" id="inputProDate" placeholder="生产日期" name="proDate">
</div>
</div>
<div class="form-group">
<label for="inputExDate" class="col-sm-4 control-label">限用日期</label>
<div class="col-sm-2">
<input type="text" readonly class="form-control" placeholder="限用日期" value="<fmt:formatDate value="${goods.exDate}" pattern="yyyy-MM-dd"/>" >
</div>
<div class="col-sm-2">
<input type="date" class="form-control" id="inputExDate" placeholder="限用日期" name="exDate">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">商品类别</label>
<div class="col-sm-4">
<select class="form-control" name="typeId">
<c:forEach items="${types}" var="type">
<option value="${type.id}" <c:if test="${type.id == goods.typeId}">selected</c:if>>${type.typeName}</option>
</c:forEach>
</select>
<%-- <input type="text" class="form-control" id="inputDeptId" placeholder="部门名称" value="${emp.deptId}" name="deptId">--%>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">修改</button>
</div>
</div>
</form>
</center>
</body>
</html>
insert.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" %>
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
<title>添加商品页面</title>
<!-- Bootstrap -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery,所以必须放在前边) -->
<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
</head>
<body>
<center>
<h1>商品添加页面</h1>
<form action="/goods/insert" method="post" class="form-horizontal" >
<input type="hidden" value="" name="id">
<div class="form-group">
<label for="inputName" class="col-sm-4 control-label">品名</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="inputName" placeholder="商品名称" name="name">
</div>
</div>
<div class="form-group">
<label for="inputDescription" class="col-sm-4 control-label">描述</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="inputDescription" placeholder="商品描述" name="description">
</div>
</div>
<div class="form-group">
<label for="inputPrice" class="col-sm-4 control-label">价格</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="inputPrice" placeholder="商品价格" name="price">
</div>
</div>
<div class="form-group">
<label for="inputProDate" class="col-sm-4 control-label">生产日期</label>
<div class="col-sm-4">
<input type="date" class="form-control" id="inputProDate" placeholder="生产日期" name="proDate">
</div>
</div>
<div class="form-group">
<label for="inputExDate" class="col-sm-4 control-label">限用日期</label>
<div class="col-sm-4">
<input type="date" class="form-control" id="inputExDate" placeholder="限用日期" name="exDate">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">商品类别</label>
<div class="col-sm-4">
<select class="form-control" name="typeId">
<c:forEach items="${types}" var="type">
<option value="${type.id}">${type.typeName}</option>
</c:forEach>
</select>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">添加</button>
</div>
</div>
</form>
</center>
</body>
</html>
psgelist.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" %>
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
<title>商品列表页面</title>
<!-- Bootstrap -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery,所以必须放在前边) -->
<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
</head>
<body>
<center>
<h1>商品列表页面</h1>
<table class="table table-bordered" style="width: 80%" id="myTable">
<thead>
<tr>
<th>ID</th>
<th>品名</th>
<th>描述</th>
<th>价格</th>
<th>生产日期</th>
<th>限用日期</th>
<th>商品类别</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<c:forEach items="${pageInfo.list}" var="goods">
<tr id="${goods.id}">
<td>${goods.id}</td>
<td>${goods.name}</td>
<td>${goods.description}</td>
<td>${goods.price}</td>
<td><fmt:formatDate value="${goods.proDate}" pattern="yyyy-MM-dd"/></td>
<td><fmt:formatDate value="${goods.exDate}" pattern="yyyy-MM-dd"/></td>
<td>${goods.type.typeName}</td>
<td>
<button type="button" class="btn btn-primary btn-xs" onclick="edit(${goods.id})">编辑</button>
<button type="button" class="btn btn-danger btn-xs" onclick="remove(${goods.id})">删除</button>
</td>
</tr>
</c:forEach>
</tbody>
<tfoot>
<tr>
<td colspan="100" style="text-align: center">
总条数:${pageInfo.total}
总页数:${pageInfo.pages}
当前页:${pageInfo.pageNum}
<a href="/goods/pagelist/1/10">首页</a>
<c:if test="${pageInfo.pageNum > 1}"><a href="/goods/pagelist/${pageInfo.pageNum-1}/10">上一页</a></c:if>
<c:if test="${pageInfo.pageNum <= 1}">上一页</c:if>
<c:if test="${pageInfo.pageNum < pageInfo.pages}"><a href="/goods/pagelist/${pageInfo.pageNum+1}/10">下一页</a></c:if>
<c:if test="${pageInfo.pageNum >= pageInfo.pages}">下一页</c:if>
<a href="/goods/pagelist/${pageInfo.pages}/10">尾页</a>
</td>
</tr>
</tfoot>
</table>
<button type="button" class="btn btn-success btn-xs" onclick="save()">添加</button>
</center>
</body>
<script>
function edit(id) {
location.href = '/goods/'+ id;
}
function remove(id){
var flag = confirm("你确定要删除吗?");
if (flag){
alert(id);
$.ajax({
url:"/goods/remove",
type:"post",
data:{"id":id},
success:function(msg){
alert(msg);
document.getElementById(id).parentNode.removeChild(document.getElementById(id));
//window.location.reload();
}
})
}
}
function save() {
location.href = '/goods/save';
}
</script>
</html>
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>SSM-test03</artifactId>
<groupId>com.qf.java2107</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>SSM-test033-web</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.qf.java2107</groupId>
<artifactId>SSM-test033-service</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<!-- servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- jsp-api-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
</dependencies>
<build>
<!-- 配置了很多插件 -->
<plugins>
<!-- jdk编译插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- tomcat插件 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>80</port>
<path>/</path>
<uriEncoding>UTF-8</uriEncoding>
<server>tomcat7</server>
</configuration>
</plugin>
</plugins>
</build>
</project>
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/65682.html