接上
6.工具类
EncryptKit
package cn.mine.testssm.service;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.mine.testssm.mapper.OrderMapper;
import cn.mine.testssm.pojo.Order;
@Service
public class OrderServiceImpl implements OrderService {
@Autowired
private OrderMapper orderMapper;
public Order selectByPrimaryKey(Integer id) {
return orderMapper.selectByPrimaryKey(id);
}
public List<Order> findAll() {
return orderMapper.findAll();
}
public List<Order> find() {
// TODO 自動生成されたメソッド・スタブ
return orderMapper.find();
}
public void deleteByPrimaryKey(Integer id) {
orderMapper.deleteByPrimaryKey(id);
}
public void insert(Order order) {
order.setCreated(new Date());
order.setUpdated(order.getCreated());
orderMapper.insert(order);
}
public Order get(Integer id) {
return orderMapper.get(id);
}
public void updateByPrimaryKey(Order order) {
orderMapper.updateByPrimaryKey(order);
}
}
ResultModel
package cn.mine.testssm.until;
/**
* 返回结果对象
* @author https://blog.csdn.net/caiqing116
*/
public class ResultModel {
//返回值 0成功 1失败
private Integer resultCode;
//返回的数据
private String username;
//返回的信息
private String msg;
public ResultModel(Integer resultCode, String msg) {
super();
this.resultCode = resultCode;
this.msg = msg;
}
public ResultModel(Integer resultCode, String username, String msg) {
super();
this.resultCode = resultCode;
this.username = username;
this.msg = msg;
}
public Integer getResultCode() {
return resultCode;
}
public void setResultCode(Integer resultCode) {
this.resultCode = resultCode;
}
public String getusername() {
return username;
}
public void setusername(String username) {
this.username = username;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}
7.Mappers
doorMapper
<?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="cn.mine.testssm.mapper.DoorMapper">
<!-- 查询所有 -->
<select id="findAll" resultType="Door">
SELECT * FROM tb_door
</select>
<!-- 查询某个door -->
<select id="get" parameterType="int" resultType="Door">
select * from tb_door where id=#{id}
</select>
<delete id="delete" parameterType="int">
DELETE FROM tb_door WHERE id=#{id}
</delete>
<insert id="insert" parameterType="Door">
INSERT INTO tb_door (NAME,tel,created,updated)
VALUES (#{name},#{tel},#{created},#{updated})
</insert>
<update id="update" parameterType="Door">
UPDATE tb_door SET
NAME=#{name},tel=#{tel},updated=now()
WHERE id=#{id}
</update>
</mapper>
orderMapper
<?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="cn.mine.testssm.mapper.OrderMapper">
<!-- 查询所有,列出门店名称和电话,type主对象 -->
<resultMap type="Order" id="orderRM">
<!-- 主键,column列(字段),property java对象属性 -->
<!-- column名称不是数据库表的字段名称,而是结果集的名称 -->
<id property="id" column="id"/>
<!-- 普通属性 -->
<result property="orderNo" column="order_no"/>
<result property="orderType" column="order_type"/>
<result property="personNum" column="person_num"/>
<result property="cashier" column="cashier"/>
<result property="createTime" column="create_time"/>
<result property="endTime" column="end_time"/>
<result property="paymentType" column="payment_type"/>
<result property="price" column="price"/>
<result property="created" column="created"/>
<result property="updated" column="updated"/>
<!-- 关联关系,订单和门店,对一 -->
<association property="door" javaType="Door">
<id property="id" column="door_id"/>
<result property="name" column="door_name"/>
<result property="tel" column="tel"/>
</association>
<!-- collection property="orderDetails" ofType="OrderDetail"></collection-->
</resultMap>
<select id="findAll" resultMap="orderRM">
SELECT
o.door_id,
o.id,
d.name AS door_name,
d.tel,
o.order_no,
o.order_type,
o.person_num,
o.cashier,
o.create_time,
o.end_time,
o.payment_type,
o.price
FROM
(SELECT
id,door_id,
order_no,
order_type,
person_num,
cashier,
create_time,
end_time,
payment_type,
price
FROM tb_order) o
LEFT JOIN
(SELECT
id,
NAME,
tel
FROM tb_door) d
ON o.door_id=d.id
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultType="Order">
select *
from tb_order
where id = #{id,jdbcType=INTEGER}
</select>
<select id="get" parameterType="int" resultMap="orderRM">
SELECT
o.door_id,
o.id,
d.name AS door_name,
d.tel,
o.order_no,
o.order_type,
o.person_num,
o.cashier,
o.create_time,
o.end_time,
o.payment_type,
o.price
FROM
(SELECT
id,door_id,
order_no,
order_type,
person_num,
cashier,
create_time,
end_time,
payment_type,
price
FROM tb_order
where id=#{id}) o
LEFT JOIN
(SELECT
id,
NAME,
tel
FROM tb_door) d
ON o.door_id=d.id
</select>
<insert id="insert" parameterType="Order">
INSERT INTO tb_order
(order_no,
door_id,
order_type,
person_num,
cashier,
create_time,
end_time,
payment_type,
price,
created,
updated)
VALUES
(#{orderNo},
#{door.id},
#{orderType},
#{personNum},
#{cashier},
#{createTime},
#{endTime},
#{paymentType},
#{price},
#{created},
#{updated}
)
</insert>
<update id="updateByPrimaryKey" parameterType="Order">
UPDATE tb_order SET
door_id=#{door.id},
order_no=#{orderNo},
order_type=#{orderType},
person_num=#{personNum},
cashier=#{cashier},
create_time=#{createTime},
end_time=#{endTime},
payment_type=#{paymentType},
price=#{price},
updated=NOW()
WHERE id=#{id}
</update>
<delete id="deleteByPrimaryKey" parameterType="int">
delete from tb_order where id=#{id}
</delete>
</mapper>
userMapper
<?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="cn.mine.testssm.mapper.UserMapper">
<!-- 目的:为DAO接口方法提供sql语句配置 -->
<!-- 查询用户和密码进行登录 -->
<select id="findByUsername" resultType="UserInfo" parameterType="String">
select * from user where username = #{username}
</select>
<!--增加用户名和密码进行注册 -->
<insert id="registerByUsernameAndPassword">
insert into user (username,password) values (#{username},#{password})
</insert>
<!-- 查询用户和密码进行登录 -->
<select id="findUsername" resultType="UserInfo" parameterType="String">
select count(*) from user where username = #{username}
</select>
</mapper>