在前面的章节中我们学习Spring的时候可以看到配置文件比较多,所以我们有了SpringBoot

1. 引入依赖

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
<!-- 核心依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <!-- 可以实现热部署,在IDEA上实现热部署还需一些额外的配置,请查阅资料 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>runtime</scope>
</dependency> <!-- JDBC for mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency> <dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.32</version>
</dependency> <!-- mybatis -->
<!--mybatis-->
<!-- https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency> <!--fastJson-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.12</version>
</dependency>
<!--druid-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.18</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.1</version>
</dependency>
<!--thymeleaf 新的模板引擎,比jsp要出色-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!--jdbc-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency> <!-- 分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>

2.配置application.properties文件

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql:///invoicingsystem
spring.datasource.username=root
spring.datasource.password=123456 mybais.mapper-locations=classpath:mapper/*.xml
mybatis.type-aliases-package=com.zn.entity #映射级别
mybatis.configuration.auto-mapping-behavior=full #Spring Data JPA配置
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jackson.serialization.indent-output=true
spring.jpa.database=mysql spring.main.allow-bean-definition-overriding=true

3.配置页面

在前面的页面中我们使用的都是jsp页面,但是在这里我们是使用html页面的并且存放到templates目录下

4.配置Dao接口

@Repository
public interface ProductDao {
//查库存
public List<Product> getList();
public Product getname(@Param("pid") Integer pid);
}
@Repository
public interface SaleDao {
//查询
public List<Sale> getsale(@Param("num") Integer num);
//绑定下拉框
public List<Product> getList();
//添加
public int addsale(Sale sale);
}
@Repository
public interface UserDao {
//登录的方法
public User login(User user);
}

5.配置Dao.xml文件

product

<?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">
<!--namespace需要指向接口全路径-->
<mapper namespace="com.zn.dao.ProductDao"> <select id="getList" resultType="com.zn.entity.Product">
select * from product
</select> <select id="getname" resultType="com.zn.entity.Product">
select * from product where pid=#{pid}
</select>
</mapper>

sale

<?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">
<!--namespace需要指向接口全路径-->
<mapper namespace="com.zn.dao.SaleDao">
<resultMap id="getAllSales" type="com.zn.entity.Sale">
<id property="sid" column="sid"></id>
<result property="quantity" column="quantity"></result>
<result property="price" column="price"></result>
<result column="totalPrice" property="totalPrice"></result>
<result property="saleDate" column="saleDate"></result>
<result column="userId" property="userId"></result>
<result property="productId" column="productId"></result>
<association property="product" javaType="com.zn.entity.Product">
<id column="pid" property="pid"></id>
<result column="productName" property="productName"></result>
</association>
<association property="user" javaType="com.zn.entity.User">
<id property="uid" column="uid"></id>
<result column="userName" property="userName"></result>
</association>
</resultMap> <select id="getsale" resultMap="getAllSales">
select * from product as p,sale as s,users as u where p.pid=s.productId and u.uid=s.userId
<if test="num==1">
order by s.totalPrice DESC
</if>
<if test="num==2">
order by s.saleDate DESC
</if>
</select> <select id="getList" resultType="com.zn.entity.Product">
select * from product
</select> <insert id="addsale">
INSERT INTO sale(price,quantity,totalPrice,saleDate,userId,productId)
VALUE(#{price},#{quantity},#{totalPrice},#{saleDate},#{userId},#{productId})
</insert>
</mapper>

user

<?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">
<!--namespace需要指向接口全路径-->
<mapper namespace="com.zn.dao.UserDao"> <select id="login" resultType="com.zn.entity.User">
select * from users where userName=#{userName} and password=#{password}
</select>
</mapper>

6.配置Service层

product

public interface ProductService {
//查库存
public List<Product> getList();
public Product getname(Integer pid);
}

sale

public interface SaleService {
//查询
public PageInfo<Sale> getsale(@Param("num") Integer num, @Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize);
//绑定下拉框
public List<Product> getList();
//添加
public int addsale(Sale sale);
}

user

public interface UserService {
//登录的方法
public User login(User user);
}

7.配置serviceimpl层

product

package com.zn.service.impl;

import com.zn.dao.ProductDao;
import com.zn.entity.Product;
import com.zn.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import java.util.List; @Service("ProductService")
public class ProductServiceImpl implements ProductService {
@Autowired
ProductDao productDao; @Override
public List<Product> getList() {
List<Product> list = productDao.getList();
return list;
} @Override
public Product getname(Integer pid) {
Product getname = productDao.getname(pid);
return getname;
}
}

sale

package com.zn.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zn.dao.ProductDao;
import com.zn.dao.SaleDao;
import com.zn.entity.Product;
import com.zn.entity.Sale;
import com.zn.service.SaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import java.util.List; @Service("SaleService")
public class SaleServiceImpl implements SaleService { @Autowired
SaleDao saleDao;
@Autowired
ProductDao productDao; @Override
public PageInfo<Sale> getsale(Integer num, Integer pageNum, Integer pageSize) {
Page<Sale> page = PageHelper.startPage(pageNum, pageSize);
List<Sale> getsale = saleDao.getsale(num);
return page.toPageInfo();
} @Override
public List<Product> getList() {
List<Product> list = productDao.getList();
return list;
} @Override
public int addsale(Sale sale) {
int addsale = saleDao.addsale(sale);
return addsale;
} }

user

package com.zn.service.impl;

import com.zn.dao.UserDao;
import com.zn.entity.User;
import com.zn.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; @Service("UserService")
public class UserServiceImpl implements UserService { @Autowired
UserDao userDao; @Override
public User login(User user) {
return userDao.login(user);
}
}

8.配置Controller控制器

product

package com.zn.controller;

import com.zn.entity.Product;
import com.zn.service.ProductService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource;
import java.util.List; @Controller
@RequestMapping("/product")
public class ProductController { @Resource(name = "ProductService")
ProductService productService; @RequestMapping("/getproduct")
@ResponseBody
public Object getProductList(){
System.out.println("库存列表绑定");
List<Product> proList = productService.getList();
return proList; } /*根据id查询库存*/
@RequestMapping("/getpr")
@ResponseBody
public Object getProduct(Integer pid){
System.out.println("库存详情");
Product proLists = productService.getname(pid);
return proLists; } }

