SSM综合练习

案例中的数据库表格有

  • 产品表
  • 订单表
  • 会员表
  • 旅客表
  • 用户表
  • 角色表
  • 资源权限表

其中订单表

  • 多个订单对应一个会员(导游)
  • 一个订单对应一个产品
  • 一个订单可以对应多个旅客,一个旅客可以对应多个订单,多对多的关系
    在这里插入图片描述

PageHelper

从侧栏访问订单

  • page,pageSize属性
</a></li>
					<li id="system-setting"><a
						href="${pageContext.request.contextPath}/orders/findAll.do?page=1&pageSize=3"> <i
							class="fa fa-circle-o"></i> 订单管理
					</a></li>

控制类,配置分页器
每一页的PageInfo都有以下值

  • pageSize
  • pages
 @RequestMapping("/findAll.do")
    public ModelAndView findAll(@RequestParam(name = "page", required = true, defaultValue = "1") int page, @RequestParam(name = "size", required = true, defaultValue = "4") int size) throws Exception {
        ModelAndView mv = new ModelAndView();
        List<Orders> ordersList = ordersService.findAll(page, size);
        //PageInfo就是一个分页Bean
        PageInfo pageInfo = new PageInfo(ordersList);
        mv.addObject("pageInfo", pageInfo);
        mv.setViewName("orders-page-list");
        return mv;
    }

Service里调用

@Override
    public List<Orders> findAll(int page, int size) throws Exception {

        //参数pageNum 是页码值   参数pageSize 代表是每页显示条数
        PageHelper.startPage(page, size);
        return ordersDao.findAll();
    }

订单展示

  • 在order-page-list里
<div class="box-footer">
                    <div class="pull-left">
                        <div class="form-group form-inline">
                            总共2 页,共14 条数据。 每页
                            <select class="form-control" id="changePageSize" onchange="changePageSize()">
                                <option>1</option>
                                <option>2</option>
                                <option>3</option>
                                <option>4</option>
                                <option>5</option>
                            </select></div>
                    </div>

                    <div class="box-tools pull-right">
                        <ul class="pagination">
                            <li>
                                <a href="${pageContext.request.contextPath}/orders/findAll.do?page=1&size=${pageInfo.pageSize}" aria-label="Previous">首页</a>
                            </li>
                            <li><a href="${pageContext.request.contextPath}/orders/findAll.do?page=${pageInfo.pageNum-1}&size=${pageInfo.pageSize}">上一页</a></li>
                           <c:forEach begin="1" end="${pageInfo.pages}" var="pageNum">
                           //var="pageNum"
							   <li><a href="${pageContext.request.contextPath}/orders/findAll.do?page=${pageNum}&size=${pageInfo.pageSize}">${pageNum}</a></li>
						   </c:forEach>
                            <li><a href="${pageContext.request.contextPath}/orders/findAll.do?page=${pageInfo.pageNum+1}&size=${pageInfo.pageSize}">下一页</a></li>
                            <li>
                                <a href="${pageContext.request.contextPath}/orders/findAll.do?page=${pageInfo.pages}&size=${pageInfo.pageSize}" aria-label="Next">尾页</a>
                            </li>
                        </ul>
                    </div>

                </div>

script

  • 下拉选择,一页展示多少条数据
function changePageSize() {
			//获取下拉框的值
			var pageSize = $("#changePageSize").val();

			//向服务器发送请求,改变没页显示条数
			location.href = "${pageContext.request.contextPath}/orders/findAll.do?page=1&size="
					+ pageSize;
		}

用户表、角色表

请添加图片描述

SpringSecurity

  • 使用数据库去登录
  • SpringSecurity.xml文件配置登录,登录成功、失败页面信息
  • 配置userService类,利用@Service(“userService”)注解跳转,该类的作用是验证授权

请添加图片描述

 <security:form-login
                login-page="/login.jsp"
                login-processing-url="/login.do"
                default-target-url="/index.jsp"
                authentication-failure-url="/failer.jsp"
                authentication-success-forward-url="/pages/main.jsp"
        />
  • 通过中转login.do,授权成功去到/pages/main.jsp,失败去到/failer.jsp

授权配置

    <!-- 切换成数据库中的用户名和密码 -->
    <security:authentication-manager>
        <security:authentication-provider user-service-ref="userService">
            <!-- 配置加密的方式 -->
<!--            <security:password-encoder ref="passwordEncoder"/>-->
        </security:authentication-provider>
    </security:authentication-manager>

接口

public interface IUserService extends UserDetailsService {
}

public class UserServiceImpl implements IUserService {
    @Autowired
    private IUserDao userDao;


    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        UserInfo userInfo=null;

            //通过s=username找到userInfo
        try {
            userInfo=userDao.findByUsername(s);
        } catch (Exception e) {
            e.printStackTrace();
        }

        //处理自己用户对象封装成UserDetails
        //第5个参数是权限
        //返回值时会做密码,权限的检验
        User user=new User(userInfo.getUsername(),"{noop}"+userInfo.getPassword(),userInfo.getStatus()==0?false:true,true,true,true,getAuthority(userInfo.getRoles()));
        return user;
    }


    public List<SimpleGrantedAuthority> getAuthority(List<Role> roles){
        List<SimpleGrantedAuthority> list=new ArrayList<>();
        for(Role role:roles)
        {
            list.add(new SimpleGrantedAuthority("ROLE_"+role.getRoleName()));
        }
        return list;
    }



}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值