ssm项目4

接上

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>





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值