sale

package com.zn.controller;

import com.github.pagehelper.PageInfo;
import com.zn.entity.Product;
import com.zn.entity.Sale;
import com.zn.entity.User;
import com.zn.service.SaleService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List; @Controller
@RequestMapping("/sale")
public class SaleController {
@Resource(name = "SaleService")
SaleService saleService; @RequestMapping("/getsale")
@ResponseBody
public Object getsale(Integer num, Integer pageNum, Integer pageSize){
System.out.println("进了吗??");
PageInfo<Sale> getsale = saleService.getsale(num, pageNum + 1, 5);
return getsale;
} @RequestMapping("/getlist")
@ResponseBody
public Object getlist(){
System.out.println("绑定下拉框");
List<Product> list = saleService.getList();
return list;
} @RequestMapping("/addsale")
@ResponseBody
public ModelAndView addsale(Sale sale, HttpServletRequest request, ModelAndView mv){
if (sale!=null){
Double totalPrice=sale.getPrice() * sale.getQuantity();
sale.setTotalPrice(totalPrice);
sale.setSaleDate(new Date());
User login = (User) request.getSession().getAttribute("login");
sale.setUserId(login.getUid());
int addsale = saleService.addsale(sale);
if (addsale>0){
System.out.println("添加成功!");
mv.setViewName("saleList");
}else{
System.out.println("添加失败!");
mv.setViewName("prodectAdd");
}
}
return mv;
}
}

user

package com.zn.controller;

import com.zn.entity.User;
import com.zn.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; @Controller
@RequestMapping(value = "/user")
public class UserController {
@Resource(name = "UserService")
UserService userService;
@RequestMapping("/login")
@ResponseBody
public ModelAndView login(User user, HttpServletRequest request, HttpServletResponse response, ModelAndView modelAndView){
User login = userService.login(user);
if (login!=null){
System.out.println("登陆成功!");
request.getSession().setAttribute("login",login);
modelAndView.setViewName("index");
}else {
modelAndView.setViewName("login");
}
return modelAndView;
} @RequestMapping("/remover")
private String loginOut(HttpServletRequest request, HttpServletResponse response) {
request.getSession().removeAttribute("login");
return "login";
} /*转发登陆页面*/
@RequestMapping("/goLogin")
public Object goLogin(){
return "login";
} /*转发查询页面*/
@RequestMapping("leList")
public Object saleList(){
return "saleList";
} /*转发销售页面*/
@RequestMapping("/prodectAdd")
public Object productAdd(){
return "prodectAdd";
} /*转发查看库存页面*/
@RequestMapping("/prview")
public Object prview(){
return "prview";
}
}

9.开启SpringbootInvoicingApplication

开启后直接访问控制器写入的路径

