SpringBoot+Mybatis Plus开发博客系统

一.下载layui社区的模版

https://fly.layui.com/store/FlyTemplate/

二.springboot热部署

参考(https://blog.csdn.net/panruola/article/details/87890234)
2.1导入依赖

>
    >org.springframework.boot>
    >spring-boot-devtools>
    >true>
>

2.2Compiler,勾选 “Make project automatically”
SpringBoot+Mybatis Plus开发博客系统_第1张图片
3.3.快捷键 Shift+Ctrl+Alt+/ ,选择 “Registry” ,选中打勾 “compiler.automake.allow.when.app.running”
SpringBoot+Mybatis Plus开发博客系统_第2张图片

三.导入到springboot项目中(抽取片段)

我们可以抽取功能的片段:比如comment.html中公共的css样式(title不一样,我们可以通过参数传过来)

<!DOCTYPE html>
:th="http://www.thymeleaf.org">
:fragment="commentStyle">
    -8">
    :</span>text="$<span class="token punctuation">{</span>title<span class="token punctuation">}</span>"<span class="token punctuation">></span>基于 layui 的极简社区页面模版</title<span class="token punctuation">></span>
    <meta name="viewport" content="width=device<span class="token punctuation">-</span>width<span class="token punctuation">,</span> initial<span class="token punctuation">-</span>scale=1<span class="token punctuation">,</span> maximum<span class="token punctuation">-</span>scale=1"<span class="token punctuation">></span>
    <meta name="keywords" content="fly<span class="token punctuation">,</span>layui<span class="token punctuation">,</span>前端社区"<span class="token punctuation">></span>
    <meta name="description" content="Fly社区是模块化前端UI框架Layui的官网社区,致力于为web开发提供强劲动力"<span class="token punctuation">></span>
    <link rel="stylesheet" th<span class="token punctuation">:</span>href="@<span class="token punctuation">{</span>/static/layui/css/layui.css<span class="token punctuation">}</span>"<span class="token punctuation">></span>
    <link rel="stylesheet" th<span class="token punctuation">:</span>href="@<span class="token punctuation">{</span>/static/css/global.css<span class="token punctuation">}</span>"<span class="token punctuation">></span>
</head<span class="token punctuation">></span>
<body<span class="token punctuation">></span>
</code></pre> 
  <p><strong>引入:</strong></p> 
  <pre><code class="prism language-yaml"><<span class="token tag">!--引入公共头部样式--></span>
<head th<span class="token punctuation">:</span>replace="~<span class="token punctuation">{</span>inc/comment<span class="token punctuation">:</span><span class="token punctuation">:</span>commentStyle(title='首页')<span class="token punctuation">}</span>"<span class="token punctuation">></span>
</code></pre> 
  <h2>四.controller中防止非整形访问该URL会报异常,所以通过id:\\d*来只允许整形通过</h2> 
  <pre><code class="prism language-yaml">    /*
    博客详细页面
    id<span class="token punctuation">:</span>\d*只允许传的参数为整形
     */
    @GetMapping("/post/<span class="token punctuation">{</span>id<span class="token punctuation">:</span>\\d*<span class="token punctuation">}</span>")
    public String detail(@PathVariable("id") Long id)<span class="token punctuation">{</span>
        return "post/detail";
    <span class="token punctuation">}</span>
</code></pre> 
  <h2>五.导航栏的信息通过项目启动就存进容器中,这样项目一运行就查询数据库中的数据</h2> 
  <p>1.创建一个类实现ApplicationRunner和ServletContextAware类</p> 
  <ol> 
   <li>ApplicationRunner用于在项目运行就执行</li> 
   <li>ServletContextAware用于获取容器上下文</li> 
  </ol> 
  <p>2.运行项目查询数据库中数据,并存进上下文</p> 
  <pre><code class="prism language-java"><span class="token keyword">package</span> com<span class="token punctuation">.</span>wcy<span class="token punctuation">.</span>eblog<span class="token punctuation">.</span>config<span class="token punctuation">;</span>

<span class="token keyword">import</span> com<span class="token punctuation">.</span>baomidou<span class="token punctuation">.</span>mybatisplus<span class="token punctuation">.</span>core<span class="token punctuation">.</span>conditions<span class="token punctuation">.</span>query<span class="token punctuation">.</span>QueryWrapper<span class="token punctuation">;</span>
<span class="token keyword">import</span> com<span class="token punctuation">.</span>wcy<span class="token punctuation">.</span>eblog<span class="token punctuation">.</span>entity<span class="token punctuation">.</span>MCategory<span class="token punctuation">;</span>
<span class="token keyword">import</span> com<span class="token punctuation">.</span>wcy<span class="token punctuation">.</span>eblog<span class="token punctuation">.</span>service<span class="token punctuation">.</span>MCategoryService<span class="token punctuation">;</span>
<span class="token keyword">import</span> org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>beans<span class="token punctuation">.</span>factory<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span>Autowired<span class="token punctuation">;</span>
<span class="token keyword">import</span> org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>boot<span class="token punctuation">.</span>ApplicationArguments<span class="token punctuation">;</span>
<span class="token keyword">import</span> org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>boot<span class="token punctuation">.</span>ApplicationRunner<span class="token punctuation">;</span>
<span class="token keyword">import</span> org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>context<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span>Bean<span class="token punctuation">;</span>
<span class="token keyword">import</span> org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>stereotype<span class="token punctuation">.</span>Component<span class="token punctuation">;</span>
<span class="token keyword">import</span> org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>web<span class="token punctuation">.</span>context<span class="token punctuation">.</span>ServletContextAware<span class="token punctuation">;</span>

<span class="token keyword">import</span> javax<span class="token punctuation">.</span>servlet<span class="token punctuation">.</span>ServletContext<span class="token punctuation">;</span>
<span class="token keyword">import</span> java<span class="token punctuation">.</span>util<span class="token punctuation">.</span>List<span class="token punctuation">;</span>

<span class="token comment">/**
 * ApplicationRunner 容器在启动的时候就会执行
 * ServletContextAware获取上下文容器
 * 把分类(导航栏)存进上下文容器中 (便于速度更快)
 */</span>
<span class="token annotation punctuation">@Component</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ContextStartUp</span> <span class="token keyword">implements</span> <span class="token class-name">ApplicationRunner</span><span class="token punctuation">,</span> ServletContextAware <span class="token punctuation">{</span>
    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> MCategoryService mCategoryService<span class="token punctuation">;</span>

    ServletContext servletContext<span class="token punctuation">;</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">run</span><span class="token punctuation">(</span>ApplicationArguments args<span class="token punctuation">)</span> <span class="token keyword">throws</span> Exception <span class="token punctuation">{</span>
        <span class="token comment">//查询status=0的所有分类导航栏 若为1则不查询</span>
        List<span class="token generics function"><span class="token punctuation"><</span>MCategory<span class="token punctuation">></span></span> mCategoryList <span class="token operator">=</span> mCategoryService<span class="token punctuation">.</span><span class="token function">list</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">QueryWrapper</span><span class="token generics function"><span class="token punctuation"><</span>MCategory<span class="token punctuation">></span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">eq</span><span class="token punctuation">(</span><span class="token string">"status"</span><span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//把查询到的数据存进容器中</span>
        servletContext<span class="token punctuation">.</span><span class="token function">setAttribute</span><span class="token punctuation">(</span><span class="token string">"mCategoryList"</span><span class="token punctuation">,</span> mCategoryList<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">setServletContext</span><span class="token punctuation">(</span>ServletContext servletContext<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>servletContext<span class="token operator">=</span>servletContext<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

</code></pre> 
  <p>3.thymeleaf获取容器上下文的方法</p> 
  <pre><code class="prism language-yaml">            <li th<span class="token punctuation">:</span>each="category<span class="token punctuation">:</span>$<span class="token punctuation">{</span><span class="token comment">#servletContext.getAttribute('mCategoryList')}"></span>
                <a th<span class="token punctuation">:</span>href="@<span class="token punctuation">{</span>'/catalog/'+$<span class="token punctuation">{</span>category.id<span class="token punctuation">}</span><span class="token punctuation">}</span>"<span class="token punctuation">></span><span class="token punctuation">[</span><span class="token punctuation">[</span>$<span class="token punctuation">{</span>category.name<span class="token punctuation">}</span><span class="token punctuation">]</span><span class="token punctuation">]</span></a<span class="token punctuation">></span>
            </li<span class="token punctuation">></span>
</code></pre> 
  <h2>六.thymeleaf处理时间显示成几小时前</h2> 
  <pre><code class="prism language-yaml">              <<span class="token tag">!--对时间处理成几小时前--></span><span class="token scalar string">
              <span th:datetime="${#dates.format(postVo.created, 'yyyy-MM-dd HH:mm')}" class="time"></span>
              <script src="https://cdn.bootcss.com/timeago.js/3.0.2/timeago.js"></script>
              <script></span>

                  // 自动更新
                  var timeagoInstance = timeago();// 实例
                  timeagoInstance.render(document.querySelectorAll('.time')<span class="token punctuation">,</span>'zh_CN');
              </script<span class="token punctuation">></span>
</code></pre> 
  <h2>七.注意layui分页的JS需要等页面加载完毕才执行</h2> 
  <p>问题:防止layui分页消失,不会出现分页按钮<br> 解决:</p> 
  <pre><code class="prism language-yaml">放到JQ的加载完毕才会执行的方法

$(function()<span class="token punctuation">{</span>
           
           
 <span class="token punctuation">}</span>);
</code></pre> 
  <h2>八.实现博客七天回复量排行榜(redis实现)</h2> 
  <p>1.实现逻辑:</p> 
  <ol> 
   <li>查询数据库中前七天的博客以及博客的评论数</li> 
   <li>通过redis的zset有序集合key存关于天数的(博客创建的那一天 有序map),然后zset里面的key存博客id之类的,分数存评论数<br> 比如:2020-7-2日有哪些博客创建了并且评论了,那么就会存进这个有序集合的key里面(见下图)</li> 
  </ol> 
  <p><a href="http://img.e-com-net.com/image/info8/b7f3c7d3f2e740d1986cc908cbfde0e8.png" target="_blank"><img src="http://img.e-com-net.com/image/info8/b7f3c7d3f2e740d1986cc908cbfde0e8.png" alt="SpringBoot+Mybatis Plus开发博客系统_第3张图片" width="510" height="109" style="border:1px solid black;"></a><br> 4. 因为web端需要展示博客的标题、评论数,所有还需要通过一个hash来存储这些数据。<br> 5. 这些都需要设置一个过期时间 超出七天则清除</p> 
  <p><strong>2.对应的service逻辑方法:</strong></p> 
  <pre><code class="prism language-java">    <span class="token comment">//初始化本周热议</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">initWeekRank</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">//1.查询七天内的博客</span>
        <span class="token comment">//DateUtil.offset(new Date(), DateField.DAY_OF_MONTH,-7)获取当前时间的第前七天的时间</span>
        List<span class="token generics function"><span class="token punctuation"><</span>MPost<span class="token punctuation">></span></span> mPosts <span class="token operator">=</span> mPostMapper<span class="token punctuation">.</span><span class="token function">selectList</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">QueryWrapper</span><span class="token generics function"><span class="token punctuation"><</span>MPost<span class="token punctuation">></span></span><span class="token punctuation">(</span><span class="token punctuation">)</span>
                <span class="token punctuation">.</span><span class="token function">ge</span><span class="token punctuation">(</span><span class="token string">"created"</span><span class="token punctuation">,</span> DateUtil<span class="token punctuation">.</span><span class="token function">offset</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> DateField<span class="token punctuation">.</span>DAY_OF_MONTH<span class="token punctuation">,</span><span class="token operator">-</span><span class="token number">7</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
                <span class="token punctuation">.</span><span class="token function">gt</span><span class="token punctuation">(</span><span class="token string">"comment_count"</span><span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token comment">//评论数大于0</span>
        <span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//2.存进redis中</span>
        <span class="token keyword">for</span><span class="token punctuation">(</span>MPost mPost<span class="token operator">:</span>mPosts<span class="token punctuation">)</span><span class="token punctuation">{</span>
            String key<span class="token operator">=</span><span class="token string">"eblog:rank:time:"</span><span class="token operator">+</span>DateUtil<span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span>mPost<span class="token punctuation">.</span><span class="token function">getCreated</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token string">"yyyy-MM-dd"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token comment">//2.1//存进zset中</span>
            redisUtil<span class="token punctuation">.</span><span class="token function">zSet</span><span class="token punctuation">(</span>key<span class="token punctuation">,</span>mPost<span class="token punctuation">.</span><span class="token function">getId</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>mPost<span class="token punctuation">.</span><span class="token function">getCommentCount</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token comment">//2.2.计算当前时间与博客创建时间差  7-(18-14)</span>
            <span class="token keyword">long</span> time<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">7</span><span class="token operator">-</span>DateUtil<span class="token punctuation">.</span><span class="token function">between</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>mPost<span class="token punctuation">.</span><span class="token function">getCreated</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> DateUnit<span class="token punctuation">.</span>DAY<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token operator">*</span><span class="token number">24</span><span class="token operator">*</span><span class="token number">60</span><span class="token operator">*</span><span class="token number">60</span><span class="token punctuation">;</span>
            <span class="token comment">//2.3设置key消失时间</span>
            <span class="token keyword">boolean</span> expire <span class="token operator">=</span> redisUtil<span class="token punctuation">.</span><span class="token function">expire</span><span class="token punctuation">(</span>key<span class="token punctuation">,</span> time<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token comment">//2.4由于前端需要显示标题、评论数等信息</span>
            <span class="token function">hashCachePostIdAndTitle</span><span class="token punctuation">(</span>mPost<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        <span class="token comment">//3.计算某七天的评论数并逆序排序</span>
        <span class="token function">zUnionPost7DaysForWeekRand</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token comment">//计算七天内的评论数</span>
    <span class="token keyword">private</span> <span class="token keyword">void</span> <span class="token function">zUnionPost7DaysForWeekRand</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        String newKey<span class="token operator">=</span><span class="token string">"eblog:rank:7week"</span><span class="token punctuation">;</span>
        List<span class="token generics function"><span class="token punctuation"><</span>String<span class="token punctuation">></span></span> list<span class="token operator">=</span><span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token operator"><</span><span class="token operator">></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">for</span><span class="token punctuation">(</span><span class="token keyword">int</span> i<span class="token operator">=</span><span class="token operator">-</span><span class="token number">7</span><span class="token punctuation">;</span>i<span class="token operator"><</span><span class="token number">0</span><span class="token punctuation">;</span>i<span class="token operator">++</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token comment">//这七天的key存进list里面 用户求并集</span>
            String timeKey<span class="token operator">=</span><span class="token string">"eblog:rank:time:"</span><span class="token operator">+</span> DateUtil<span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span>DateUtil<span class="token punctuation">.</span><span class="token function">offsetDay</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>i<span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token string">"yyyy-MM-dd"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            list<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>timeKey<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        String key<span class="token operator">=</span><span class="token string">"eblog:rank:time:"</span><span class="token operator">+</span> DateUtil<span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token string">"yyyy-MM-dd"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        redisUtil<span class="token punctuation">.</span><span class="token function">zUnionAndStore</span><span class="token punctuation">(</span>key<span class="token punctuation">,</span>list<span class="token punctuation">,</span>newKey<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//timeKey</span>
    <span class="token punctuation">}</span>

    <span class="token comment">//把博客信息存进redis中</span>
    <span class="token keyword">private</span> <span class="token keyword">void</span> <span class="token function">hashCachePostIdAndTitle</span><span class="token punctuation">(</span>MPost mPost<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">//通过博客的ID来存储键</span>
        String key<span class="token operator">=</span><span class="token string">"eblog:rank:post:"</span><span class="token operator">+</span>mPost<span class="token punctuation">.</span><span class="token function">getId</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//计算当前时间与博客创建时间差  7-(18-14)</span>
        <span class="token keyword">long</span> time<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">7</span><span class="token operator">-</span>DateUtil<span class="token punctuation">.</span><span class="token function">between</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>mPost<span class="token punctuation">.</span><span class="token function">getCreated</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> DateUnit<span class="token punctuation">.</span>DAY<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token operator">*</span><span class="token number">24</span><span class="token operator">*</span><span class="token number">60</span><span class="token operator">*</span><span class="token number">60</span><span class="token punctuation">;</span>
        <span class="token comment">//存进redis中并设置过期时间</span>
        redisUtil<span class="token punctuation">.</span><span class="token function">hset</span><span class="token punctuation">(</span>key<span class="token punctuation">,</span><span class="token string">"id"</span><span class="token punctuation">,</span>mPost<span class="token punctuation">.</span><span class="token function">getId</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>time<span class="token punctuation">)</span><span class="token punctuation">;</span>
        redisUtil<span class="token punctuation">.</span><span class="token function">hset</span><span class="token punctuation">(</span>key<span class="token punctuation">,</span><span class="token string">"title"</span><span class="token punctuation">,</span>mPost<span class="token punctuation">.</span><span class="token function">getTitle</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>time<span class="token punctuation">)</span><span class="token punctuation">;</span>
        redisUtil<span class="token punctuation">.</span><span class="token function">hset</span><span class="token punctuation">(</span>key<span class="token punctuation">,</span><span class="token string">"commentCount"</span><span class="token punctuation">,</span>mPost<span class="token punctuation">.</span><span class="token function">getCommentCount</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>time<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</code></pre> 
  <p><strong>3.一旦用户评论或删除评论就修改缓存中评论的数目,并且重新更新缓存中的并集以及博客信息</strong></p> 
  <pre><code class="prism language-java">    <span class="token comment">/**
     * 增加或减少redis这篇博客的评论数
     * @param postId
     * @param isincr
     */</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">incrCommentWeekRank</span><span class="token punctuation">(</span>Long postId<span class="token punctuation">,</span> Boolean isincr<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        String key<span class="token operator">=</span><span class="token string">"eblog:rank:time:"</span><span class="token operator">+</span>DateUtil<span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token string">"yyyy-MM-dd"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        redisUtil<span class="token punctuation">.</span><span class="token function">zIncrementScore</span><span class="token punctuation">(</span>key<span class="token punctuation">,</span>postId<span class="token punctuation">,</span>isincr<span class="token operator">?</span><span class="token number">1</span><span class="token operator">:</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//判断是+1还是-1</span>
        <span class="token function">zUnionPost7DaysForWeekRand</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//重新更新七天的并集排行榜</span>
        MPost mPost <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">getById</span><span class="token punctuation">(</span>postId<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">hashCachePostIdAndTitle</span><span class="token punctuation">(</span>mPost<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//重新更新这篇博客信息</span>
    <span class="token punctuation">}</span>
</code></pre> 
  <h2>九.博客访问量</h2> 
  <p>1.比如查看某篇博客就更新缓存的访问量</p> 
  <pre><code class="prism language-java">    <span class="token annotation punctuation">@GetMapping</span><span class="token punctuation">(</span><span class="token string">"/post/{id:\\d*}"</span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> String <span class="token function">detail</span><span class="token punctuation">(</span><span class="token annotation punctuation">@PathVariable</span><span class="token punctuation">(</span><span class="token string">"id"</span><span class="token punctuation">)</span> Long id<span class="token punctuation">,</span>
    <span class="token annotation punctuation">@RequestParam</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"current"</span><span class="token punctuation">,</span>required <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">,</span>defaultValue <span class="token operator">=</span> <span class="token string">"1"</span><span class="token punctuation">)</span> Long current
            <span class="token punctuation">,</span><span class="token annotation punctuation">@RequestParam</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"size"</span><span class="token punctuation">,</span>required <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">,</span>defaultValue <span class="token operator">=</span> <span class="token string">"2"</span><span class="token punctuation">)</span> Long size<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token comment">//返回博客信息</span>
        PostVo postVo<span class="token operator">=</span>mPostService<span class="token punctuation">.</span><span class="token function">findPostById</span><span class="token punctuation">(</span>id<span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token comment">//实时更新缓存中访问量</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>mPostService<span class="token punctuation">.</span><span class="token function">putViewCount</span><span class="token punctuation">(</span>postVo<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//返回评论信息 1.分页 2.博客id 3.用户id 4.排序</span>
        IPage<span class="token generics function"><span class="token punctuation"><</span>CommentVo<span class="token punctuation">></span></span> commentVoIPage<span class="token operator">=</span>mCommentService<span class="token punctuation">.</span><span class="token function">pageingComment</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Page</span><span class="token punctuation">(</span>current<span class="token punctuation">,</span>size<span class="token punctuation">)</span><span class="token punctuation">,</span>id<span class="token punctuation">,</span>null<span class="token punctuation">,</span><span class="token string">"created"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        req<span class="token punctuation">.</span><span class="token function">setAttribute</span><span class="token punctuation">(</span><span class="token string">"PostVo"</span><span class="token punctuation">,</span>postVo<span class="token punctuation">)</span><span class="token punctuation">;</span>
        req<span class="token punctuation">.</span><span class="token function">setAttribute</span><span class="token punctuation">(</span><span class="token string">"CommentVo"</span><span class="token punctuation">,</span>commentVoIPage<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> <span class="token string">"post/detail"</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</code></pre> 
  <p><strong>2.更新缓存访问量,给实体的访问量重新赋值,这样传回前端访问量就自动修改了</strong><br> 通过标题八缓存的博客信息来获取访问量,无则使用实体的</p> 
  <pre><code class="prism language-java">    <span class="token comment">/**
     *更新缓存中访问量
     * @param postVo
     */</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">putViewCount</span><span class="token punctuation">(</span>PostVo postVo<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">//1.从缓存中拿出访问量 如果缓存中没有直接获取实体的访问量</span>
        String key<span class="token operator">=</span><span class="token string">"eblog:rank:post:"</span><span class="token operator">+</span>postVo<span class="token punctuation">.</span><span class="token function">getId</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        Integer viewCount <span class="token operator">=</span> <span class="token punctuation">(</span>Integer<span class="token punctuation">)</span>redisUtil<span class="token punctuation">.</span><span class="token function">hget</span><span class="token punctuation">(</span>key<span class="token punctuation">,</span> <span class="token string">"viewCount"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span><span class="token punctuation">(</span>viewCount<span class="token operator">!=</span>null<span class="token punctuation">)</span><span class="token punctuation">{</span>
            postVo<span class="token punctuation">.</span><span class="token function">setViewCount</span><span class="token punctuation">(</span>viewCount<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token keyword">else</span><span class="token punctuation">{</span>
            postVo<span class="token punctuation">.</span><span class="token function">setViewCount</span><span class="token punctuation">(</span>postVo<span class="token punctuation">.</span><span class="token function">getViewCount</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token comment">//2.更新缓存数据</span>
        redisUtil<span class="token punctuation">.</span><span class="token function">hset</span><span class="token punctuation">(</span>key<span class="token punctuation">,</span><span class="token string">"viewCount"</span><span class="token punctuation">,</span>postVo<span class="token punctuation">.</span><span class="token function">getViewCount</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</code></pre> 
  <h2>十.redis不能存储Long类型</h2> 
  <p>redis不能存储Long类型,会把Long类型转换为Integer类型,所以如果想要获取到long类型,就需要:</p> 
  <pre><code class="prism language-java">   Integer id <span class="token operator">=</span> <span class="token punctuation">(</span>Integer<span class="token punctuation">)</span>redisUtil<span class="token punctuation">.</span><span class="token function">hget</span><span class="token punctuation">(</span>key<span class="token punctuation">,</span> <span class="token string">"id"</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//博客ID</span>
   Long idLong <span class="token operator">=</span> Long<span class="token punctuation">.</span><span class="token function">valueOf</span><span class="token punctuation">(</span>id<span class="token punctuation">.</span><span class="token function">longValue</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> 
  <h2>十一.springboot使用定时任务:</h2> 
  <p>1.开启定时任务</p> 
  <pre><code class="prism language-java"><span class="token comment">//开启定时任务</span>
<span class="token annotation punctuation">@EnableScheduling</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">EblogApplication</span> <span class="token punctuation">{</span>

    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span>String<span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        SpringApplication<span class="token punctuation">.</span><span class="token function">run</span><span class="token punctuation">(</span>EblogApplication<span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> args<span class="token punctuation">)</span><span class="token punctuation">;</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"http://localhost:8088"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre> 
  <p><strong>2.使用 @Scheduled(fixedRate = 60<em>60</em>1000)注解 (每一小时执行一次)</strong><br> <strong>参数配置:</strong><br> fixedRate = 10<em>1000 固定每10秒执行一次<br> fixedDelay = 10</em>1000 延迟每10秒执行一次<br> cron = “0 0 2 * * ?” //每天凌晨两点执行 https://qqe2.com/cron可配置cron<br> <strong>3.cron的更多配置。</strong><br> 每隔5秒执行一次:*/5 * * * * ?<br> 每隔1分钟执行一次:0 */1 * * * ?</p> 
  <p>每天23点执行一次:0 0 23 * * ?</p> 
  <p>每天凌晨1点执行一次:0 0 1 * * ?</p> 
  <p>每月1号凌晨1点执行一次:0 0 1 1 * ?</p> 
  <p>每月最后一天23点执行一次:0 0 23 L * ?</p> 
  <p>每周星期天凌晨1点实行一次:0 0 1 ? * L</p> 
  <p>在26分、29分、33分执行一次:0 26,29,33 * * * ?</p> 
  <p>每天的0点、13点、18点、21点都执行一次:0 0 0,13,18,21 * * ?</p> 
  <h2>十二.springboot实现定时更新访问量</h2> 
  <pre><code class="prism language-java"><span class="token comment">/**
 * 定时更新访问量
 */</span>
<span class="token annotation punctuation">@Component</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ViewCountSyncTask</span> <span class="token punctuation">{</span>
    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> RedisUtil redisUtil<span class="token punctuation">;</span>
    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> RedisTemplate<span class="token generics function"><span class="token punctuation"><</span>String<span class="token punctuation">,</span>Object<span class="token punctuation">></span></span> redisTemplate<span class="token punctuation">;</span>
    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> MPostService mPostService<span class="token punctuation">;</span>
    <span class="token comment">/**
     * @Scheduled进行定时任务
     * fixedRate = 10*1000 固定每10秒执行一次
     * fixedDelay = 10*1000 延迟每10秒执行一次
     * cron = "0 0 2 * * ?" //每天凌晨两点执行     https://qqe2.com/cron可配置cron
     *
     */</span>
    <span class="token annotation punctuation">@Scheduled</span><span class="token punctuation">(</span>fixedRate <span class="token operator">=</span> <span class="token number">60</span><span class="token operator">*</span><span class="token number">60</span><span class="token operator">*</span><span class="token number">1000</span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">viewCountTast</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token comment">//1.获取缓存中访问量</span>
        Set<span class="token generics function"><span class="token punctuation"><</span>String<span class="token punctuation">></span></span> keys <span class="token operator">=</span> redisTemplate<span class="token punctuation">.</span><span class="token function">keys</span><span class="token punctuation">(</span><span class="token string">"eblog:rank:post:*"</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//查询有eblog:rank:post:所有key</span>
        List<span class="token generics function"><span class="token punctuation"><</span>MPost<span class="token punctuation">></span></span> posts<span class="token operator">=</span><span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token operator"><</span><span class="token operator">></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">for</span><span class="token punctuation">(</span>String key<span class="token operator">:</span>keys<span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token comment">//查看缓存中是否有访问量</span>
            <span class="token keyword">if</span><span class="token punctuation">(</span>redisUtil<span class="token punctuation">.</span><span class="token function">hHasKey</span><span class="token punctuation">(</span>key<span class="token punctuation">,</span><span class="token string">"viewCount"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                Integer id <span class="token operator">=</span> <span class="token punctuation">(</span>Integer<span class="token punctuation">)</span>redisUtil<span class="token punctuation">.</span><span class="token function">hget</span><span class="token punctuation">(</span>key<span class="token punctuation">,</span> <span class="token string">"id"</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//博客ID</span>
                Long idLong <span class="token operator">=</span> Long<span class="token punctuation">.</span><span class="token function">valueOf</span><span class="token punctuation">(</span>id<span class="token punctuation">.</span><span class="token function">longValue</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                Integer viewCount <span class="token operator">=</span> <span class="token punctuation">(</span>Integer<span class="token punctuation">)</span>redisUtil<span class="token punctuation">.</span><span class="token function">hget</span><span class="token punctuation">(</span>key<span class="token punctuation">,</span> <span class="token string">"viewCount"</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//博客访问量</span>
                MPost post<span class="token operator">=</span><span class="token keyword">new</span> <span class="token class-name">MPost</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                post<span class="token punctuation">.</span><span class="token function">setId</span><span class="token punctuation">(</span>idLong<span class="token punctuation">)</span><span class="token punctuation">;</span>
                post<span class="token punctuation">.</span><span class="token function">setViewCount</span><span class="token punctuation">(</span>viewCount<span class="token punctuation">)</span><span class="token punctuation">;</span>
                posts<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>post<span class="token punctuation">)</span><span class="token punctuation">;</span>

                <span class="token comment">//更新之后这些访问量缓存里面的数据需要清空(清空的原因:</span>
                <span class="token comment">// 如果不删除 下次执行这个方法就又会查出很多viewCount这个缓存 以至于上方的list会很大</span>
                redisUtil<span class="token punctuation">.</span><span class="token function">hdel</span><span class="token punctuation">(</span>key<span class="token punctuation">,</span><span class="token string">"viewCount"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>

        <span class="token comment">//2.判断是否需要更新到数据库</span>
        <span class="token keyword">if</span><span class="token punctuation">(</span>posts<span class="token punctuation">.</span><span class="token function">isEmpty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">return</span><span class="token punctuation">;</span>

        <span class="token comment">//3.批量更新数据库</span>
        <span class="token keyword">boolean</span> isUpdate <span class="token operator">=</span> mPostService<span class="token punctuation">.</span><span class="token function">updateBatchById</span><span class="token punctuation">(</span>posts<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span><span class="token punctuation">(</span>isUpdate<span class="token punctuation">)</span><span class="token punctuation">{</span>
            System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"------------------访问量更新数据库成功--------------------"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> 
  <h2>十三.springboot使用Hibernate Validator校验pojo的某些字段</h2> 
  <p><strong>1.spring-boot-starter-web包里面有hibernate-validator包,不需要引用hibernate validator依赖。</strong><br> 2.比如邮箱验证(不能为空和格式)</p> 
  <pre><code class="prism language-java"><span class="token keyword">import</span> javax<span class="token punctuation">.</span>validation<span class="token punctuation">.</span>constraints<span class="token punctuation">.</span>Email<span class="token punctuation">;</span>
<span class="token keyword">import</span> javax<span class="token punctuation">.</span>validation<span class="token punctuation">.</span>constraints<span class="token punctuation">.</span>NotBlank<span class="token punctuation">;</span>
    <span class="token annotation punctuation">@Email</span>
    <span class="token annotation punctuation">@NotBlank</span><span class="token punctuation">(</span>message <span class="token operator">=</span> <span class="token string">"邮箱不能为空"</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> String email<span class="token punctuation">;</span>
</code></pre> 
  <p>3.添加hibernate validator的工具类</p> 
  <pre><code class="prism language-java"><span class="token keyword">package</span> com<span class="token punctuation">.</span>wcy<span class="token punctuation">.</span>eblog<span class="token punctuation">.</span>util<span class="token punctuation">;</span>

<span class="token keyword">import</span> lombok<span class="token punctuation">.</span>Data<span class="token punctuation">;</span>
<span class="token keyword">import</span> org<span class="token punctuation">.</span>hibernate<span class="token punctuation">.</span>validator<span class="token punctuation">.</span>HibernateValidator<span class="token punctuation">;</span>

<span class="token keyword">import</span> javax<span class="token punctuation">.</span>validation<span class="token punctuation">.</span>ConstraintViolation<span class="token punctuation">;</span>
<span class="token keyword">import</span> javax<span class="token punctuation">.</span>validation<span class="token punctuation">.</span>Validation<span class="token punctuation">;</span>
<span class="token keyword">import</span> javax<span class="token punctuation">.</span>validation<span class="token punctuation">.</span>Validator<span class="token punctuation">;</span>
<span class="token keyword">import</span> java<span class="token punctuation">.</span>util<span class="token punctuation">.</span>ArrayList<span class="token punctuation">;</span>
<span class="token keyword">import</span> java<span class="token punctuation">.</span>util<span class="token punctuation">.</span>List<span class="token punctuation">;</span>
<span class="token keyword">import</span> java<span class="token punctuation">.</span>util<span class="token punctuation">.</span>Set<span class="token punctuation">;</span>

<span class="token comment">/**
 * Hibernate Validator校验工具类
 */</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ValidationUtil</span> <span class="token punctuation">{</span>

    <span class="token comment">/**
     * 开启快速结束模式 failFast (true)
     */</span>
    <span class="token keyword">private</span> <span class="token keyword">static</span> Validator validator <span class="token operator">=</span> Validation<span class="token punctuation">.</span><span class="token function">byProvider</span><span class="token punctuation">(</span>HibernateValidator<span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">configure</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">failFast</span><span class="token punctuation">(</span><span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">buildValidatorFactory</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getValidator</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">/**
     * 校验对象
     *
     * @param t bean
     * @param groups 校验组
     * @return ValidResult
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token generics function"><span class="token punctuation"><</span>T<span class="token punctuation">></span></span> ValidResult <span class="token function">validateBean</span><span class="token punctuation">(</span>T t<span class="token punctuation">,</span>Class<span class="token operator"><</span><span class="token operator">?</span><span class="token operator">></span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>groups<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        ValidResult result <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ValidationUtil</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token keyword">new</span> <span class="token class-name">ValidResult</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        Set<span class="token operator"><</span>ConstraintViolation<span class="token generics function"><span class="token punctuation"><</span>T<span class="token punctuation">></span></span><span class="token operator">></span> violationSet <span class="token operator">=</span> validator<span class="token punctuation">.</span><span class="token function">validate</span><span class="token punctuation">(</span>t<span class="token punctuation">,</span>groups<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">boolean</span> hasError <span class="token operator">=</span> violationSet <span class="token operator">!=</span> null <span class="token operator">&&</span> violationSet<span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">></span> <span class="token number">0</span><span class="token punctuation">;</span>
        result<span class="token punctuation">.</span><span class="token function">setHasErrors</span><span class="token punctuation">(</span>hasError<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>hasError<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">for</span> <span class="token punctuation">(</span>ConstraintViolation<span class="token generics function"><span class="token punctuation"><</span>T<span class="token punctuation">></span></span> violation <span class="token operator">:</span> violationSet<span class="token punctuation">)</span> <span class="token punctuation">{</span>
                result<span class="token punctuation">.</span><span class="token function">addError</span><span class="token punctuation">(</span>violation<span class="token punctuation">.</span><span class="token function">getPropertyPath</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> violation<span class="token punctuation">.</span><span class="token function">getMessage</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">return</span> result<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token comment">/**
     * 校验bean的某一个属性
     *
     * @param obj          bean
     * @param propertyName 属性名称
     * @return ValidResult
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token generics function"><span class="token punctuation"><</span>T<span class="token punctuation">></span></span> ValidResult <span class="token function">validateProperty</span><span class="token punctuation">(</span>T obj<span class="token punctuation">,</span> String propertyName<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        ValidResult result <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ValidationUtil</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token keyword">new</span> <span class="token class-name">ValidResult</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        Set<span class="token operator"><</span>ConstraintViolation<span class="token generics function"><span class="token punctuation"><</span>T<span class="token punctuation">></span></span><span class="token operator">></span> violationSet <span class="token operator">=</span> validator<span class="token punctuation">.</span><span class="token function">validateProperty</span><span class="token punctuation">(</span>obj<span class="token punctuation">,</span> propertyName<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">boolean</span> hasError <span class="token operator">=</span> violationSet <span class="token operator">!=</span> null <span class="token operator">&&</span> violationSet<span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">></span> <span class="token number">0</span><span class="token punctuation">;</span>
        result<span class="token punctuation">.</span><span class="token function">setHasErrors</span><span class="token punctuation">(</span>hasError<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>hasError<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">for</span> <span class="token punctuation">(</span>ConstraintViolation<span class="token generics function"><span class="token punctuation"><</span>T<span class="token punctuation">></span></span> violation <span class="token operator">:</span> violationSet<span class="token punctuation">)</span> <span class="token punctuation">{</span>
                result<span class="token punctuation">.</span><span class="token function">addError</span><span class="token punctuation">(</span>propertyName<span class="token punctuation">,</span> violation<span class="token punctuation">.</span><span class="token function">getMessage</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">return</span> result<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token comment">/**
     * 校验结果类
     */</span>
    <span class="token annotation punctuation">@Data</span>
    <span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ValidResult</span> <span class="token punctuation">{</span>

        <span class="token comment">/**
         * 是否有错误
         */</span>
        <span class="token keyword">private</span> <span class="token keyword">boolean</span> hasErrors<span class="token punctuation">;</span>

        <span class="token comment">/**
         * 错误信息
         */</span>
        <span class="token keyword">private</span> List<span class="token generics function"><span class="token punctuation"><</span>ErrorMessage<span class="token punctuation">></span></span> errors<span class="token punctuation">;</span>

        <span class="token keyword">public</span> <span class="token function">ValidResult</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">this</span><span class="token punctuation">.</span>errors <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token operator"><</span><span class="token operator">></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">public</span> <span class="token keyword">boolean</span> <span class="token function">hasErrors</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">return</span> hasErrors<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">setHasErrors</span><span class="token punctuation">(</span><span class="token keyword">boolean</span> hasErrors<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">this</span><span class="token punctuation">.</span>hasErrors <span class="token operator">=</span> hasErrors<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        <span class="token comment">/**
         * 获取所有验证信息
         * @return 集合形式
         */</span>
        <span class="token keyword">public</span> List<span class="token generics function"><span class="token punctuation"><</span>ErrorMessage<span class="token punctuation">></span></span> <span class="token function">getAllErrors</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">return</span> errors<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token comment">/**
         * 获取所有验证信息
         * @return 字符串形式
         */</span>
        <span class="token keyword">public</span> String <span class="token function">getErrors</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
            StringBuilder sb <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">StringBuilder</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">for</span> <span class="token punctuation">(</span>ErrorMessage error <span class="token operator">:</span> errors<span class="token punctuation">)</span> <span class="token punctuation">{</span>
                sb<span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span>error<span class="token punctuation">.</span><span class="token function">getPropertyPath</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token string">":"</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span>error<span class="token punctuation">.</span><span class="token function">getMessage</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token string">" "</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            <span class="token keyword">return</span> sb<span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">addError</span><span class="token punctuation">(</span>String propertyName<span class="token punctuation">,</span> String message<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">this</span><span class="token punctuation">.</span>errors<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">ErrorMessage</span><span class="token punctuation">(</span>propertyName<span class="token punctuation">,</span> message<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

    <span class="token annotation punctuation">@Data</span>
    <span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ErrorMessage</span> <span class="token punctuation">{</span>

        <span class="token keyword">private</span> String propertyPath<span class="token punctuation">;</span>

        <span class="token keyword">private</span> String message<span class="token punctuation">;</span>

        <span class="token keyword">public</span> <span class="token function">ErrorMessage</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token punctuation">}</span>

        <span class="token keyword">public</span> <span class="token function">ErrorMessage</span><span class="token punctuation">(</span>String propertyPath<span class="token punctuation">,</span> String message<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">this</span><span class="token punctuation">.</span>propertyPath <span class="token operator">=</span> propertyPath<span class="token punctuation">;</span>
            <span class="token keyword">this</span><span class="token punctuation">.</span>message <span class="token operator">=</span> message<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre> 
  <p>4.controller层使用</p> 
  <pre><code class="prism language-java">    <span class="token annotation punctuation">@PostMapping</span><span class="token punctuation">(</span><span class="token string">"/regist"</span><span class="token punctuation">)</span>
    <span class="token annotation punctuation">@ResponseBody</span>
    <span class="token keyword">public</span> Result <span class="token function">doregist</span><span class="token punctuation">(</span> MUser user<span class="token punctuation">,</span>String repass<span class="token punctuation">,</span>String vercode<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token comment">//验证表单信息是否符合</span>
        ValidationUtil<span class="token punctuation">.</span>ValidResult validResult <span class="token operator">=</span> ValidationUtil<span class="token punctuation">.</span><span class="token function">validateBean</span><span class="token punctuation">(</span>user<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>validResult<span class="token punctuation">.</span><span class="token function">hasErrors</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token keyword">return</span> Result<span class="token punctuation">.</span><span class="token function">fail</span><span class="token punctuation">(</span>validResult<span class="token punctuation">.</span><span class="token function">getErrors</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> 
  <h2>十四.使用MP的插入方法小心主键会使用它自己的生成策略</h2> 
  <p>1.配置文件</p> 
  <pre><code class="prism language-yaml"><span class="token key atrule">mybatis-plus</span><span class="token punctuation">:</span>
  <span class="token key atrule">mapper-locations</span><span class="token punctuation">:</span> classpath*<span class="token punctuation">:</span>/mapper/*<span class="token important">*Mapper</span>.xml
  <span class="token key atrule">type-aliases-package</span><span class="token punctuation">:</span> com.wcy.eblog.*
  <span class="token key atrule">global-config</span><span class="token punctuation">:</span>
    <span class="token key atrule">db-config</span><span class="token punctuation">:</span>
      <span class="token key atrule">id-type</span><span class="token punctuation">:</span> auto <span class="token comment">#使用mybatis-plus的插入时主键使用数据库自增</span>
</code></pre> 
  <p>2.实体类ID上加上@TableId(value = “id”,type = IdType.AUTO)使用数据库的自增</p> 
  <pre><code class="prism language-java">    <span class="token annotation punctuation">@TableId</span><span class="token punctuation">(</span>value <span class="token operator">=</span> <span class="token string">"id"</span><span class="token punctuation">,</span>type <span class="token operator">=</span> IdType<span class="token punctuation">.</span>AUTO<span class="token punctuation">)</span>
    <span class="token keyword">private</span> Long id<span class="token punctuation">;</span>
</code></pre> 
  <h2>十五.不小心用了MP的主键生成策略,如何把主键序列重写修改</h2> 
  <p>1,删除原有主键:</p> 
  <pre><code class="prism language-yml">ALTER TABLE `table_name` DROP `id`;
</code></pre> 
  <p>2,添加新主键字段:</p> 
  <pre><code class="prism language-java">ALTER TABLE `table_name` ADD `id` <span class="token function">INT</span><span class="token punctuation">(</span> <span class="token number">11</span> <span class="token punctuation">)</span> NOT NULL FIRST<span class="token punctuation">;</span>
</code></pre> 
  <p>3,设置新主键:</p> 
  <pre><code class="prism language-java">ALTER TABLE `table_name` MODIFY COLUMN `id` <span class="token function">INT</span><span class="token punctuation">(</span> <span class="token number">11</span> <span class="token punctuation">)</span> NOT NULL AUTO_INCREMENT<span class="token punctuation">,</span>ADD PRIMARY <span class="token function">KEY</span><span class="token punctuation">(</span>id<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> 
  <h2>十六.springboot中使用shiro</h2> 
  <p>shirod重要的三部分</p> 
  <ul> 
   <li>1.获取subject(用户)</li> 
   <li>2.shiro有自己的session,无http中的session无关</li> 
   <li>3.判断是否认证</li> 
   <li>4.获取token</li> 
   <li>5.是否有某个角色</li> 
   <li>6.是否有某个权限</li> 
   <li>7.注销<br> <a href="http://img.e-com-net.com/image/info8/f3f0cae7972c48e8b2978b002b1017c3.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/f3f0cae7972c48e8b2978b002b1017c3.jpg" alt="SpringBoot+Mybatis Plus开发博客系统_第4张图片" width="494" height="167" style="border:1px solid black;"></a><br> 1.导入依赖</li> 
  </ul> 
  <pre><code class="prism language-java">        <span class="token operator"><</span><span class="token operator">!</span><span class="token operator">--</span>shiro权限框架<span class="token operator">--</span><span class="token operator">></span>
        <span class="token generics function"><span class="token punctuation"><</span>dependency<span class="token punctuation">></span></span>
            <span class="token generics function"><span class="token punctuation"><</span>groupId<span class="token punctuation">></span></span>org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>shiro<span class="token operator"><</span><span class="token operator">/</span>groupId<span class="token operator">></span>
            <span class="token generics function"><span class="token punctuation"><</span>artifactId<span class="token punctuation">></span></span>shiro<span class="token operator">-</span>spring<span class="token operator"><</span><span class="token operator">/</span>artifactId<span class="token operator">></span>
            <span class="token generics function"><span class="token punctuation"><</span>version<span class="token punctuation">></span></span><span class="token number">1.4</span><span class="token number">.0</span><span class="token operator"><</span><span class="token operator">/</span>version<span class="token operator">></span>
        <span class="token operator"><</span><span class="token operator">/</span>dependency<span class="token operator">></span>
        <span class="token operator"><</span><span class="token operator">!</span><span class="token operator">--</span>thymeleaf中使用shiro的标签<span class="token operator">--</span><span class="token operator">></span>
        <span class="token generics function"><span class="token punctuation"><</span>dependency<span class="token punctuation">></span></span>
            <span class="token generics function"><span class="token punctuation"><</span>groupId<span class="token punctuation">></span></span>com<span class="token punctuation">.</span>github<span class="token punctuation">.</span>theborakompanioni<span class="token operator"><</span><span class="token operator">/</span>groupId<span class="token operator">></span>
            <span class="token generics function"><span class="token punctuation"><</span>artifactId<span class="token punctuation">></span></span>thymeleaf<span class="token operator">-</span>extras<span class="token operator">-</span>shiro<span class="token operator"><</span><span class="token operator">/</span>artifactId<span class="token operator">></span>
            <span class="token generics function"><span class="token punctuation"><</span>version<span class="token punctuation">></span></span><span class="token number">2.0</span><span class="token number">.0</span><span class="token operator"><</span><span class="token operator">/</span>version<span class="token operator">></span>
        <span class="token operator"><</span><span class="token operator">/</span>dependency<span class="token operator">></span>
</code></pre> 
  <p>2.自定义XXXRealm 继承AuthorizingRealm用于授权和认证<br> <strong>授权的设置:</strong><br> <a href="http://img.e-com-net.com/image/info8/a0ff6f4665be4841939517620f76021e.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/a0ff6f4665be4841939517620f76021e.jpg" alt="SpringBoot+Mybatis Plus开发博客系统_第5张图片" width="548" height="311" style="border:1px solid black;"></a></p> 
  <pre><code class="prism language-java"><span class="token annotation punctuation">@Component</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">AccountRealm</span> <span class="token keyword">extends</span> <span class="token class-name">AuthorizingRealm</span> <span class="token punctuation">{</span>
    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> MUserService mUserService<span class="token punctuation">;</span>
    <span class="token comment">//模拟授权 实际应该查库</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">protected</span> AuthorizationInfo <span class="token function">doGetAuthorizationInfo</span><span class="token punctuation">(</span>PrincipalCollection principalCollection<span class="token punctuation">)</span> <span class="token punctuation">{</span>
                AccountProfile profile<span class="token operator">=</span> <span class="token punctuation">(</span>AccountProfile<span class="token punctuation">)</span> principalCollection<span class="token punctuation">.</span><span class="token function">getPrimaryPrincipal</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//模拟给用户9赋予Admin权限</span>
        <span class="token keyword">if</span><span class="token punctuation">(</span>profile<span class="token punctuation">.</span><span class="token function">getId</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">==</span> <span class="token number">9</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
            SimpleAuthorizationInfo info<span class="token operator">=</span><span class="token keyword">new</span> <span class="token class-name">SimpleAuthorizationInfo</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            info<span class="token punctuation">.</span><span class="token function">addRole</span><span class="token punctuation">(</span><span class="token string">"admin"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">return</span> info<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">return</span> null<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token comment">/**
     * 用于用户登录认证
     */</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">protected</span> AuthenticationInfo <span class="token function">doGetAuthenticationInfo</span><span class="token punctuation">(</span>AuthenticationToken authenticationToken<span class="token punctuation">)</span> <span class="token keyword">throws</span> AuthenticationException <span class="token punctuation">{</span>
        UsernamePasswordToken token<span class="token operator">=</span> <span class="token punctuation">(</span>UsernamePasswordToken<span class="token punctuation">)</span> authenticationToken<span class="token punctuation">;</span>
        String email <span class="token operator">=</span> token<span class="token punctuation">.</span><span class="token function">getUsername</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//查询数据库进行操作</span>
        AccountProfile profile<span class="token operator">=</span>mUserService<span class="token punctuation">.</span><span class="token function">login</span><span class="token punctuation">(</span>token<span class="token punctuation">.</span><span class="token function">getUsername</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>String<span class="token punctuation">.</span><span class="token function">valueOf</span><span class="token punctuation">(</span>token<span class="token punctuation">.</span><span class="token function">getPassword</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        SimpleAuthenticationInfo info <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SimpleAuthenticationInfo</span><span class="token punctuation">(</span>profile<span class="token punctuation">,</span> token<span class="token punctuation">.</span><span class="token function">getCredentials</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">getName</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> info<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> 
  <p>3.登录的controller</p> 
  <pre><code class="prism language-java">    <span class="token annotation punctuation">@PostMapping</span><span class="token punctuation">(</span><span class="token string">"login"</span><span class="token punctuation">)</span>
    <span class="token annotation punctuation">@ResponseBody</span>
    <span class="token keyword">public</span> Result <span class="token function">doLogin</span><span class="token punctuation">(</span>String email<span class="token punctuation">,</span>String password<span class="token punctuation">,</span>String vercode<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">if</span><span class="token punctuation">(</span>StringUtils<span class="token punctuation">.</span><span class="token function">isEmpty</span><span class="token punctuation">(</span>email<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token keyword">return</span> Result<span class="token punctuation">.</span><span class="token function">fail</span><span class="token punctuation">(</span><span class="token string">"请填写邮箱"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">if</span><span class="token punctuation">(</span>StringUtils<span class="token punctuation">.</span><span class="token function">isEmpty</span><span class="token punctuation">(</span>password<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token keyword">return</span> Result<span class="token punctuation">.</span><span class="token function">fail</span><span class="token punctuation">(</span><span class="token string">"请填写密码"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">if</span><span class="token punctuation">(</span>StringUtils<span class="token punctuation">.</span><span class="token function">isEmpty</span><span class="token punctuation">(</span>vercode<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token keyword">return</span> Result<span class="token punctuation">.</span><span class="token function">fail</span><span class="token punctuation">(</span><span class="token string">"验证码不能为空"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        String kapchat <span class="token operator">=</span> <span class="token punctuation">(</span>String<span class="token punctuation">)</span>req<span class="token punctuation">.</span><span class="token function">getSession</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getAttribute</span><span class="token punctuation">(</span>Constants<span class="token punctuation">.</span>KAPTCHA_SESSION_KEY<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token operator">!</span>vercode<span class="token punctuation">.</span><span class="token function">toUpperCase</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span>kapchat<span class="token punctuation">.</span><span class="token function">toUpperCase</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token keyword">return</span> Result<span class="token punctuation">.</span><span class="token function">fail</span><span class="token punctuation">(</span><span class="token string">"验证码错误"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        UsernamePasswordToken token<span class="token operator">=</span><span class="token keyword">new</span> <span class="token class-name">UsernamePasswordToken</span><span class="token punctuation">(</span>email<span class="token punctuation">,</span> DigestUtil<span class="token punctuation">.</span><span class="token function">md5Hex</span><span class="token punctuation">(</span>password<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">try</span><span class="token punctuation">{</span>
            <span class="token comment">//使用shiro进行登录</span>
            SecurityUtils<span class="token punctuation">.</span><span class="token function">getSubject</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">login</span><span class="token punctuation">(</span>token<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">AuthenticationException</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token comment">//进行登录会产生下面的异常</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>e <span class="token keyword">instanceof</span> <span class="token class-name">UnknownAccountException</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token keyword">return</span> Result<span class="token punctuation">.</span><span class="token function">fail</span><span class="token punctuation">(</span><span class="token string">"用户不存在"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>e <span class="token keyword">instanceof</span> <span class="token class-name">LockedAccountException</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token keyword">return</span> Result<span class="token punctuation">.</span><span class="token function">fail</span><span class="token punctuation">(</span><span class="token string">"用户被禁用"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>e <span class="token keyword">instanceof</span> <span class="token class-name">IncorrectCredentialsException</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token keyword">return</span> Result<span class="token punctuation">.</span><span class="token function">fail</span><span class="token punctuation">(</span><span class="token string">"密码错误"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
                <span class="token keyword">return</span> Result<span class="token punctuation">.</span><span class="token function">fail</span><span class="token punctuation">(</span><span class="token string">"用户认证失败"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">return</span> Result<span class="token punctuation">.</span><span class="token function">success</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">action</span><span class="token punctuation">(</span><span class="token string">"/"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</code></pre> 
  <p>4.shiro的配置类</p> 
  <pre><code class="prism language-java"><span class="token comment">/**
 * 类似于拦截器
 */</span>
<span class="token annotation punctuation">@Slf4j</span>
<span class="token annotation punctuation">@Configuration</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ShiroConfig</span> <span class="token punctuation">{</span>

    <span class="token annotation punctuation">@Bean</span>
    <span class="token keyword">public</span> SecurityManager <span class="token function">securityManager</span><span class="token punctuation">(</span>AccountRealm accountRealm<span class="token punctuation">)</span><span class="token punctuation">{</span>

        DefaultWebSecurityManager securityManager <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">DefaultWebSecurityManager</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        securityManager<span class="token punctuation">.</span><span class="token function">setRealm</span><span class="token punctuation">(</span>accountRealm<span class="token punctuation">)</span><span class="token punctuation">;</span>

        log<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string">"------------------>securityManager注入成功"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">return</span> securityManager<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token annotation punctuation">@Bean</span>
    <span class="token keyword">public</span> ShiroFilterFactoryBean <span class="token function">shiroFilterFactoryBean</span><span class="token punctuation">(</span>SecurityManager securityManager<span class="token punctuation">)</span> <span class="token punctuation">{</span>

        ShiroFilterFactoryBean filterFactoryBean <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ShiroFilterFactoryBean</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        filterFactoryBean<span class="token punctuation">.</span><span class="token function">setSecurityManager</span><span class="token punctuation">(</span>securityManager<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">// 配置登录的url和登录成功的url</span>
        filterFactoryBean<span class="token punctuation">.</span><span class="token function">setLoginUrl</span><span class="token punctuation">(</span><span class="token string">"/login"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        filterFactoryBean<span class="token punctuation">.</span><span class="token function">setSuccessUrl</span><span class="token punctuation">(</span><span class="token string">"/user/center"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">// 配置未授权跳转页面</span>
        filterFactoryBean<span class="token punctuation">.</span><span class="token function">setUnauthorizedUrl</span><span class="token punctuation">(</span><span class="token string">"/error/403"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        Map<span class="token generics function"><span class="token punctuation"><</span>String<span class="token punctuation">,</span> String<span class="token punctuation">></span></span> hashMap <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">LinkedHashMap</span><span class="token operator"><</span><span class="token operator">></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">//        hashMap.put("/res/**", "anon");</span>
<span class="token comment">//</span>
<span class="token comment">//        hashMap.put("/user/home", "auth");</span>
<span class="token comment">//        hashMap.put("/user/set", "auth");</span>
<span class="token comment">//        hashMap.put("/user/upload", "auth");</span>
<span class="token comment">//        hashMap.put("/user/index", "auth");</span>
<span class="token comment">//        hashMap.put("/user/public", "auth");</span>
<span class="token comment">//        hashMap.put("/user/collection", "auth");</span>
<span class="token comment">//        hashMap.put("/user/mess", "auth");</span>
<span class="token comment">//        hashMap.put("/msg/remove/", "auth");</span>
<span class="token comment">//        hashMap.put("/message/nums/", "auth");</span>
<span class="token comment">//</span>
<span class="token comment">//        hashMap.put("/collection/remove/", "auth");</span>
<span class="token comment">//        hashMap.put("/collection/find/", "auth");</span>
<span class="token comment">//        hashMap.put("/collection/add/", "auth");</span>
<span class="token comment">//</span>
<span class="token comment">//        hashMap.put("/post/edit", "auth");</span>
<span class="token comment">//        hashMap.put("/post/submit", "auth");</span>
<span class="token comment">//        hashMap.put("/post/delete", "auth");</span>
<span class="token comment">//        hashMap.put("/post/reply/", "auth");</span>
<span class="token comment">//</span>
<span class="token comment">//        hashMap.put("/websocket", "anon");</span>
        hashMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"/login"</span><span class="token punctuation">,</span> <span class="token string">"anon"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        filterFactoryBean<span class="token punctuation">.</span><span class="token function">setFilterChainDefinitionMap</span><span class="token punctuation">(</span>hashMap<span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">return</span> filterFactoryBean<span class="token punctuation">;</span>

    <span class="token punctuation">}</span>

    <span class="token operator">/</span><span class="token operator">*</span><span class="token operator">*</span>
     <span class="token operator">*</span> 用于thymeleaf模板与shiro的标签
     <span class="token operator">*</span> @<span class="token keyword">return</span>
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token annotation punctuation">@Bean</span>
    <span class="token keyword">public</span> ShiroDialect <span class="token function">shiroDialect</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">ShiroDialect</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> 
  <p>5.thymeleaf使用标签:<br> 1.引入:</p> 
  <pre><code class="prism language-yaml"><html xmlns<span class="token punctuation">:</span>shiro="http<span class="token punctuation">:</span>//www.pollix.at/thymeleaf/shiro"<span class="token punctuation">></span>
</code></pre> 
  <p>2.标签:</p> 
  <pre><code class="prism language-yaml">guest标签
  <shiro<span class="token punctuation">:</span>guest<span class="token punctuation">></span>
  </shiro<span class="token punctuation">:</span>guest<span class="token punctuation">></span>
  用户没有身份验证时显示相应信息,即游客访问信息。

user标签
  <shiro<span class="token punctuation">:</span>user<span class="token punctuation">></span>  
  </shiro<span class="token punctuation">:</span>user<span class="token punctuation">></span>
  用户已经身份验证/记住我登录后显示相应的信息。

authenticated标签
  <shiro<span class="token punctuation">:</span>authenticated<span class="token punctuation">></span>  
  </shiro<span class="token punctuation">:</span>authenticated<span class="token punctuation">></span>
  用户已经身份验证通过,即Subject.login登录成功,不是记住我登录的。

notAuthenticated标签
  <shiro<span class="token punctuation">:</span>notAuthenticated<span class="token punctuation">></span>
  
  </shiro<span class="token punctuation">:</span>notAuthenticated<span class="token punctuation">></span>
  用户已经身份验证通过,即没有调用Subject.login进行登录,包括记住我自动登录的也属于未进行身份验证。

principal标签
  <shiro<span class="token punctuation">:</span> principal/<span class="token punctuation">></span>
  
  <shiro<span class="token punctuation">:</span>principal property="username"/<span class="token punctuation">></span>
  相当于((User)Subject.getPrincipals()).getUsername()。

lacksPermission标签
  <shiro<span class="token punctuation">:</span>lacksPermission name="org<span class="token punctuation">:</span>create"<span class="token punctuation">></span>
 
  </shiro<span class="token punctuation">:</span>lacksPermission<span class="token punctuation">></span>
  如果当前Subject没有权限将显示body体内容。

hasRole标签
  <shiro<span class="token punctuation">:</span>hasRole name="admin"<span class="token punctuation">></span>  
  </shiro<span class="token punctuation">:</span>hasRole<span class="token punctuation">></span>
  如果当前Subject有角色将显示body体内容。

hasAnyRoles标签
  <shiro<span class="token punctuation">:</span>hasAnyRoles name="admin<span class="token punctuation">,</span>user"<span class="token punctuation">></span>
   
  </shiro<span class="token punctuation">:</span>hasAnyRoles<span class="token punctuation">></span>
  如果当前Subject有任意一个角色(或的关系)将显示body体内容。

lacksRole标签
  <shiro<span class="token punctuation">:</span>lacksRole name="abc"<span class="token punctuation">></span>  
  </shiro<span class="token punctuation">:</span>lacksRole<span class="token punctuation">></span>
  如果当前Subject没有角色将显示body体内容。

hasPermission标签
  <shiro<span class="token punctuation">:</span>hasPermission name="user<span class="token punctuation">:</span>create"<span class="token punctuation">></span>  
  </shiro<span class="token punctuation">:</span>hasPermission<span class="token punctuation">></span>
  如果当前Subject有权限将显示body体内容

</code></pre> 
  <h2>十七.thymeleaf中标签的属性上如何shiro标签</h2> 
  <p>问题:<br> <strong><shiro:principal property=“avatar”/>只能只能作用于标签的内容上,不能作用于属性上。</strong><br> 解决:<br> 1.我们可以随便设置一个div标签,然后把值给div<br> 2.再通过js获取div的值,然后赋值src或href等等标签属性上面</p> 
  <pre><code class="prism language-yaml">      <div style="display<span class="token punctuation">:</span> none" id="div_avatar"<span class="token punctuation">></span><shiro<span class="token punctuation">:</span>principal property="avatar"/<span class="token punctuation">></span></div<span class="token punctuation">></span>
      <img src="" id="img_avatar"/<span class="token punctuation">></span>
      <script<span class="token punctuation">></span>
          $(function () <span class="token punctuation">{</span>
             var avatar=$('<span class="token comment">#div_avatar').html();</span>
             $('<span class="token comment">#img_avatar').attr("src",avatar)</span>
             console.log(avatar)
          <span class="token punctuation">}</span>)
     </script<span class="token punctuation">></span>
</code></pre> 
  <h2>十八.thymeleaf中判断list是否为空</h2> 
  <p><strong>不为空:</strong></p> 
  <pre><code class="prism language-yaml">th<span class="token punctuation">:</span>if="$<span class="token punctuation">{</span>not <span class="token comment">#lists.isEmpty(listData)}"</span>
</code></pre> 
  <p><strong>为空:</strong></p> 
  <pre><code class="prism language-yaml">th<span class="token punctuation">:</span>if="$<span class="token punctuation">{</span><span class="token comment">#lists.isEmpty(listData)}"</span>
</code></pre> 
  <h2>十九.批量删除文件(忽略后缀)</h2> 
  <pre><code class="prism language-java">    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">deleteFileSuff</span><span class="token punctuation">(</span>File file<span class="token punctuation">,</span>String fileName<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token comment">//批量删除忽略后缀的文件</span>
        String<span class="token punctuation">[</span><span class="token punctuation">]</span> list <span class="token operator">=</span> file<span class="token punctuation">.</span><span class="token function">list</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">for</span><span class="token punctuation">(</span>String temp<span class="token operator">:</span>list<span class="token punctuation">)</span><span class="token punctuation">{</span>
            String name<span class="token operator">=</span>temp<span class="token punctuation">.</span><span class="token function">substring</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span>temp<span class="token punctuation">.</span><span class="token function">indexOf</span><span class="token punctuation">(</span><span class="token string">"."</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            String nameSuffix<span class="token operator">=</span>temp<span class="token punctuation">.</span><span class="token function">substring</span><span class="token punctuation">(</span>temp<span class="token punctuation">.</span><span class="token function">indexOf</span><span class="token punctuation">(</span><span class="token string">"."</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">if</span><span class="token punctuation">(</span>name<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span>fileName<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                File file1<span class="token operator">=</span><span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span>file<span class="token punctuation">.</span><span class="token function">getAbsolutePath</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">+</span><span class="token string">"/"</span><span class="token operator">+</span>fileName<span class="token operator">+</span>nameSuffix<span class="token punctuation">)</span><span class="token punctuation">;</span>
                file1<span class="token punctuation">.</span><span class="token function">delete</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
</code></pre> 
  <h2>二十.springboot上传图片</h2> 
  <p><strong>1.yml配置:${user.dir}是获取容器src路径的绝对路径</strong></p> 
  <pre><code class="prism language-yaml"><span class="token comment">#文件下载路径  ${user.dir}可以获取容器即src路径的绝对路径   记得最后的/</span>
<span class="token key atrule">file</span><span class="token punctuation">:</span>
  <span class="token key atrule">upload</span><span class="token punctuation">:</span>
    <span class="token key atrule">dir</span><span class="token punctuation">:</span> $<span class="token punctuation">{</span>user.dir<span class="token punctuation">}</span>/upload/
</code></pre> 
  <p><strong>2.配置类;一但发起/upload请求就会映射到${user.dir}/upload/路径下面,我们只需要再返回图片的路径就可以了</strong></p> 
  <pre><code class="prism language-java"><span class="token annotation punctuation">@Configuration</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">MyMvcConfig</span> <span class="token keyword">implements</span> <span class="token class-name">WebMvcConfigurer</span><span class="token punctuation">{</span>
    <span class="token annotation punctuation">@Value</span><span class="token punctuation">(</span><span class="token string">"${file.upload.dir}"</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> String uploadPath<span class="token punctuation">;</span><span class="token comment">//获取配置文件的路径 这样可以随时配置图片上传路径</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">addResourceHandlers</span><span class="token punctuation">(</span>ResourceHandlerRegistry registry<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">//资源映射  用于图片显示</span>
        registry<span class="token punctuation">.</span><span class="token function">addResourceHandler</span><span class="token punctuation">(</span><span class="token string">"/upload/**"</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">addResourceLocations</span><span class="token punctuation">(</span><span class="token string">"file:"</span><span class="token operator">+</span>uploadPath<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre> 
  <p>3.比如返回路径为:/upload/user/avatar"+newName 这样前端展示这个url就可以了。</p> 
  <pre><code class="prism language-java"><span class="token keyword">return</span> Result<span class="token punctuation">.</span><span class="token function">success</span><span class="token punctuation">(</span><span class="token string">"/upload/user/avatar"</span><span class="token operator">+</span>newName<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> 
  <h2>二十二.layui流和layui的模板引擎</h2> 
  <p>一个类似于流的形式的页面<br> <a href="http://img.e-com-net.com/image/info8/dac002557030485c8a39dc84246188d6.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/dac002557030485c8a39dc84246188d6.jpg" alt="SpringBoot+Mybatis Plus开发博客系统_第6张图片" width="650" height="130" style="border:1px solid black;"></a><br> <strong>1.首先使用layui的模板引擎定义一个显示的item</strong><br> 其中使用了layui的时间工具类 这里面没法使用thymeleaf的语法</p> 
  <pre><code class="prism language-yaml"><ul class="mine<span class="token punctuation">-</span>view jie<span class="token punctuation">-</span>row" id="fabu"<span class="token punctuation">></span>

            <script id="lpl_fabu" type="text/html" th<span class="token punctuation">:</span>inline="javascript"<span class="token punctuation">></span>
              <li<span class="token punctuation">></span>
                <a class="jie<span class="token punctuation">-</span>title" th<span class="token punctuation">:</span>href="@<span class="token punctuation">{</span>/post/post/<span class="token punctuation">{</span><span class="token punctuation">{</span>d.id<span class="token punctuation">}</span><span class="token punctuation">}</span><span class="token punctuation">}</span>" target="_blank"<span class="token punctuation">></span><span class="token punctuation">{</span><span class="token punctuation">{</span>d.title<span class="token punctuation">}</span><span class="token punctuation">}</span></a<span class="token punctuation">></span>
                <i<span class="token punctuation">></span><span class="token punctuation">{</span><span class="token punctuation">{</span>layui.util.toDateString(d.created<span class="token punctuation">,</span> 'yyyy<span class="token punctuation">-</span>MM<span class="token punctuation">-</span>dd HH<span class="token punctuation">:</span>mm<span class="token punctuation">:</span>ss')<span class="token punctuation">}</span><span class="token punctuation">}</span></i<span class="token punctuation">></span>
                <a class="mine<span class="token punctuation">-</span>edit" href="/jie/edit/8116"<span class="token punctuation">></span>编辑</a<span class="token punctuation">></span>
                <em<span class="token punctuation">></span><span class="token punctuation">{</span><span class="token punctuation">{</span>d.viewCount<span class="token punctuation">}</span><span class="token punctuation">}</span>阅/<span class="token punctuation">{</span><span class="token punctuation">{</span>d.commentCount<span class="token punctuation">}</span><span class="token punctuation">}</span>答</em<span class="token punctuation">></span>
              </li<span class="token punctuation">></span>
            </script<span class="token punctuation">></span>

          </ul<span class="token punctuation">></span>
</code></pre> 
  <p><strong>2.js的代码</strong></p> 
  <pre><code class="prism language-yaml">    $(function () <span class="token punctuation">{</span>
        layui.use(<span class="token punctuation">[</span><span class="token string">'flow'</span><span class="token punctuation">,</span><span class="token string">'laytpl'</span><span class="token punctuation">,</span><span class="token string">'util'</span><span class="token punctuation">]</span><span class="token punctuation">,</span> function()<span class="token punctuation">{</span>
            var $ = layui.jquery; //不用额外加载jQuery,flow模块本身是有依赖jQuery的,直接用即可。
            var flow = layui.flow;
            var laytpl = layui.laytpl;
            var util = layui.util;
            //流加载的容器
            flow.load(<span class="token punctuation">{</span>
                <span class="token key atrule">elem</span><span class="token punctuation">:</span> <span class="token string">'#fabu'</span><span class="token punctuation">,</span> //指定列表容器 放在哪个容器里面
                isAuto<span class="token punctuation">:</span>false  //不自动加载
                <span class="token punctuation">,</span><span class="token key atrule">done</span><span class="token punctuation">:</span> function(page<span class="token punctuation">,</span> next)<span class="token punctuation">{</span> //到达临界点(默认滚动触发),触发下一页
                    var lis = <span class="token punctuation">[</span><span class="token punctuation">]</span>;

                    //以jQuery的Ajax请求为例,请求下一页数据(注意:page是从2开始返回)
                    $.get('/user/publish<span class="token punctuation">?</span>page='+page<span class="token punctuation">,</span> function(res)<span class="token punctuation">{</span>
                        //假设你的列表返回在data集合中 通过layui的循环获取数据
                        layui.each(res.data.records<span class="token punctuation">,</span> function(index<span class="token punctuation">,</span> item)<span class="token punctuation">{</span>
                            //通过layui的自定义数据模板 lpl_fabu.innerHTML是模板引擎的ID并显示html
                            laytpl(lpl_fabu.innerHTML).render(item<span class="token punctuation">,</span> function(html)<span class="token punctuation">{</span>
                                //放进数组中
                                lis.push(html);
                            <span class="token punctuation">}</span>);
                        <span class="token punctuation">}</span>);

                        //执行下一页渲染,第二参数为:满足“加载更多”的条件,即后面仍有分页
                        //pages为Ajax返回的总页数,只有当前页小于总页数的情况下,才会继续出现加载更多
                        next(lis.join('')<span class="token punctuation">,</span> page < res.data.pages);
                    <span class="token punctuation">}</span>);
                <span class="token punctuation">}</span>
            <span class="token punctuation">}</span>);
        <span class="token punctuation">}</span>);
    <span class="token punctuation">}</span>)
</code></pre> 
  <h2>二十三.对于多表查询如果涉及到四个表以上不推荐使用left join</h2> 
  <p><strong>通过内部查询的方式来查询设计多表的查询</strong></p> 
  <pre><code class="prism language-yaml">SELECT
            m.*<span class="token punctuation">,</span> (
                SELECT
                    username
                FROM
                    m_user
                WHERE
                    id = m.from_user_id
            ) AS fromUserName<span class="token punctuation">,</span>
            (
                SELECT
                    title
                FROM
                    m_post
                WHERE
                    id = m.post_id
            ) AS blogTitle<span class="token punctuation">,</span>
            (
                SELECT
                    content
                FROM
                    m_comment
                WHERE
                    id = m.comment_id
            ) AS commentContent
        FROM
            m_user_message m
        WHERE
            to_user_id=<span class="token comment">#{id}</span>
        ORDER BY created DESC
</code></pre> 
  <h2>二十四.shiro中对ajax的自定义过滤器</h2> 
  <p><strong>1.自定义过滤器</strong></p> 
  <pre><code class="prism language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">AuthFilter</span> <span class="token keyword">extends</span> <span class="token class-name">UserFilter</span> <span class="token punctuation">{</span>
    <span class="token comment">//重写没有登录重定向的方法</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">protected</span> <span class="token keyword">void</span> <span class="token function">redirectToLogin</span><span class="token punctuation">(</span>ServletRequest request<span class="token punctuation">,</span> ServletResponse response<span class="token punctuation">)</span> <span class="token keyword">throws</span> IOException <span class="token punctuation">{</span>
        HttpServletRequest httpServletRequest<span class="token operator">=</span> <span class="token punctuation">(</span>HttpServletRequest<span class="token punctuation">)</span> request<span class="token punctuation">;</span>
        <span class="token comment">//X-Requested-With: XMLHttpRequest</span>
        String header <span class="token operator">=</span> httpServletRequest<span class="token punctuation">.</span><span class="token function">getHeader</span><span class="token punctuation">(</span><span class="token string">"X-Requested-With"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//1.判断是否是ajax请求</span>
        <span class="token keyword">if</span><span class="token punctuation">(</span>header <span class="token operator">!=</span> null <span class="token operator">&&</span> <span class="token string">"XMLHttpRequest"</span><span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span>header<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token keyword">boolean</span> authenticated <span class="token operator">=</span> SecurityUtils<span class="token punctuation">.</span><span class="token function">getSubject</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">isAuthenticated</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token comment">//登录回超时</span>
            <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token operator">!</span>authenticated<span class="token punctuation">)</span><span class="token punctuation">{</span>
                response<span class="token punctuation">.</span><span class="token function">setContentType</span><span class="token punctuation">(</span><span class="token string">"application/json;charset=UTF-8"</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//设置字符集</span>
                JSONObject jsonObject<span class="token operator">=</span><span class="token keyword">new</span> <span class="token class-name">JSONObject</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                jsonObject<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"msg"</span><span class="token punctuation">,</span><span class="token string">"回话超时,请重新登录"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                response<span class="token punctuation">.</span><span class="token function">getWriter</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">print</span><span class="token punctuation">(</span>jsonObject<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span><span class="token keyword">else</span> <span class="token punctuation">{</span>
            <span class="token keyword">super</span><span class="token punctuation">.</span><span class="token function">redirectToLogin</span><span class="token punctuation">(</span>request<span class="token punctuation">,</span> response<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> 
  <p><strong>2.shiroconfig配置类中注入自定义过滤器bean</strong></p> 
  <pre><code class="prism language-java">    <span class="token comment">//把自己写的过滤器加入到容器中</span>
    <span class="token annotation punctuation">@Bean</span>
    <span class="token keyword">public</span> AuthFilter <span class="token function">authFilter</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">AuthFilter</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</code></pre> 
  <p><strong>3.shiroFilterFactoryBean中配置自己的过滤器</strong></p> 
  <pre><code class="prism language-java"><span class="token comment">//添加自定义的过滤器</span>
        Map filterMap<span class="token operator">=</span><span class="token keyword">new</span> <span class="token class-name">HashMap</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//注意不要与内置的过滤器相同了</span>
        filterMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"auth"</span><span class="token punctuation">,</span><span class="token function">authFilter</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        filterFactoryBean<span class="token punctuation">.</span><span class="token function">setFilters</span><span class="token punctuation">(</span>filterMap<span class="token punctuation">)</span><span class="token punctuation">;</span>


 <span class="token comment">//查看当前用户是否收藏了该博客  判断是否是ajax请求  ajax自己写一个过滤器 配置自己的过滤器</span>
        hashMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"/collection/find/"</span><span class="token punctuation">,</span> <span class="token string">"auth"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        hashMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"/collection/remove/"</span><span class="token punctuation">,</span> <span class="token string">"auth"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        hashMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"/collection/add/"</span><span class="token punctuation">,</span> <span class="token string">"auth"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> 
  <h2>二十五.java中使用hutool的断言</h2> 
  <p><strong>有时候在controller中,我们返回博客详情页面,可能出现博客以及不存在,那么我们就可以使用断言,如果不满足条件,就会抛出异常。</strong><br> 比如下方 当postVo==null 就会抛出异常 <strong>(注意是相反的哦)</strong></p> 
  <pre><code class="prism language-java">        <span class="token comment">//返回博客信息</span>
        PostVo postVo<span class="token operator">=</span>mPostService<span class="token punctuation">.</span><span class="token function">findPostById</span><span class="token punctuation">(</span>id<span class="token punctuation">)</span><span class="token punctuation">;</span>
        Assert<span class="token punctuation">.</span><span class="token function">isTrue</span><span class="token punctuation">(</span>postVo<span class="token operator">!=</span>null<span class="token punctuation">,</span><span class="token string">"该文章已被删除"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> 
 </div> 
</div>
                            </div>
                        </div>
                    </div>
                    <!--PC和WAP自适应版-->
                    <div id="SOHUCS" sid="1287932782168813568"></div>
                    <script type="text/javascript" src="/views/front/js/chanyan.js"></script>
                    <!-- 文章页-底部 动态广告位 -->
                    <div class="youdao-fixed-ad" id="detail_ad_bottom"></div>
                </div>
                <div class="col-md-3">
                    <div class="row" id="ad">
                        <!-- 文章页-右侧1 动态广告位 -->
                        <div id="right-1" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad">
                            <div class="youdao-fixed-ad" id="detail_ad_1"> </div>
                        </div>
                        <!-- 文章页-右侧2 动态广告位 -->
                        <div id="right-2" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad">
                            <div class="youdao-fixed-ad" id="detail_ad_2"></div>
                        </div>
                        <!-- 文章页-右侧3 动态广告位 -->
                        <div id="right-3" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad">
                            <div class="youdao-fixed-ad" id="detail_ad_3"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="container">
        <h4 class="pt20 mb15 mt0 border-top">你可能感兴趣的:(springboot)</h4>
        <div id="paradigm-article-related">
            <div class="recommend-post mb30">
                <ul class="widget-links">
                    <li><a href="/article/1835448238103162880.htm"
                           title="springboot+vue项目实战一-创建SpringBoot简单项目" target="_blank">springboot+vue项目实战一-创建SpringBoot简单项目</a>
                        <span class="text-muted">苹果酱0567</span>
<a class="tag" taget="_blank" href="/search/%E9%9D%A2%E8%AF%95%E9%A2%98%E6%B1%87%E6%80%BB%E4%B8%8E%E8%A7%A3%E6%9E%90/1.htm">面试题汇总与解析</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/boot/1.htm">boot</a><a class="tag" taget="_blank" href="/search/%E5%90%8E%E7%AB%AF/1.htm">后端</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E4%B8%AD%E9%97%B4%E4%BB%B6/1.htm">中间件</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a>
                        <div>这段时间抽空给女朋友搭建一个个人博客,想着记录一下建站的过程,就当做笔记吧。虽然复制zjblog只要一个小时就可以搞定一个网站,或者用cms系统,三四个小时就可以做出一个前后台都有的网站,而且想做成啥样也都行。但是就是要从新做,自己做的意义不一样,更何况,俺就是专门干这个的,嘿嘿嘿要做一个网站,而且从零开始,首先呢就是技术选型了,经过一番思量决定选择-SpringBoot做后端,前端使用Vue做一</div>
                    </li>
                    <li><a href="/article/1835438028768768000.htm"
                           title="Spring Boot中实现跨域请求" target="_blank">Spring Boot中实现跨域请求</a>
                        <span class="text-muted">BABA8891</span>
<a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/boot/1.htm">boot</a><a class="tag" taget="_blank" href="/search/%E5%90%8E%E7%AB%AF/1.htm">后端</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a>
                        <div>在SpringBoot中实现跨域请求(CORS,Cross-OriginResourceSharing)可以通过多种方式,以下是几种常见的方法:1.使用@CrossOrigin注解在SpringBoot中,你可以在控制器或者具体的请求处理方法上使用@CrossOrigin注解来允许跨域请求。在控制器上应用:importorg.springframework.web.bind.annotation.</div>
                    </li>
                    <li><a href="/article/1835437775344726016.htm"
                           title="博客网站制作教程" target="_blank">博客网站制作教程</a>
                        <span class="text-muted">2401_85194651</span>
<a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/maven/1.htm">maven</a>
                        <div>首先就是技术框架:后端:Java+SpringBoot数据库:MySQL前端:Vue.js数据库连接:JPA(JavaPersistenceAPI)1.项目结构blog-app/├──backend/│├──src/main/java/com/example/blogapp/││├──BlogApplication.java││├──config/│││└──DatabaseConfig.java</div>
                    </li>
                    <li><a href="/article/1835380041006018560.htm"
                           title="SpringBoot和SpringMVC是什么关系?SpringBoot替代SpringMVC了吗?" target="_blank">SpringBoot和SpringMVC是什么关系?SpringBoot替代SpringMVC了吗?</a>
                        <span class="text-muted">瑞金彭于晏</span>
<a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/boot/1.htm">boot</a><a class="tag" taget="_blank" href="/search/%E5%90%8E%E7%AB%AF/1.htm">后端</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/MVC/1.htm">MVC</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%BA%93/1.htm">数据库</a>
                        <div>SpringBoot和SpringMVC都是SpringFramework生态系统中的一部分,但它们各自扮演着不同的角色和提供不同的功能集。理解它们之间的关系,首先需要了解SpringFramework本身。SpringFrameworkSpringFramework是一个全面的、开源的应用程序开发框架,它提供了广泛的功能来支持企业应用开发的几乎所有方面。SpringFramework的核心特性之</div>
                    </li>
                    <li><a href="/article/1835373226490949632.htm"
                           title="Java -jar 如何在后台运行项目" target="_blank">Java -jar 如何在后台运行项目</a>
                        <span class="text-muted">vincent_hahaha</span>

                        <div>撸了今年阿里、头条和美团的面试,我有一个重要发现.......>>>说到运行jar包通常我们都会以下面的方式运行:java-jarspringboot-0.0.1-SNAPSHOT.jar这样运行的话会有一个问题,就是我们一关闭当前窗口就会停止运行项目,要想解决这个问题,就需要在后台运行。nohupjava-jarbabyshark-0.0.1-SNAPSHOT.jar >log.file 2>&</div>
                    </li>
                    <li><a href="/article/1835362136054919168.htm"
                           title="探索Zebra4J:构建高效企业级Web应用的微服务框架" target="_blank">探索Zebra4J:构建高效企业级Web应用的微服务框架</a>
                        <span class="text-muted">叶准鑫Natalie</span>

                        <div>探索Zebra4J:构建高效企业级Web应用的微服务框架ZebraZebra4J/Zebra4Js基于SpringBoot的JavaWeb/Nodejs框架项目地址:https://gitcode.com/gh_mirrors/zebra/Zebra项目介绍在当今快速发展的技术环境中,构建高效、可扩展的企业级Web应用是每个开发团队的追求。Zebra4J作为一款基于SpringBoot的全新微服务</div>
                    </li>
                    <li><a href="/article/1835277244763828224.htm"
                           title="Sentinel实时监控不展示问题" target="_blank">Sentinel实时监控不展示问题</a>
                        <span class="text-muted">朱杰jjj</span>
<a class="tag" taget="_blank" href="/search/sentinel/1.htm">sentinel</a><a class="tag" taget="_blank" href="/search/sentinel/1.htm">sentinel</a>
                        <div>问题官方插件Endpoint支持,可以实时统计出SpringBoot的健康状况和请求的调用信息在使用Endpoint特性之前需要在Maven中添加spring-boot-starter-actuator依赖,并在配置中允许Endpoints的访问。SpringBoot1.x中添加配置management.security.enabled=false。暴露的endpoint路径为/sentinelS</div>
                    </li>
                    <li><a href="/article/1835273340084908032.htm"
                           title="36. MyBatis如何支持多数据库操作?如何配置不同的数据源?" target="_blank">36. MyBatis如何支持多数据库操作?如何配置不同的数据源?</a>
                        <span class="text-muted">这孩子叫逆</span>
<a class="tag" taget="_blank" href="/search/Mybatis%E7%AC%94%E8%AE%B0/1.htm">Mybatis笔记</a><a class="tag" taget="_blank" href="/search/mybatis/1.htm">mybatis</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%BA%93/1.htm">数据库</a>
                        <div>在许多企业级应用中,可能需要访问多个数据库。MyBatis可以通过配置多个数据源和动态切换数据源来支持多数据库操作。下面介绍如何在MyBatis中配置和使用多个数据源。1.多数据源的基本配置1.1配置多个数据源要支持多个数据源,首先需要在Spring或SpringBoot中配置不同的数据源。假设我们要连接两个数据库db1和db2,可以通过以下步骤进行配置。SpringBoot示例:applicat</div>
                    </li>
                    <li><a href="/article/1835262244313722880.htm"
                           title="SpringBoot整合ES搜索引擎 实现网站热搜词及热度计算" target="_blank">SpringBoot整合ES搜索引擎 实现网站热搜词及热度计算</a>
                        <span class="text-muted">码踏云端</span>
<a class="tag" taget="_blank" href="/search/springboot/1.htm">springboot</a><a class="tag" taget="_blank" href="/search/Elasticsearch/1.htm">Elasticsearch</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/boot/1.htm">boot</a><a class="tag" taget="_blank" href="/search/elasticsearch/1.htm">elasticsearch</a><a class="tag" taget="_blank" href="/search/%E5%90%8E%E7%AB%AF/1.htm">后端</a><a class="tag" taget="_blank" href="/search/%E7%83%AD%E6%90%9C%E8%AF%8D/1.htm">热搜词</a><a class="tag" taget="_blank" href="/search/%E7%83%AD%E5%BA%A6%E8%AE%A1%E7%AE%97/1.htm">热度计算</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a>
                        <div>博主简介:历代文学网(PC端可以访问:https://literature.sinhy.com/#/literature?__c=1000,移动端可微信小程序搜索“历代文学”)总架构师,15年工作经验,精通Java编程,高并发设计,Springboot和微服务,熟悉Linux,ESXI虚拟化以及云原生Docker和K8s,热衷于探索科技的边界,并将理论知识转化为实际应用。保持对新技术的好奇心,乐于</div>
                    </li>
                    <li><a href="/article/1835233629056364544.htm"
                           title="java 技术 架构 相关文档" target="_blank">java 技术 架构 相关文档</a>
                        <span class="text-muted">圣心</span>
<a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E6%9E%B6%E6%9E%84/1.htm">架构</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a>
                        <div>在Java中,有许多不同的技术和架构,这里我将列举一些常见的Java技术和架构,并提供一些相关的文档资源。SpringFrameworkSpring是一个开源的Java/JavaEE全功能框架,以Apache许可证形式发布,提供了一种实现企业级应用的方法。官方文档:SpringFrameworkSpringBootSpringBoot是Spring的一个子项目,旨在简化创建生产级的Spring应用</div>
                    </li>
                    <li><a href="/article/1835225687028494336.htm"
                           title="java获取applicationcontext,SpringBoot获取ApplicationContext的3种方式" target="_blank">java获取applicationcontext,SpringBoot获取ApplicationContext的3种方式</a>
                        <span class="text-muted">花儿街参考</span>

                        <div>ApplicationContext是什么?简单来说就是Spring中的容器,可以用来获取容器中的各种bean组件,注册监听事件,加载资源文件等功能。ApplicationContext获取的几种方式1直接使用Autowired注入@ComponentpublicclassBook1{@AutowiredprivateApplicationContextapplicationContext;pub</div>
                    </li>
                    <li><a href="/article/1835215731222999040.htm"
                           title="SpringBoot 设置传入参数非必要" target="_blank">SpringBoot 设置传入参数非必要</a>
                        <span class="text-muted">loveLifeLoveCoding</span>
<a class="tag" taget="_blank" href="/search/springboot/1.htm">springboot</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/boot/1.htm">boot</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a>
                        <div>查看RequestParam源码packageorg.springframework.web.bind.annotation;importjava.lang.annotation.Documented;importjava.lang.annotation.ElementType;importjava.lang.annotation.Retention;importjava.lang.annotat</div>
                    </li>
                    <li><a href="/article/1835201490998882304.htm"
                           title="SpringBoot 获取 ApplicationContext" target="_blank">SpringBoot 获取 ApplicationContext</a>
                        <span class="text-muted">loveLifeLoveCoding</span>
<a class="tag" taget="_blank" href="/search/springboot/1.htm">springboot</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/boot/1.htm">boot</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a>
                        <div>1.概念ApplicationContext是什么?简单来说就是Spring中的容器,可以用来获取容器中的各种bean组件,注册监听事件,加载资源文件等功能2.获取ApplicationContext的方式2.1.创建工具类通过此工具类,可以方便的获取bean组件,获取配置信息等importorg.springframework.beans.BeansException;importorg.spr</div>
                    </li>
                    <li><a href="/article/1835189885280022528.htm"
                           title="关于项目中使用shiro进行安全管理的总结" target="_blank">关于项目中使用shiro进行安全管理的总结</a>
                        <span class="text-muted">一颗大青柠</span>
<a class="tag" taget="_blank" href="/search/Java/1.htm">Java</a><a class="tag" taget="_blank" href="/search/Shiro/1.htm">Shiro</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a>
                        <div>关于项目中使用shiro进行安全管理的总结关于SpringBoot下使用shiro进行用户认证与权限管理对于安全框架有一定了解的开发者一定对于shiro这款安全框架有一定的了解,这里我们不再对该框架进行其设计与知识的介绍,仅对于我的个人项目中所使用到的进行一个总结,并放上代码。使用该框架的第一步,进行配置:packagecom.libvirtjava.demo.vm.util.config;imp</div>
                    </li>
                    <li><a href="/article/1835188748925628416.htm"
                           title="Spring Boot 请求处理流程:从负载均衡到多实例并发 - 电子商务网站实例" target="_blank">Spring Boot 请求处理流程:从负载均衡到多实例并发 - 电子商务网站实例</a>
                        <span class="text-muted">烟雨国度</span>
<a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/boot/1.htm">boot</a><a class="tag" taget="_blank" href="/search/%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1/1.htm">负载均衡</a><a class="tag" taget="_blank" href="/search/%E5%90%8E%E7%AB%AF/1.htm">后端</a>
                        <div>SpringBoot请求处理流程:从负载均衡到多实例并发-电子商务网站实例SpringBoot请求处理流程:从负载均衡到多实例并发SpringBoot作为一个强大的Java应用开发框架,能够有效地处理高并发请求。本文将基于三个关键流程图,详细分析SpringBoot应用如何从负载均衡到请求处理,再到多实例并发处理的整个过程。1.负载均衡和多实例处理首先,让我们看一下描述负载均衡和多实例处理的流程图</div>
                    </li>
                    <li><a href="/article/1835180381905711104.htm"
                           title="微服务架构 | nacos - [自动刷新配置方式 & 失效排查]" target="_blank">微服务架构 | nacos - [自动刷新配置方式 & 失效排查]</a>
                        <span class="text-muted">问仙长何方蓬莱</span>
<a class="tag" taget="_blank" href="/search/%E5%BE%AE%E6%9C%8D%E5%8A%A1/1.htm">微服务</a><a class="tag" taget="_blank" href="/search/java%E6%8A%80%E6%9C%AF/1.htm">java技术</a><a class="tag" taget="_blank" href="/search/SpringCloud/1.htm">SpringCloud</a><a class="tag" taget="_blank" href="/search/%E5%BE%AE%E6%9C%8D%E5%8A%A1/1.htm">微服务</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/nacos/1.htm">nacos</a>
                        <div>INDEX§1配置方式§1.1springboot配置§1.2springcloud配置§2失效排查§2.1常见失效场景§2.1.1配置不配套§2.1.2自动刷新未开启§2.1.3依赖冲突§2.1.4改错了配置文件§2.2未知情况关键排查点§1配置方式nacos的配置中心主要有两套配置方式,配置方式不互相共通,需要配套配置springbootspringcloud§1.1springboot配置依</div>
                    </li>
                    <li><a href="/article/1835175340083867648.htm"
                           title="【免费】springboot项目申报管理系统|毕业设计|Javaweb项目" target="_blank">【免费】springboot项目申报管理系统|毕业设计|Javaweb项目</a>
                        <span class="text-muted">计算机学姐来啦</span>
<a class="tag" taget="_blank" href="/search/springboot/1.htm">springboot</a><a class="tag" taget="_blank" href="/search/ssm/1.htm">ssm</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/boot/1.htm">boot</a><a class="tag" taget="_blank" href="/search/%E8%AF%BE%E7%A8%8B%E8%AE%BE%E8%AE%A1/1.htm">课程设计</a><a class="tag" taget="_blank" href="/search/%E5%90%8E%E7%AB%AF/1.htm">后端</a><a class="tag" taget="_blank" href="/search/%E6%AF%95%E8%AE%BE/1.htm">毕设</a><a class="tag" taget="_blank" href="/search/%E6%AF%95%E4%B8%9A%E8%AE%BE%E8%AE%A1/1.htm">毕业设计</a><a class="tag" taget="_blank" href="/search/java-ee/1.htm">java-ee</a>
                        <div>收藏点赞不迷路关注作者有好处编号:springboot375springboot项目申报管理系统开发语言:Java数据库:MySQL技术:Spring+SpringMVC+MyBatis工具:IDEA/Ecilpse、Navicat、Maven1.万字文档展示(部分)2.系统图片展示第5章系统详细设计5.1管理员功能模块的实现5.1.1项目列表如图5.1显示的就是项目列表页面,此页面提供给管理员的</div>
                    </li>
                    <li><a href="/article/1835160866744528896.htm"
                           title="springboot与日志" target="_blank">springboot与日志</a>
                        <span class="text-muted">最后的夏t</span>

                        <div>日志1、日志框架小张;开发一个大型系统;1、System.out.println("");将关键数据打印在控制台;去掉?写在一个文件?2、框架来记录系统的一些运行时信息;日志框架;zhanglogging.jar;3、高大上的几个功能?异步模式?自动归档?xxxx?zhanglogging-good.jar?4、将以前框架卸下来?换上新的框架,重新修改之前相关的API;zhanglogging-p</div>
                    </li>
                    <li><a href="/article/1835147613041684480.htm"
                           title="计算机信息管理本科自考选题推荐" target="_blank">计算机信息管理本科自考选题推荐</a>
                        <span class="text-muted">李哥讲程序开发</span>
<a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/boot/1.htm">boot</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a>
                        <div>计算机信息管理专业是一个跨学科的领域,它结合了计算机技术与管理技术,旨在利用计算机完成各类信息管理。以下是一些推荐的自考选题方向:基于SSM的毕业设计管理系统的设计与实现基于SSM大学生校园兼职论坛管理系统基于SSM的家教应聘招聘系统的设计和实现基于SpringBoot住院患者满意度跟踪调查系统的设计与实现基于SpringBoot在线作业提交系统的设计与实现总的来说,这些建议的选题方向覆盖了计算机</div>
                    </li>
                    <li><a href="/article/1835096805776388096.htm"
                           title="springboot+mybatisplus实现基本的增删改查以及分页查询。这里使用的是Restful风格包括简单描述Restful是什么" target="_blank">springboot+mybatisplus实现基本的增删改查以及分页查询。这里使用的是Restful风格包括简单描述Restful是什么</a>
                        <span class="text-muted">okchan666</span>
<a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/boot/1.htm">boot</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a>
                        <div>先实现springboot+mybatisplus的增删改查接口使用postman测试:第一步创建项目导入依赖:直接给大家了:4.0.0org.springframework.bootspring-boot-starter-parent2.6.6com.okchanspringboot_07_ssmp0.0.1-SNAPSHOT1.8org.springframework.bootspring-b</div>
                    </li>
                    <li><a href="/article/1835089877234970624.htm"
                           title="SpringBoot2:web开发常用功能实现及原理解析-整合EasyExcel实现Excel导入导出功能" target="_blank">SpringBoot2:web开发常用功能实现及原理解析-整合EasyExcel实现Excel导入导出功能</a>
                        <span class="text-muted">生产队队长</span>
<a class="tag" taget="_blank" href="/search/Spring/1.htm">Spring</a><a class="tag" taget="_blank" href="/search/All/1.htm">All</a><a class="tag" taget="_blank" href="/search/excel/1.htm">excel</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/boot/1.htm">boot</a>
                        <div>1、工程包结构主要是这5个Java类2、导入EasyExcel包这里同时贴出其他相关springboot的基础包org.springframework.bootspring-boot-starter-weborg.springframework.bootspring-boot-devtoolsruntimetrueorg.springframework.bootspring-boot-config</div>
                    </li>
                    <li><a href="/article/1835089499072327680.htm"
                           title="nacos管理springboot配置时,发生的Could not resolve placeholder两种原因" target="_blank">nacos管理springboot配置时,发生的Could not resolve placeholder两种原因</a>
                        <span class="text-muted">生产队队长</span>
<a class="tag" taget="_blank" href="/search/Spring/1.htm">Spring</a><a class="tag" taget="_blank" href="/search/All/1.htm">All</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/boot/1.htm">boot</a>
                        <div>IllegalArgumentException:Couldnotresolveplaceholder'xxx.xxx.xxx'invalue"${xxx.xxx.xxx}"第一种:确实缺少配置,加上对应的配置即可。第二种:这个情况,可能会迷惑很多人报错某个配置无法引用,但是,检查配置时,确实存在,已经配置好了。而且,整个yml文件也没有语法格式错误。原因:我们在解决第一个问题的时候,可能导致这个</div>
                    </li>
                    <li><a href="/article/1835089497243611136.htm"
                           title="springboot整合MongoDB时碰到的问题" target="_blank">springboot整合MongoDB时碰到的问题</a>
                        <span class="text-muted">生产队队长</span>
<a class="tag" taget="_blank" href="/search/Database/1.htm">Database</a><a class="tag" taget="_blank" href="/search/Spring/1.htm">Spring</a><a class="tag" taget="_blank" href="/search/All/1.htm">All</a><a class="tag" taget="_blank" href="/search/mongodb/1.htm">mongodb</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a>
                        <div>1.账号总是不对,导致查不出数据,报错Auth…权鉴错误这次,我也是第一次接触MongoDB,非常的生疏springboot整合MongoDB,要在properties文件中配置账号mongodb基本语法:useDATABASE_NAME;--创建数据库showdbs;--查看我们所有的库,注意,我们刚创建的库,如果没有数据,是不会被显示的showusers;--查看当前库所有拥有的账号db.cr</div>
                    </li>
                    <li><a href="/article/1835019650895802368.htm"
                           title="python基于django/flask的NBA球员大数据分析与可视化python+java+node.js" target="_blank">python基于django/flask的NBA球员大数据分析与可视化python+java+node.js</a>
                        <span class="text-muted">QQ_511008285</span>
<a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/django/1.htm">django</a><a class="tag" taget="_blank" href="/search/flask/1.htm">flask</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/boot/1.htm">boot</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90/1.htm">数据分析</a>
                        <div>前端开发框架:vue.js数据库mysql版本不限后端语言框架支持:1java(SSM/springboot)-idea/eclipse2.Nodejs+Vue.js-vscode3.python(flask/django)--pycharm/vscode4.php(thinkphp/laravel)-hbuilderx数据库工具:Navicat/SQLyog等都可以本文针对NBA球员的大数据进行</div>
                    </li>
                    <li><a href="/article/1835019524521422848.htm"
                           title="Java基于spring boot的国产电影数据分析与可视化python+java+node.js" target="_blank">Java基于spring boot的国产电影数据分析与可视化python+java+node.js</a>
                        <span class="text-muted">QQ_511008285</span>
<a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/boot/1.htm">boot</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90/1.htm">数据分析</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/django/1.htm">django</a><a class="tag" taget="_blank" href="/search/vue.js/1.htm">vue.js</a><a class="tag" taget="_blank" href="/search/flask/1.htm">flask</a>
                        <div>前端开发框架:vue.js数据库mysql版本不限后端语言框架支持:1java(SSM/springboot)-idea/eclipse2.Nodejs+Vue.js-vscode3.python(flask/django)--pycharm/vscode4.php(thinkphp/laravel)-hbuilderx数据库工具:Navicat/SQLyog等都可以  该系统使用进行大数据处理和</div>
                    </li>
                    <li><a href="/article/1834985730561110016.htm"
                           title="SpringBoot—集成AOP详解(面向切面编程Aspect)" target="_blank">SpringBoot—集成AOP详解(面向切面编程Aspect)</a>
                        <span class="text-muted">Hughman</span>

                        <div>AOP介绍AOP概述  AOP是Aspect-OrientedProgramming,即为面向(切面)方面编程。在维基百科中的解释:Aspect是一种新的模块化机制,用来描述分散在对象、类或函数中的横切关注点。从关注点中分离出横切关注点是面向切面的程序设计核心概念。分离关注点使得解决特定领域问题的代码从业务逻辑中独立出来,业务逻辑代码不需要再包含针对特定领域问题代码的调用,比如一些公用模块的日志、</div>
                    </li>
                    <li><a href="/article/1834980687418060800.htm"
                           title="工程项目管理系统源码与Spring Cloud:实现高效系统管理与二次开发" target="_blank">工程项目管理系统源码与Spring Cloud:实现高效系统管理与二次开发</a>
                        <span class="text-muted">微服务技术分享</span>
<a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/cloud/1.htm">cloud</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E5%B7%A5%E7%A8%8B%E9%A1%B9%E7%9B%AE%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F%E6%BA%90%E7%A0%81/1.htm">工程项目管理系统源码</a>
                        <div>随着企业规模的不断扩大和业务的快速发展,传统的工程项目管理方式已经无法满足现代企业的需求。为了提高工程管理效率、减轻劳动强度、提高信息处理速度和准确性,企业需要借助先进的数字化技术进行转型。本文将介绍一款采用SpringCloud+SpringBoot+Mybatis技术框架的工程项目管理系统,该系统涵盖了项目管理、合同管理、预警管理、竣工管理、质量管理等多个方面,通过数据字典、编码管理、用户管理</div>
                    </li>
                    <li><a href="/article/1834972869294125056.htm"
                           title="springboot结合vue如何展示服务器磁盘里的图片,如何预览图片" target="_blank">springboot结合vue如何展示服务器磁盘里的图片,如何预览图片</a>
                        <span class="text-muted">夏之小星星</span>
<a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/boot/1.htm">boot</a><a class="tag" taget="_blank" href="/search/vue.js/1.htm">vue.js</a><a class="tag" taget="_blank" href="/search/%E6%9C%8D%E5%8A%A1%E5%99%A8/1.htm">服务器</a>
                        <div>1、在springboot配置文件中用spring.web.resources.static-locations配置静态资源路径例如图片的位置存放在服务器C盘下的路径为:C:/image/先在配置文件中使用web.upload-path配置磁盘路径如下web.upload-path=C:/image/再把该路径添加在静态资源路径里spring.web.resources.static-locati</div>
                    </li>
                    <li><a href="/article/1834961771631308800.htm"
                           title="Spring Boot项目自动生成OpenAPI3.0规范的接口描述文档yaml" target="_blank">Spring Boot项目自动生成OpenAPI3.0规范的接口描述文档yaml</a>
                        <span class="text-muted">1316901704@qq.com</span>
<a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/boot/1.htm">boot</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/openapi/1.htm">openapi</a>
                        <div>首先在pom.xml文件中添加springdoc-openapi的依赖:org.springdocspringdoc-openapi-core1.1.45启动SpringBoot程序,通过项目的ip和端口/v3/api-docs访问自动生成的OpenAPI3.0文档(JSON)/v3/api-docs.yaml下载yaml格式的文件如果想要自定义路径,可在application.propertie</div>
                    </li>
                    <li><a href="/article/1834957101491908608.htm"
                           title="基于springboot+vue的“考研资讯平台”程序设计实现【毕业论文,源码】" target="_blank">基于springboot+vue的“考研资讯平台”程序设计实现【毕业论文,源码】</a>
                        <span class="text-muted">一枚务实的码农</span>
<a class="tag" taget="_blank" href="/search/%E6%AF%95%E4%B8%9A%E8%AE%BE%E8%AE%A1/1.htm">毕业设计</a><a class="tag" taget="_blank" href="/search/%E6%AF%95%E8%AE%BE/1.htm">毕设</a><a class="tag" taget="_blank" href="/search/%E8%80%83%E7%A0%94/1.htm">考研</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/boot/1.htm">boot</a><a class="tag" taget="_blank" href="/search/%E6%AF%95%E4%B8%9A%E8%AE%BA%E6%96%87/1.htm">毕业论文</a><a class="tag" taget="_blank" href="/search/%E7%B3%BB%E7%BB%9F%E6%BA%90%E7%A0%81/1.htm">系统源码</a>
                        <div>摘要随着现在网络的快速发展,网络的应用在各行各业当中它很快融入到了许多学校的眼球之中,他们利用网络来做这个电商的服务,随之就产生了“考研资讯平台”,这样就让学生考研资讯平台更加方便简单。对于本考研资讯平台的设计来说,它主要是采用java技术。在整个系统的设计当中它是应用mysql数据库来完成的,具体根据网上考研资讯平台的现状来进行开发的,具体根据学生需求实现网上考研资讯平台网络化的管理,各类信息有</div>
                    </li>
                                <li><a href="/article/56.htm"
                                       title="多线程编程之存钱与取钱" target="_blank">多线程编程之存钱与取钱</a>
                                    <span class="text-muted">周凡杨</span>
<a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/thread/1.htm">thread</a><a class="tag" taget="_blank" href="/search/%E5%A4%9A%E7%BA%BF%E7%A8%8B/1.htm">多线程</a><a class="tag" taget="_blank" href="/search/%E5%AD%98%E9%92%B1/1.htm">存钱</a><a class="tag" taget="_blank" href="/search/%E5%8F%96%E9%92%B1/1.htm">取钱</a>
                                    <div>  
生活费问题是这样的:学生每月都需要生活费,家长一次预存一段时间的生活费,家长和学生使用统一的一个帐号,在学生每次取帐号中一部分钱,直到帐号中没钱时 通知家长存钱,而家长看到帐户还有钱则不存钱,直到帐户没钱时才存钱。   
问题分析:首先问题中有三个实体,学生、家长、银行账户,所以设计程序时就要设计三个类。其中银行账户只有一个,学生和家长操作的是同一个银行账户,学生的行为是</div>
                                </li>
                                <li><a href="/article/183.htm"
                                       title="java中数组与List相互转换的方法" target="_blank">java中数组与List相互转换的方法</a>
                                    <span class="text-muted">征客丶</span>
<a class="tag" taget="_blank" href="/search/JavaScript/1.htm">JavaScript</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/jsonp/1.htm">jsonp</a>
                                    <div>1.List转换成为数组。(这里的List是实体是ArrayList) 
  调用ArrayList的toArray方法。 
  toArray 
  public T[] toArray(T[] a)返回一个按照正确的顺序包含此列表中所有元素的数组;返回数组的运行时类型就是指定数组的运行时类型。如果列表能放入指定的数组,则返回放入此列表元素的数组。否则,将根据指定数组的运行时类型和此列表的大小分</div>
                                </li>
                                <li><a href="/article/310.htm"
                                       title="Shell 流程控制" target="_blank">Shell 流程控制</a>
                                    <span class="text-muted">daizj</span>
<a class="tag" taget="_blank" href="/search/%E6%B5%81%E7%A8%8B%E6%8E%A7%E5%88%B6/1.htm">流程控制</a><a class="tag" taget="_blank" href="/search/if+else/1.htm">if else</a><a class="tag" taget="_blank" href="/search/while/1.htm">while</a><a class="tag" taget="_blank" href="/search/case/1.htm">case</a><a class="tag" taget="_blank" href="/search/shell/1.htm">shell</a>
                                    <div>Shell 流程控制 
和Java、PHP等语言不一样,sh的流程控制不可为空,如(以下为PHP流程控制写法): 
<?php
if(isset($_GET["q"])){
    search(q);}else{// 不做任何事情} 
在sh/bash里可不能这么写,如果else分支没有语句执行,就不要写这个else,就像这样  if else if 
if 语句语</div>
                                </li>
                                <li><a href="/article/437.htm"
                                       title="Linux服务器新手操作之二" target="_blank">Linux服务器新手操作之二</a>
                                    <span class="text-muted">周凡杨</span>
<a class="tag" taget="_blank" href="/search/Linux+%E7%AE%80%E5%8D%95+%E6%93%8D%E4%BD%9C/1.htm">Linux 简单 操作</a>
                                    <div>1.利用关键字搜寻Man Pages    man -k keyword  其中-k 是选项,keyword是要搜寻的关键字 如果现在想使用whoami命令,但是只记住了前3个字符who,就可以使用 man -k who来搜寻关键字who的man命令       [haself@HA5-DZ26 ~]$ man -k </div>
                                </li>
                                <li><a href="/article/564.htm"
                                       title="socket聊天室之服务器搭建" target="_blank">socket聊天室之服务器搭建</a>
                                    <span class="text-muted">朱辉辉33</span>
<a class="tag" taget="_blank" href="/search/socket/1.htm">socket</a>
                                    <div>因为我们做的是聊天室,所以会有多个客户端,每个客户端我们用一个线程去实现,通过搭建一个服务器来实现从每个客户端来读取信息和发送信息。 
   我们先写客户端的线程。 
public class ChatSocket extends Thread{ 
 Socket socket; 
 
 public ChatSocket(Socket socket){ 
 this.sock</div>
                                </li>
                                <li><a href="/article/691.htm"
                                       title="利用finereport建设保险公司决策分析系统的思路和方法" target="_blank">利用finereport建设保险公司决策分析系统的思路和方法</a>
                                    <span class="text-muted">老A不折腾</span>
<a class="tag" taget="_blank" href="/search/finereport/1.htm">finereport</a><a class="tag" taget="_blank" href="/search/%E9%87%91%E8%9E%8D%E4%BF%9D%E9%99%A9/1.htm">金融保险</a><a class="tag" taget="_blank" href="/search/%E5%88%86%E6%9E%90%E7%B3%BB%E7%BB%9F/1.htm">分析系统</a><a class="tag" taget="_blank" href="/search/%E6%8A%A5%E8%A1%A8%E7%B3%BB%E7%BB%9F/1.htm">报表系统</a><a class="tag" taget="_blank" href="/search/%E9%A1%B9%E7%9B%AE%E5%BC%80%E5%8F%91/1.htm">项目开发</a>
                                    <div>决策分析系统呈现的是数据页面,也就是俗称的报表,报表与报表间、数据与数据间都按照一定的逻辑设定,是业务人员查看、分析数据的平台,更是辅助领导们运营决策的平台。底层数据决定上层分析,所以建设决策分析系统一般包括数据层处理(数据仓库建设)。 
  
项目背景介绍 
通常,保险公司信息化程度很高,基本上都有业务处理系统(像集团业务处理系统、老业务处理系统、个人代理人系统等)、数据服务系统(通过</div>
                                </li>
                                <li><a href="/article/818.htm"
                                       title="始终要页面在ifream的最顶层" target="_blank">始终要页面在ifream的最顶层</a>
                                    <span class="text-muted">林鹤霄</span>

                                    <div>index.jsp中有ifream,但是session消失后要让login.jsp始终显示到ifream的最顶层。。。始终没搞定,后来反复琢磨之后,得到了解决办法,在这儿给大家分享下。。 
index.jsp--->主要是加了颜色的那一句 
<html> 
<iframe name="top" ></iframe> 
<ifram</div>
                                </li>
                                <li><a href="/article/945.htm"
                                       title="MySQL binlog恢复数据" target="_blank">MySQL binlog恢复数据</a>
                                    <span class="text-muted">aigo</span>
<a class="tag" taget="_blank" href="/search/mysql/1.htm">mysql</a>
                                    <div>1,先确保my.ini已经配置了binlog: 
  
# binlog
log_bin = D:/mysql-5.6.21-winx64/log/binlog/mysql-bin.log
log_bin_index = D:/mysql-5.6.21-winx64/log/binlog/mysql-bin.index
log_error = D:/mysql-5.6.21-win</div>
                                </li>
                                <li><a href="/article/1072.htm"
                                       title="OCX打成CBA包并实现自动安装与自动升级" target="_blank">OCX打成CBA包并实现自动安装与自动升级</a>
                                    <span class="text-muted">alxw4616</span>
<a class="tag" taget="_blank" href="/search/ocx/1.htm">ocx</a><a class="tag" taget="_blank" href="/search/cab/1.htm">cab</a>
                                    <div>近来手上有个项目,需要使用ocx控件 
(ocx是什么? 
http://baike.baidu.com/view/393671.htm) 
在生产过程中我遇到了如下问题. 
1. 如何让 ocx 自动安装? 
    a) 如何签名? 
    b) 如何打包? 
    c) 如何安装到指定目录? 
2.</div>
                                </li>
                                <li><a href="/article/1199.htm"
                                       title="Hashmap队列和PriorityQueue队列的应用" target="_blank">Hashmap队列和PriorityQueue队列的应用</a>
                                    <span class="text-muted">百合不是茶</span>
<a class="tag" taget="_blank" href="/search/Hashmap%E9%98%9F%E5%88%97/1.htm">Hashmap队列</a><a class="tag" taget="_blank" href="/search/PriorityQueue%E9%98%9F%E5%88%97/1.htm">PriorityQueue队列</a>
                                    <div>  
HashMap队列已经是学过了的,但是最近在用的时候不是很熟悉,刚刚重新看以一次, 
  HashMap是K,v键 ,值   
  
put()添加元素 
  
  
 //下面试HashMap去掉重复的 
package com.hashMapandPriorityQueue;

import java.util.H</div>
                                </li>
                                <li><a href="/article/1326.htm"
                                       title="JDK1.5 returnvalue实例" target="_blank">JDK1.5 returnvalue实例</a>
                                    <span class="text-muted">bijian1013</span>
<a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/thread/1.htm">thread</a><a class="tag" taget="_blank" href="/search/java%E5%A4%9A%E7%BA%BF%E7%A8%8B/1.htm">java多线程</a><a class="tag" taget="_blank" href="/search/returnvalue/1.htm">returnvalue</a>
                                    <div>Callable接口: 
返回结果并且可能抛出异常的任务。实现者定义了一个不带任何参数的叫做 call 的方法。 
Callable 接口类似于 Runnable,两者都是为那些其实例可能被另一个线程执行的类设计的。但是 Runnable 不会返回结果,并且无法抛出经过检查的异常。 
        
ExecutorService接口方</div>
                                </li>
                                <li><a href="/article/1453.htm"
                                       title="angularjs指令中动态编译的方法(适用于有异步请求的情况) 内嵌指令无效" target="_blank">angularjs指令中动态编译的方法(适用于有异步请求的情况) 内嵌指令无效</a>
                                    <span class="text-muted">bijian1013</span>
<a class="tag" taget="_blank" href="/search/JavaScript/1.htm">JavaScript</a><a class="tag" taget="_blank" href="/search/AngularJS/1.htm">AngularJS</a>
                                    <div>        在directive的link中有一个$http请求,当请求完成后根据返回的值动态做element.append('......');这个操作,能显示没问题,可问题是我动态组的HTML里面有ng-click,发现显示出来的内容根本不执行ng-click绑定的方法! 
    </div>
                                </li>
                                <li><a href="/article/1580.htm"
                                       title="【Java范型二】Java范型详解之extend限定范型参数的类型" target="_blank">【Java范型二】Java范型详解之extend限定范型参数的类型</a>
                                    <span class="text-muted">bit1129</span>
<a class="tag" taget="_blank" href="/search/extend/1.htm">extend</a>
                                    <div>在第一篇中,定义范型类时,使用如下的方式: 
  
public class Generics<M, S, N> {
   //M,S,N是范型参数
} 
 这种方式定义的范型类有两个基本的问题: 
  
1. 范型参数定义的实例字段,如private M m = null;由于M的类型在运行时才能确定,那么我们在类的方法中,无法使用m,这跟定义pri</div>
                                </li>
                                <li><a href="/article/1707.htm"
                                       title="【HBase十三】HBase知识点总结" target="_blank">【HBase十三】HBase知识点总结</a>
                                    <span class="text-muted">bit1129</span>
<a class="tag" taget="_blank" href="/search/hbase/1.htm">hbase</a>
                                    <div>1. 数据从MemStore flush到磁盘的触发条件有哪些? 
   a.显式调用flush,比如flush 'mytable' 
   b.MemStore中的数据容量超过flush的指定容量,hbase.hregion.memstore.flush.size,默认值是64M 2. Region的构成是怎么样? 
1个Region由若干个Store组成</div>
                                </li>
                                <li><a href="/article/1834.htm"
                                       title="服务器被DDOS攻击防御的SHELL脚本" target="_blank">服务器被DDOS攻击防御的SHELL脚本</a>
                                    <span class="text-muted">ronin47</span>

                                    <div>mkdir /root/bin
vi /root/bin/dropip.sh
#!/bin/bash/bin/netstat -na|grep ESTABLISHED|awk ‘{print $5}’|awk -F:‘{print $1}’|sort|uniq -c|sort -rn|head -10|grep -v -E ’192.168|127.0′|awk ‘{if($2!=null&a</div>
                                </li>
                                <li><a href="/article/1961.htm"
                                       title="java程序员生存手册-craps 游戏-一个简单的游戏" target="_blank">java程序员生存手册-craps 游戏-一个简单的游戏</a>
                                    <span class="text-muted">bylijinnan</span>
<a class="tag" taget="_blank" href="/search/java/1.htm">java</a>
                                    <div>
import java.util.Random;


public class CrapsGame {

	/**
	 *
	 *一个简单的赌*博游戏,游戏规则如下:
	 *玩家掷两个骰子,点数为1到6,如果第一次点数和为7或11,则玩家胜,
	 *如果点数和为2、3或12,则玩家输,
	 *如果和为其它点数,则记录第一次的点数和,然后继续掷骰,直至点数和等于第一次掷出的点</div>
                                </li>
                                <li><a href="/article/2088.htm"
                                       title="TOMCAT启动提示NB: JAVA_HOME should point to a JDK not a JRE解决" target="_blank">TOMCAT启动提示NB: JAVA_HOME should point to a JDK not a JRE解决</a>
                                    <span class="text-muted">开窍的石头</span>
<a class="tag" taget="_blank" href="/search/JAVA_HOME/1.htm">JAVA_HOME</a>
                                    <div>当tomcat是解压的时候,用eclipse启动正常,点击startup.bat的时候启动报错; 
报错如下: 
  The JAVA_HOME environment variable is not defined correctly 
This environment variable is needed to run this program 
NB: JAVA_HOME shou</div>
                                </li>
                                <li><a href="/article/2215.htm"
                                       title="[操作系统内核]操作系统与互联网" target="_blank">[操作系统内核]操作系统与互联网</a>
                                    <span class="text-muted">comsci</span>
<a class="tag" taget="_blank" href="/search/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/1.htm">操作系统</a>
                                    <div> 
 
     我首先申明:我这里所说的问题并不是针对哪个厂商的,仅仅是描述我对操作系统技术的一些看法 
 
 
      操作系统是一种与硬件层关系非常密切的系统软件,按理说,这种系统软件应该是由设计CPU和硬件板卡的厂商开发的,和软件公司没有直接的关系,也就是说,操作系统应该由做硬件的厂商来设计和开发</div>
                                </li>
                                <li><a href="/article/2342.htm"
                                       title="富文本框ckeditor_4.4.7 文本框的简单使用 支持IE11" target="_blank">富文本框ckeditor_4.4.7 文本框的简单使用 支持IE11</a>
                                    <span class="text-muted">cuityang</span>
<a class="tag" taget="_blank" href="/search/%E5%AF%8C%E6%96%87%E6%9C%AC%E6%A1%86/1.htm">富文本框</a>
                                    <div><html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<title>知识库内容编辑</tit</div>
                                </li>
                                <li><a href="/article/2469.htm"
                                       title="Property null not found" target="_blank">Property null not found</a>
                                    <span class="text-muted">darrenzhu</span>
<a class="tag" taget="_blank" href="/search/datagrid/1.htm">datagrid</a><a class="tag" taget="_blank" href="/search/Flex/1.htm">Flex</a><a class="tag" taget="_blank" href="/search/Advanced/1.htm">Advanced</a><a class="tag" taget="_blank" href="/search/propery+null/1.htm">propery null</a>
                                    <div>When you got error message like "Property null not found ***", try to fix it by the following way: 
 
1)if you are using AdvancedDatagrid, make sure you only update the data in the data prov</div>
                                </li>
                                <li><a href="/article/2596.htm"
                                       title="MySQl数据库字符串替换函数使用" target="_blank">MySQl数据库字符串替换函数使用</a>
                                    <span class="text-muted">dcj3sjt126com</span>
<a class="tag" taget="_blank" href="/search/mysql/1.htm">mysql</a><a class="tag" taget="_blank" href="/search/%E5%87%BD%E6%95%B0/1.htm">函数</a><a class="tag" taget="_blank" href="/search/%E6%9B%BF%E6%8D%A2/1.htm">替换</a>
                                    <div>需求:需要将数据表中一个字段的值里面的所有的  .   替换成  _   
原来的数据是  site.title  site.keywords  .... 
替换后要为     site_title  site_keywords 
  
使用的SQL语句如下: 
  
updat</div>
                                </li>
                                <li><a href="/article/2723.htm"
                                       title="mac上终端起动MySQL的方法" target="_blank">mac上终端起动MySQL的方法</a>
                                    <span class="text-muted">dcj3sjt126com</span>
<a class="tag" taget="_blank" href="/search/mysql/1.htm">mysql</a><a class="tag" taget="_blank" href="/search/mac/1.htm">mac</a>
                                    <div>首先去官网下载: http://www.mysql.com/downloads/ 
我下载了5.6.11的dmg然后安装,安装完成之后..如果要用终端去玩SQL.那么一开始要输入很长的:/usr/local/mysql/bin/mysql 
这不方便啊,好想像windows下的cmd里面一样输入mysql -uroot -p1这样...上网查了下..可以实现滴. 
打开终端,输入: 
1</div>
                                </li>
                                <li><a href="/article/2850.htm"
                                       title="Gson使用一(Gson)" target="_blank">Gson使用一(Gson)</a>
                                    <span class="text-muted">eksliang</span>
<a class="tag" taget="_blank" href="/search/json/1.htm">json</a><a class="tag" taget="_blank" href="/search/gson/1.htm">gson</a>
                                    <div>转载请出自出处:http://eksliang.iteye.com/blog/2175401 一.概述 
从结构上看Json,所有的数据(data)最终都可以分解成三种类型: 
 
 第一种类型是标量(scalar),也就是一个单独的字符串(string)或数字(numbers),比如"ickes"这个字符串。 
 第二种类型是序列(sequence),又叫做数组(array)</div>
                                </li>
                                <li><a href="/article/2977.htm"
                                       title="android点滴4" target="_blank">android点滴4</a>
                                    <span class="text-muted">gundumw100</span>
<a class="tag" taget="_blank" href="/search/android/1.htm">android</a>
                                    <div>Android 47个小知识 
 
http://www.open-open.com/lib/view/open1422676091314.html 
 
 Android实用代码七段(一) 
 
http://www.cnblogs.com/over140/archive/2012/09/26/2611999.html 
 
http://www.cnblogs.com/over140/arch</div>
                                </li>
                                <li><a href="/article/3104.htm"
                                       title="JavaWeb之JSP基本语法" target="_blank">JavaWeb之JSP基本语法</a>
                                    <span class="text-muted">ihuning</span>
<a class="tag" taget="_blank" href="/search/javaweb/1.htm">javaweb</a>
                                    <div>  
目录 
  
JSP模版元素  
JSP表达式  
JSP脚本片断  
EL表达式  
JSP注释  
特殊字符序列的转义处理  
如何查找JSP页面中的错误 
  
JSP模版元素  
  
JSP页面中的静态HTML内容称之为JSP模版元素,在静态的HTML内容之中可以嵌套JSP</div>
                                </li>
                                <li><a href="/article/3231.htm"
                                       title="App Extension编程指南(iOS8/OS X v10.10)中文版" target="_blank">App Extension编程指南(iOS8/OS X v10.10)中文版</a>
                                    <span class="text-muted">啸笑天</span>
<a class="tag" taget="_blank" href="/search/ext/1.htm">ext</a>
                                    <div>  
  
  
  
 当iOS 8.0和OS X v10.10发布后,一个全新的概念出现在我们眼前,那就是应用扩展。顾名思义,应用扩展允许开发者扩展应用的自定义功能和内容,能够让用户在使用其他app时使用该项功能。你可以开发一个应用扩展来执行某些特定的任务,用户使用该扩展后就可以在多个上下文环境中执行该任务。比如说,你提供了一个能让用户把内容分</div>
                                </li>
                                <li><a href="/article/3358.htm"
                                       title="SQLServer实现无限级树结构" target="_blank">SQLServer实现无限级树结构</a>
                                    <span class="text-muted">macroli</span>
<a class="tag" taget="_blank" href="/search/oracle/1.htm">oracle</a><a class="tag" taget="_blank" href="/search/sql/1.htm">sql</a><a class="tag" taget="_blank" href="/search/SQL+Server/1.htm">SQL Server</a>
                                    <div> 
 表结构如下: 
 数据库id path titlesort 排序 1 0 首页 0 2 0,1 新闻 1 3 0,2 JAVA 2 4 0,3 JSP 3 5 0,2,3 业界动态 2 6 0,2,3 国内新闻 1 
 创建一个存储过程来实现,如果要在页面上使用可以设置一个返回变量将至传过去 
   
 create procedure test
as
begin
decla</div>
                                </li>
                                <li><a href="/article/3485.htm"
                                       title="Css居中div,Css居中img,Css居中文本,Css垂直居中div" target="_blank">Css居中div,Css居中img,Css居中文本,Css垂直居中div</a>
                                    <span class="text-muted">qiaolevip</span>
<a class="tag" taget="_blank" href="/search/%E4%BC%97%E8%A7%82%E5%8D%83%E8%B1%A1/1.htm">众观千象</a><a class="tag" taget="_blank" href="/search/%E5%AD%A6%E4%B9%A0%E6%B0%B8%E6%97%A0%E6%AD%A2%E5%A2%83/1.htm">学习永无止境</a><a class="tag" taget="_blank" href="/search/%E6%AF%8F%E5%A4%A9%E8%BF%9B%E6%AD%A5%E4%B8%80%E7%82%B9%E7%82%B9/1.htm">每天进步一点点</a><a class="tag" taget="_blank" href="/search/css/1.htm">css</a>
                                    <div>/**********Css居中Div**********/
div.center {
  width: 100px;
  margin: 0 auto;
}
/**********Css居中img**********/
img.center {
  display: block;
  margin-left: auto;
  margin-right: auto;
}

</div>
                                </li>
                                <li><a href="/article/3612.htm"
                                       title="Oracle 常用操作(实用)" target="_blank">Oracle 常用操作(实用)</a>
                                    <span class="text-muted">吃猫的鱼</span>
<a class="tag" taget="_blank" href="/search/oracle/1.htm">oracle</a>
                                    <div> 
  SQL>select text from all_source where owner=user and name=upper('&plsql_name');
  SQL>select * from user_ind_columns where index_name=upper('&index_name');  将表记录恢复到指定时间段以前</div>
                                </li>
                                <li><a href="/article/3739.htm"
                                       title="iOS中使用RSA对数据进行加密解密" target="_blank">iOS中使用RSA对数据进行加密解密</a>
                                    <span class="text-muted">witcheryne</span>
<a class="tag" taget="_blank" href="/search/ios/1.htm">ios</a><a class="tag" taget="_blank" href="/search/rsa/1.htm">rsa</a><a class="tag" taget="_blank" href="/search/iPhone/1.htm">iPhone</a><a class="tag" taget="_blank" href="/search/objective+c/1.htm">objective c</a>
                                    <div>  
RSA算法是一种非对称加密算法,常被用于加密数据传输.如果配合上数字摘要算法, 也可以用于文件签名. 
本文将讨论如何在iOS中使用RSA传输加密数据. 本文环境 
 
 mac os  
 openssl-1.0.1j, openssl需要使用1.x版本, 推荐使用[homebrew](http://brew.sh/)安装. 
 Java 8 
 RSA基本原理 
RS</div>
                                </li>
                </ul>
            </div>
        </div>
    </div>

<div>
    <div class="container">
        <div class="indexes">
            <strong>按字母分类:</strong>
            <a href="/tags/A/1.htm" target="_blank">A</a><a href="/tags/B/1.htm" target="_blank">B</a><a href="/tags/C/1.htm" target="_blank">C</a><a
                href="/tags/D/1.htm" target="_blank">D</a><a href="/tags/E/1.htm" target="_blank">E</a><a href="/tags/F/1.htm" target="_blank">F</a><a
                href="/tags/G/1.htm" target="_blank">G</a><a href="/tags/H/1.htm" target="_blank">H</a><a href="/tags/I/1.htm" target="_blank">I</a><a
                href="/tags/J/1.htm" target="_blank">J</a><a href="/tags/K/1.htm" target="_blank">K</a><a href="/tags/L/1.htm" target="_blank">L</a><a
                href="/tags/M/1.htm" target="_blank">M</a><a href="/tags/N/1.htm" target="_blank">N</a><a href="/tags/O/1.htm" target="_blank">O</a><a
                href="/tags/P/1.htm" target="_blank">P</a><a href="/tags/Q/1.htm" target="_blank">Q</a><a href="/tags/R/1.htm" target="_blank">R</a><a
                href="/tags/S/1.htm" target="_blank">S</a><a href="/tags/T/1.htm" target="_blank">T</a><a href="/tags/U/1.htm" target="_blank">U</a><a
                href="/tags/V/1.htm" target="_blank">V</a><a href="/tags/W/1.htm" target="_blank">W</a><a href="/tags/X/1.htm" target="_blank">X</a><a
                href="/tags/Y/1.htm" target="_blank">Y</a><a href="/tags/Z/1.htm" target="_blank">Z</a><a href="/tags/0/1.htm" target="_blank">其他</a>
        </div>
    </div>
</div>
<footer id="footer" class="mb30 mt30">
    <div class="container">
        <div class="footBglm">
            <a target="_blank" href="/">首页</a> -
            <a target="_blank" href="/custom/about.htm">关于我们</a> -
            <a target="_blank" href="/search/Java/1.htm">站内搜索</a> -
            <a target="_blank" href="/sitemap.txt">Sitemap</a> -
            <a target="_blank" href="/custom/delete.htm">侵权投诉</a>
        </div>
        <div class="copyright">版权所有 IT知识库 CopyRight © 2000-2050 E-COM-NET.COM , All Rights Reserved.
<!--            <a href="https://beian.miit.gov.cn/" rel="nofollow" target="_blank">京ICP备09083238号</a><br>-->
        </div>
    </div>
</footer>
<!-- 代码高亮 -->
<script type="text/javascript" src="/static/syntaxhighlighter/scripts/shCore.js"></script>
<script type="text/javascript" src="/static/syntaxhighlighter/scripts/shLegacy.js"></script>
<script type="text/javascript" src="/static/syntaxhighlighter/scripts/shAutoloader.js"></script>
<link type="text/css" rel="stylesheet" href="/static/syntaxhighlighter/styles/shCoreDefault.css"/>
<script type="text/javascript" src="/static/syntaxhighlighter/src/my_start_1.js"></script>





</body>

</html>