整体框架

  • springboot框架+mysql+freemarker
  • 3层架构
  • springboot+Session
  • springboot+Redis
  • springboot+JPA
  • springboot+mybatis

springboot+Redis+session

首先引入pom引入redis

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

yml文件配置

 / /  配置 ip和 端口redis:host: 192.168.30.113port: 6379

登陆

根据登陆的流程看出利用redis存储和cookies存储token得到redis的openid value

  1. 查找数据库找是否有该openid
  2. 把token和openid用于redis的key和value存储到redis中
  3. 把token存储到cookies中

代码

 //openid和数据库中的数据配对SellerInfo sellerInfo = sellerService.findByOpenid(openid);if (sellerInfo == null) {map.put("msg", ResultEnum.LOGIN_FAIL.getMessage());map.put("url","sell/seller/order/List");return new ModelAndView("common/error");}//把token放到redis中String token = UUID.randomUUID().toString();Integer expire= RedisConstant.EXPIRE;redisTemplate.opsForValue().set(String.format(RedisConstant.TOKEN_PREFIX,token),openid,expire, TimeUnit.SECONDS);//设置token到cookies中,从token中取到value值,然后从value值中得到reids中根据tokenid得到openidCookieUtil.set(response, CookieConstant.TOKEN,token,CookieConstant.EXPIRE);return new ModelAndView("redirect:/sell/seller/order/list");/***  设置cookies* @param response 请求* @param name key* @param value value* @param maxAge 过期时间*/public static void set(HttpServletResponse response,String name,String value,int maxAge){Cookie cookie= new Cookie(name,value);cookie.setPath("/");cookie.setMaxAge(maxAge);response.addCookie(cookie);}

退出登陆

  1. 首先从cookie中得到token
  2. 如果cookie不为空,则删除redis中数据
  3. 清楚cookis中的数据为null
 //cookies里面查询Cookie cookie = CookieUtil.get(request, CookieConstant.TOKEN);if (cookie != null) {//清除redisredisTemplate.opsForValue().getOperations().delete(String.format(RedisConstant.TOKEN_PREFIX,cookie.getName()));// 清楚cookiesCookieUtil.set(response,CookieConstant.TOKEN,null,0);}map.put("msg",ResultEnum.LOGOUT_SUCCESS.getMessage());map.put("url","sell/seller/order/list");return new ModelAndView("common/success",map);/*** 得到cookie* @param request  响应* @param name* @return*/public static Cookie get(HttpServletRequest request,String name){Map<String, Cookie> CookieMap = readCookieMap(request);if(CookieMap!=null){if(CookieMap.containsKey(name)){return CookieMap.get(name);}else {return null;}}return  null;}

springboot+JPA

1引入pom文件

     <dependency>  <groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency><dependency><groupId>org.springframework.data</groupId><artifactId>spring-data-jpa</artifactId></dependency>

2 yml文件配置

spring:datasource:driver-class-name: com.mysql.jdbc.Driverusername: rootpassword: judyurl: jdbc:mysql://localhost/sell?characterEncoding=utf-8&useSSL=falsejpa:show-sql: true

3 代码

JpaRepository<OrderDetailEntity,Integer> 表示表实体和id类型

@Component
public interface OrderDetilRepository  extends JpaRepository<OrderDetailEntity,Integer> {//订单详情表List<OrderDetailEntity> findByOrderId(Integer orderId);
}

@Query: 查询
@Modifying :更新

springboot+mybatis

引入pom文件

<dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>1.2.0</version></dependency>

配置mybatis

