品优购项目笔记(一)

springSecurity的注意事项

在分布式项目中,使用springSecurity的注意事项

  1. springSecurity如果需要去数据库中找对应的用户对象进行验证, 就需要自定义UserDetailService实现类
  2. 因为在自定义的service中需要使用其他的service到数据库中查询, 所以需要注入, 而这里sellerService是在service-sellerGoods项目中, 跨项目调用需要使用dubbo注入.
  3. 在springMvc.xml中虽然配置了包扫描但是扫描的是controller包, 只有在这个包下面写@Refrence注解才会生效
  4. 在我们UserDetailService实现类中无法使用dubbo注解进行注入(无法进行多次扫描,这是dubbo的bug), 所以我们这里利用xml配置文件的标签<dubbo:refrence>进行注入sellerService
  5. 在userDetailService中如果使用@Service注解无法指定注入的属性或者是对象, 所以这里我们使用最原始的set方法注入, 可以在配置文件中配置bean, 在bean标签了配置<property>标签注入SellerService属性
package cn.itcast.core.service;

import cn.itcast.core.pojo.seller.Seller;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import java.util.ArrayList;
import java.util.List;

/**
 * 自定义验证类,实现springSecurity框架的userDetailService接口
 */
public class UserDetailServiceImpl implements UserDetailsService {

    private SellerService sellerService;

    public void setSellerService(SellerService sellerService) {
        this.sellerService = sellerService;
    }

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        List<GrantedAuthority> authList = new ArrayList<>();
        authList.add(new SimpleGrantedAuthority("ROLE_SELLER"));

        //1.判断用户名是否为空
        if (username==null){
            return null;
        }
        //2.根据用户名到数据库查询对应的用户对象
        Seller seller = sellerService.findOne(username);
        //3.如果查不到
        if(seller != null){
            if("1".equals(seller.getStatus())){


                return new User(username,seller.getPassword(),authList);
            }
        }


