SpringBoot企业级博客开发

1.springboot生成项目

 PS : 进入项目,输入gradle build,生成build文件夹;  然后进入libs有jar,使用java jar进行运行项目

 

 

PS: 这个项目没有准守restful APi

 

 

 

 

 

PS: 顺序扫描效率不高

      全文搜索就是把无规则的再次组织形成有规律数据,再进行创建索引。

PS: 非常类似于查字典,可以按照顺序一个一个找,也可以按照拼音找

------------------------------------------------------------------------

 

 

搜索引擎选择: Elasticsearch与Solr, 目前es会更火爆

PS:索引可以划分成 多个分片(因为索引的数据量太大,所以继续划分), 一个分片又可以划分成多个副本

PS: 近实时, 就是添加一个东西以后,不会立马刷入磁盘,等个几s才能查的到

PS: 类型,对索引进行分类

PS: 文档是进行索引的基本单位,每个索引都有一个文档与之对应

-------------------------------------------------------------------------------------------------------------------

 

PS : 安装启动es

PS:  和jpa类似 会根据名字查询

 

PS : 这个normalize用来解决跨浏览器的一致性

 

-----------------------------------

 PS: 现在测试一个只根据    超小屏幕  和 中屏幕 开发的项目

 PS: 这是中屏幕的效果

 

 

 

------------------------实战后台

package com.waylau.spring.boot.blog.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * Spring Security 配置类.
 * 
 * @since 1.0.0 2017年3月8日
 * @author <a href="https://waylau.com">Way Lau</a>
 */
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true) // 启用方法安全设置
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    
    private static final String KEY = "waylau.com";
    
    @Autowired
    private UserDetailsService userDetailsService;

    @Autowired
    private PasswordEncoder passwordEncoder;
    
    @Bean  
    public PasswordEncoder passwordEncoder() {  
        return new BCryptPasswordEncoder();   // 使用 BCrypt 加密
    }  
    
    @Bean  
    public AuthenticationProvider authenticationProvider() {  
        DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider();
        authenticationProvider.setUserDetailsService(userDetailsService);
        authenticationProvider.setPasswordEncoder(passwordEncoder); // 设置密码加密方式
        return authenticationProvider;  
    }  
 
    /**
     * 自定义配置,  !!!!必须重写这个方法
     */
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().antMatchers("/css/**", "/js/**", "/fonts/**", "/index").permitAll() // 都可以访问
                .antMatchers("/h2-console/**").permitAll() // 都可以访问
                .antMatchers("/admins/**").hasRole("ADMIN") // 需要相应的角色才能访问,  只有admin才能访问/admins/**
                .and()
                .formLogin()   //基于 Form 表单登录验证
                .loginPage("/login").failureUrl("/login-error") // 自定义登录界面
                .and().rememberMe().key(KEY) // 启用 remember me
                .and().exceptionHandling().accessDeniedPage("/403");  // 处理异常,拒绝访问就重定向到 403 页面
        http.csrf().ignoringAntMatchers("/h2-console/**"); // 禁用 H2 控制台的 CSRF 防护
        http.headers().frameOptions().sameOrigin(); // 允许来自同一来源的H2 控制台的请求
    }
    
    /**
     * 认证信息管理
     * @param auth
     * @throws Exception
     */
    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(userDetailsService);
        auth.authenticationProvider(authenticationProvider());
    }
}
package com.waylau.spring.boot.blog.controller;

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import com.waylau.spring.boot.blog.domain.Authority;
import com.waylau.spring.boot.blog.domain.User;
import com.waylau.spring.boot.blog.service.AuthorityService;
import com.waylau.spring.boot.blog.service.UserService;

/**
 * 主页控制器.
 * 
 * @since 1.0.0 2017年3月8日
 * @author <a href="https://waylau.com">Way Lau</a> 
 */
@Controller
public class MainController {
    
    private static final Long ROLE_USER_AUTHORITY_ID = 2L;
    
    @Autowired
    private UserService userService;
    
    @Autowired
    private AuthorityService  authorityService;
    
    @GetMapping("/")
    public String root() {
        return "redirect:/index";
    }
    
    @GetMapping("/index")
    public String index() {
        return "redirect:/blogs";
    }

    /**
     * 获取登录界面
     * @return
     */
    @GetMapping("/login")
    public String login() {
        return "login";
    }

    @GetMapping("/login-error")
    public String loginError(Model model) {
        model.addAttribute("loginError", true);
        model.addAttribute("errorMsg", "登陆失败,账号或者密码错误!");
        return "login";
    }
    
    @GetMapping("/register")
    public String register() {
        return "register";
    }
    
    /**
     * 注册用户
     * @param user
     * @param result
     * @param redirect
     * @return
     */
    @PostMapping("/register")
    public String registerUser(User user) {
        List<Authority> authorities = new ArrayList<>();
        authorities.add(authorityService.getAuthorityById(ROLE_USER_AUTHORITY_ID));
        user.setAuthorities(authorities);
        userService.saveUser(user);
        return "redirect:/login";
    }
    
    @GetMapping("/search")
    public String search() {
        return "search";
    }
}

--------------------------前台

 

原文地址:https://www.cnblogs.com/bee-home/p/9943377.html