mybatis:mapper-locations: classpath:mapper/*.xml

扫描mapper

你不扫描mapper肯定不能读取sql啊

//mybatis的扫描包
@MapperScan(basePackages = "com.judy.demo.mapper")

代码

@ insert
@ select
@ update
@ delete

…在mapper写sql,不说了…

思路

  • 如果进行前后端分离写代码,(判空的时候怎么办)
  • 如果回复统一code码
  • 拦截器使用
  • 封装异常

注解使用

@SpringBootApplication:

@SpringBootApplication = @Configuration + @ EnableAutoConfiguration + @ComponentScan

@Configuration与@Bean 是一对,一般在项目中都是这样使用的

//表示这个类是bean定义的源
@Configuration
public class ComponentDemo{//负责告诉容器返回的对象会交给springioc容器管理@Beanpublic String judy(){String a = new String();return a;}@Beanpublic Integer judyInt(){Integer a = new Integer(2);return a;}
}

@ EnableAutoConfiguration : 自动载入应用程序所需的所有Bean, 依赖于springboot在类路径中查找

@ComponentScan : 会自动扫描指定包下所有标有@Component类,并且注为Bean, 还有@Component下的注解,@service @Repository @Controller

@MapperScan

一般是在项目启动的时候要扫描到mapper

@SpringBootApplication
//mybatis的扫描包
@MapperScan(basePackages = "com.judy.demo.mapper")
public class DemoApplication {public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);}}

@JsonSerialize

一般是序列化为指定的类型

 @JsonSerialize(using = Date2LongSerializer.class)private Date updateTime;

@JsonIgnore

它是在属性上使用的,一般用于序列化的时候自动忽略该属性,用于前后端联调的时候使用

@Entity与@Table(name=“order_detail”)

@Entity实体类一般是和表的名字对应,如果不对应的时候可以使用@Table用来指定表的名字

@DynamicUpdate(true)

当设置为true的时候表示更新的时候如果属性的值为null则不会更新,默认为false

@JsonProperty

前端传值的时候序列化为另一个属性名

断言

一般在调试和测试的使用到,最好在项目中要保持一致性

0:预期值,实际值Assert.assertEquals(0,orderDTOPage.getTotalElements());
不为空
Assert.assertNotNull(byCategoryType);
不等于0则正确Assert.assertNotEquals(0,productCategoryEntityList.size());........

拦截

例如判断用户是否登陆过
使用@compent容器管理
@Pointcut切点

@Pointcut("execution(public * com.judy.demo.Controler.Seller*.*(..))"+"&& !execution(public * com.judy.demo.Controler.SellerUserController.*(..))")public void verify(){}
  @Before("verify()")public void doVerify() throws SellerAuthorizeAspect {ServletRequestAttributes attributes =(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();HttpServletRequest request = attributes.getRequest();Cookie cookie = CookieUtil.get(request, CookieConstant.TOKEN);if(cookie==null){log.warn("登陆失败,cookies中查不到token");throw  new SellerAuthorizeAspect();}//去redis中查询String tokenValue=redisTemplate.opsForValue().get(String.format(RedisConstant.TOKEN_PREFIX,cookie.getName()));if (StringUtils.isEmpty(tokenValue)){log.warn("登陆校验失败redis中没有token");throw new SellerAuthorizeAspect();}}

额外补充(redis缓存知识点)

@Cacheable(cacheNames=“product”,key=“123”)
当线程执行到这个方法的时候,返回值就会缓存上,当下次执行的时候直接从缓存中取出,首先说明cacheNames和key都是表示的redis的key,key可以不写,如果不写表示的是参数值

@CachePut: 更新

@CacheEvict : 删除
必须要提醒的是由缓存那么相应的也应该有删除,避免出现脏数据

unless : 表示如果为空则不存储, 如果不加会报错, 有一次项目上线的时候没有加unless 结果报错了

springboot微信订餐系统总结相关推荐

  1. SpringBoot笔记01【微信订餐系统】[也许对你毫无意义]

    虚拟机-服务器登陆 账号: root 密码:123456 查看服务器ip 终端输入 ifcongig 注意:由于公司和住所的网络环境变化,所以在不同地方 需要重新查看该值,并设置到 项目中 以便连接上 ...

  2. 基于SpringBOOT的订餐系统

    1,项目功能: 卖家端: (1)商品管理:卖家可以在该模块下进行商品信息添加,商品信息查看,商品信息修改以及商品商品信息删除等功能. (2)订单管理:卖家可以查看订单信息,并对订单信息进行确认,同时也 ...

  3. 微信订餐系统php,微信网上订餐系统多用户版 v0.52

    微信网上订餐系统多用户版(微信外卖订餐+手机管理+在线点餐+在线订位)介绍: 微信订餐系统提供在线点餐.在线订位.外面送餐等功能, 方便用户点餐.订位,后台提供菜品管理.订单管理.餐台管理, 不仅可以 ...

  4. Java项目:springboot在线订餐系统

    作者主页:源码空间站2022 简介:Java领域优质创作者.Java项目.学习资料.技术互助 文末获取源码 项目介绍 SpringBoot在线订餐系统项目.主要功能说明: 分为两个角色,餐厅老板和普通 ...

  5. springboot在线订餐系统、

    下载地址:https://download.csdn.net/download/Gouzi99/23887654 项目介绍: springboot在线订餐系统. 系统说明: 项目引见 SpringBo ...

  6. 医院his系统什么服务器,医院营养餐微信订餐系统

    仪创科技研发的该系统的启用不仅及时为病人提供安全.营养的餐食,同时通过移动互联网.移动支付等新技术,为家属提供"一站式"自助服务,减轻了家属陪护的负担,细致.便捷的服务理念也提升了 ...

  7. php 单位食堂订餐,单位食堂职工微信订餐系统

    单位食堂手机点餐系统产品概述: 企业.单位.医院等职工的就餐方式是到餐厅现场购买,由于职工工作繁忙,如果采用电话预约订餐,在中午就餐时间段,电话常常占线,并且餐厅人员通过纸和笔记录,手工制作食品制作计 ...

  8. 微信订餐系统怎么建设?

    随着信息技术的发展,各种应用和娱乐工具不断涌现,微信就是最新兴起的一种.据了解,微信用户现在已经超过5亿,这样庞大的用户群自然也让敏锐的商界垂涎三尺,通过微信开放平台接口嫁接的各种微信功能类服务,比如 ...

  9. 微信订餐系统项目回顾

    项目地址:https://github.com/wanger61/Springboot- 1.系统流程 该项目分为买家端和卖家端两部分: 买家端为微信端,可以在买家端查看商品,创建订单/查询订单和支付 ...

最新文章

  1. mysql启用keepalive_keepalive+mysql 主主配置
  2. 谷歌2020博士生奖研金名单出炉,大陆高校无一人入选
  3. 一些经常会用到的vbscript检测函数
  4. android与mysql的交互,与Android中的外部SQLite数据库进行交互.
  5. python罗马数字转换,Python3.5实现的罗马数字转换成整数功能示例
  6. openwrt是嵌入式linux,非常方便的OpenWrt的嵌入式Linux开发环境
  7. JSpider(4):Tasks,EventsVisitors
  8. bzoj 1677: [Usaco2005 Jan]Sumsets 求和(DP)
  9. 信息论与贝叶斯(二)
  10. Go语言优秀Web框架
  11. Proteus进行单片机仿真(一)
  12. 《Redis开发与运维》第一章 初识Redis 读书笔记
  13. 批量添加时id使用mybatisplus的id生成策略
  14. 老鸟必备 | 如何画出优秀的架构图
  15. Reason: Cannot pass null or empty values to constructor in spring security
  16. 移动端天气系统--【下雨】效果之【雨滴】的实现和分析
  17. 服务器宝塔Error: connect ETIMEDOUT
  18. webstorm注册码
  19. 凭借渠道优势穿越风险?科大讯飞探索AI新应用场景
  20. 自考深圳大学计算机专业难吗,深圳大学全日制自考本科有用吗?计算机与软件学院自考办通过率...

热门文章

  1. 用选择法对10个整数进行升序排序
  2. 教程 |10分钟成为简笔画达人 9 (一大波蠢萌小动物来袭)
  3. JVM in a nut shell
  4. 【保研经验】来自一只five的一点经验(最终去向:西电广研院专硕)
  5. 【TRIO-Basic从入门到精通教程十七】设置连接TRIO运动控制器并输入激活码
  6. java 8 lambda·List操作
  7. 免费的oa办公系统好吗?
  8. java xml stax_java XML -- SAX和StAX分析XML
  9. linux mp4 开源播放器,Linux下五款轻量级音乐播放器(开源).doc
  10. 用所学JS的知识做一个简单的坦克小游戏