SpringBoot终章(整合小型进销系统)的更多相关文章

  1. spring boot的一个小项目小型进销存系统

    项目所需的依赖: <dependency> <groupId>org.springframework.boot</groupId> <artifactId&g ...

  2. SQL 报表 --简易进销系统

    模型图: -- ============================================ -- Author: lifu -- Create Date: 2017-06-18 -- D ...

  3. BugPhobia终章篇章:学霸在线系统Beta阶段展示

    0x00 :序言 1 universe, 9 planets, 204 countries,809 islands, 7 seas, and i had the privilege to meet y ...

  4. spring-boot序章:打造博客系统

    blog 使用spring-boot打造一个博客系统,在项目中学习! 项目功能 文章 游览 创建 编辑 删除 评论 用户 游客 注册用户 关注 被关注 后台统计 注册用户数 在线人数 文章总数 评论总 ...

  5. SpringBoot非官方教程 | 终章:文章汇总

    转载请标明出处: 原文首发于:https://www.fangzhipeng.com/springboot/2017/07/11/springboot-all/ 本文出自方志朋的博客 SpringBo ...

  6. 浩瀚技术团队... 安卓智能POS移动PDA开单器 开单器 进销存系统 进销存系统

    浩瀚技术团队... 智能POS移动PDA开单器 开单器 进销存系统 进销存系统 点餐 会员管理 会员管理 深度解读 手机APP移动办公到底是什么? 快速打单POS·不仅仅是快那么简单!  

  7. PDA手持机 移动开单进销存系统 现场出打印凭据和扫码 新的亮点

    传统车销模式弊端:1.手写开单,效率低,动作慢2.现场手写开单明细不能打印,产品明细不规范3.电脑办公人员及车销人员对车上的库存情况掌握不清楚,销售人员对每种产品销售价格不清楚4.老板对员工工作的管控 ...

  8. Silverlight管理系统源码(用于开发ERP、OA、CRM、HR、进销存、财务等系统之用)

    Silverlight大型管理系统源代码(支持创建ERP.OA.CRM.HR.进销存.财务等系统之用) 可用于开发以下系统 SilverlightERP SilverlightCRM Silverli ...

  9. [系统开发] FileMaker进销存系统

    一.简介 这是我用 FileMaker 编写的进销存系统: FileMaker 是一种在欧美流行的桌面型数据库:它使用非常方便,功能也很强大,用户可以在它上面开发自己的系统: 开发时间:2008年 二 ...

随机推荐

  1. Delphi快递鸟【支持快递查询和单号识别】

    作者QQ:(648437169) 点击下载➨Delphi快递鸟 [delphi快递鸟]支持快递查询.单号识别.

  2. PAT(B) 1030 完美数列 - C语言 - 滑动窗口 & 双指针

    题目链接:1030 完美数列 (25 point(s)) 给定一个正整数数列,和正整数 \(p\),设这个数列中的最大值是 \(M\),最小值是 \(m\),如果 \(M≤mp\),则称这个数列是完美 ...

  3. LeetCode 5108. Encode Number - Java - 2进制

    题目链接:https://leetcode-cn.com/problems/encode-number/ Given a non-negative integer num, Return its en ...

  4. golang开发:环境篇(六) Go运行监控Supervisord的使用

    为什么要使用Supervisord 17年第一次写Go项目的时候,用Go开发项目倒没没费多大劲,很快就开发完成了.到了在测试环境部署的时候,由于不知道有 Supervisord 这个软件,着实花了些功 ...

  5. nohup 日志按天输出

    输出日志在当前目录: nohup java -jar ace-auth.jar >> nohup`date +%Y-%m-%d`.out 2>&1 & 指定日志目录输 ...

  6. Jenkins服务使用 宿主机的docker、docker-compose (Jenkins 执行sudo命令时出现“sudo: no tty present and no askpass program specified”,以及 docker-compose command not found解决办法)

    若要转载本文,请务必声明出处:https://www.cnblogs.com/zhongyuanzhao000/p/11681474.html 原因: 本人最近正在尝试CI/CD,所以就使用了 Jen ...

  7. 阿里云主机centos7系统创建SWAP区,并启动挂载(适合无SWAP区虚拟化平台)

    以root用户登录建立交换区文件: fallocate -l 2G /swapfile /swapfile //赋予仅root用户的权限,确保安全 mkswap /swapfile swapon /s ...

  8. python day 21: HTML的基本元素及CSS

    目录 python day 21 1. HTML 1.1 常见的HTML元素 python day 21 2019/11/02 学习资料来自老男孩与尚学堂 1. HTML 1.1 常见的HTML元素 ...

  9. PcAnywhere用法

    安装软件 配置被控端 点击"主机",点击"添加" 可以使用"现有的Windows账户",也可以创建新的"用户名和密码" ...

  10. 嵌入式 vlc从接收到数据流到播放视频的过程分析(经典)

    个人整理: Vlc流播放流程 vlc源码目录树: 目录名称 说明 bindings Java, CIL 和Python绑定 doc 帮助文档 (不是更新的) extras 另叙. include VL ...