        return null;
    }
}

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans 
	xmlns="http://www.springframework.org/schema/security"
	xmlns:beans="http://www.springframework.org/schema/beans" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" 
	
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
						http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
						http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">
	
	<http pattern="/*.html" security="none"/>
	<http pattern="/css/**" security="none"/>
	<http pattern="/img/**" security="none"/>
	<http pattern="/js/**" security="none"/>
	<http pattern="/plugins/**" security="none"/>
	<http pattern="/seller/add.do" security="none"/>
	
	<!-- use-expressions:设置是否启动SpEL表达式,默认值是true。 -->
	<http use-expressions="false">
		<!-- 
			配置SpringSecurity的拦截路径(拦截规则) 
			* pattern:配置拦截规则。   /* 代表的是根路径下的所有资源(不包含子路径) /**代表的是根路径下所有的资源(包含子路径)
			* access:设置角色  角色命名 ROLE_角色名称  如:  ROLE_USER  
		-->
		<intercept-url pattern="/**" access="ROLE_SELLER"/>
		
		<!-- 
		开启表单验证 
			username-parameter="username" 
			password-parameter="password" 
			login-page			:登录页面名称  以  / 开始
			default-target-url	:登录成功后跳转的页面
			login-processing-url:提交的路径的设置 默认值"/login" 可以修改
		-->
		<form-login login-page="/shoplogin.html" default-target-url="/admin/index.html" always-use-default-target="true" authentication-failure-url="/shoplogin.html"/>
		
		<!-- 不使用csrf的校验 -->
		<csrf disabled="true"/>
		
		<!-- 配置框架页面不拦截 -->
		<headers>
			<frame-options policy="SAMEORIGIN"/>
		</headers>
		
		<!-- 注销的配置 -->
		<logout logout-url="/logout" logout-success-url="/shoplogin.html" />
	</http>
	
	<!-- 配置认证管理器 -->
	<authentication-manager>
		<!-- 认证的提供者 -->
		<authentication-provider user-service-ref="userDetailService">
<!--			<password-encoder ref="passwordEncoder"></password-encoder>	-->
		</authentication-provider>
	</authentication-manager>
		

	<!-- 引用dubbo 服务 -->	
	<dubbo:application name="pinyougou-shop-web" />
	<dubbo:registry address="zookeeper://192.168.200.128:2181"/>
	<dubbo:reference id="sellerService"  interface="cn.itcast.core.service.SellerService" >
	</dubbo:reference>
	
	<!-- 配置自定义的认证类 -->
	<beans:bean id="userDetailService" class="cn.itcast.core.service.UserDetailServiceImpl">
		<beans:property name="sellerService" ref="sellerService"></beans:property>
	</beans:bean>


	<beans:bean id="passwordEncoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"/>
</beans:beans>

springSecurity的登陆流程

在这里插入图片描述

自关联表

自关联表, 自己关联自己, 这张表有主键id唯一, 有parentid字段指定父级的主键id
自关联表

  • 优点: 一张表可以通过这种关系做成一个树状关系
  • 缺点: 在这张表数据量大的时候, 如果想展示整棵树所有节点数据加载会非常慢.

表的纵切

使用场景: 一张表字段太多, 几十个甚至上百个字段, 没查询一条或者多条的时候, 返回数据太多,页面展示不下, 所以没有必要一次性返回过都数据, 这个时候可以根据页面需要展示的数据, 将一张表切分成多张表, 多张表的关系是一对一.

  • 优点: 每次查询的时候返回数据量会变小, 提高网络io和磁盘io效率. 查询速度变快
  • 缺点: 如果确实需要一次返回所有数据, 返回的数据量依然大, 增加表关系的复杂度. 不利于sql语句的编写.

spu和sku

  • SPU标准产品单位: 就是一个产品的统称, 是一个商品的单位
  • SKU库存量单位: 一个产品的所有型号, 所有价钱, 所有规格都列出来, 具体的详细的每一个单位, 也就是库存单位

SPU: iphone8
SKU: iphone8 64G 8000元 白色 联通
iphone8 64G 8000元 黑色 联通
iphone8 128G 9000元 黑色 联通
iphone8 128G 9000元 白色 联通
iphone8 64G 8000元 白色 移动
iphone8 64G 8000元 黑色 移动
iphone8 128G 9000元 黑色 移动
iphone8 128G 9000元 白色 移动
一个SPU单位对应多个SKU单位

在这里插入图片描述

商品添加五级联动

angular的下拉框
在这里插入图片描述

<select class="form-control" ng-model="entity.goods.category1Id" 
	ng-options="xxx.id as xxx.name for xxx in itemCat1List">	
  • ng-model: 将下拉框选中的数据, 封装到$scope域中变量叫做entity.goods.category1Id
  • ng-option:指定下来选项的各项内容, 它的语法是for循环itemCat1List这个集合变量, 每次循环赋值给xxx这个变量xxx.id作为key xxx.name作为value, 选中一个后, 提交的数据是key, 这里as , for, in 都是语法关键字

angular的内置对象$watch

// 查询二级分类列表:
	$scope.$watch("entity.goods.category1Id",function(newValue,oldValue){
		itemCatService.findByParentId(newValue).success(function(response){
			$scope.itemCat2List = response;
		});
	});

$watch是angularjs中的内置对象, 作用是监听$scope域中的某个变量发生了值的改变.

富文本编辑器

我们这里使用的是kindEditor这个. 其实就是一款网页版的word, 可以对文字图片等进行排版功能.都是使用js+css实现的, 如果我们保存富文本编辑器里面的数据, 保存到数据库中是 文字+html+css

  • KindEditor: http://kindeditor.net/
  • UEditor: http://ueditor.baidu.com/website/
  • CKEditor: http://ckeditor.com/

引入js和css

<!-- 富文本编辑器 -->
	<link rel="stylesheet" href="../plugins/kindeditor/themes/default/default.css" />
	<script charset="utf-8" src="../plugins/kindeditor/kindeditor-min.js"></script>
	<script charset="utf-8" src="../plugins/kindeditor/lang/zh_CN.js"></script>

添加textarea,name设置为content

 <textarea name="content" style="width:800px;height:400px;visibility:hidden;" ></textarea>

添加js

            <!-- 正文区域 /-->
<script type="text/javascript">

	var editor;
	KindEditor.ready(function(K) {
		editor = K.create('textarea[name="content"]', {
			allowFileManager : true
		});
	});

</script>

在这里插入图片描述

JVM中堆的内部结构

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/Sakuraaaaaaa/article/details/106568307