Spring boot博客功能

部分功能实现代码

BlogService.java

    @Autowired
    private BlogDao blogDao;
    @Override
    public Page<Blog> listBlog(Pageable pageable) {
        Page<Blog> page = blogDao.findAll(pageable);
        return page;
    }

    @Override
    public void deleteBlog(Long id) {
        blogDao.deleteById(id);
    }

TagService.java

@Service
public class TagService implements ITagService
{
    @Autowired
    private TagDao tagDao;
    @Override
    public Page<Tag> listTag(Pageable pageable) {
        Page<Tag> page = tagDao.findAll(pageable);
        return page;
    }

    @Override
    public void deleteTag(Long id) {
        tagDao.deleteById(id);
    }

    @Override
    public void addTag(Tag tag) {
        tagDao.save(tag);
    }

    @Override
    public Tag getTag(Long id) {
        return tagDao.getOne(id);
    }

    @Override
    public void update(Long id, Tag tag) {
        Tag tag1=tagDao.getOne(id);
        BeanUtils.copyProperties(tag,tag1);
        tagDao.save(tag1);
    }

TypeService.java

@Service
public class TypeService implements ITypeService
{
    @Autowired
    private TypeDao typeDao;
    @Override
    public Page<Type> listType(Pageable pageable) {
        Page<Type> page = typeDao.findAll(pageable);
        return page;
    }
    @Override
    public void deleteType(Long id)
    {
        typeDao.deleteById(id);
    }
    @Override
    public void addType(Type type)
    {
        typeDao.save(type);
    }
    @Override
    public Type getType(Long id)
    {
        return typeDao.getOne(id);
    }

    @Override
    public void update(Long id, Type type) {
        Type type1=typeDao.getOne(id);
        BeanUtils.copyProperties(type,type1);
        typeDao.save(type1);
    }

UserService.java

@Service
public class UserService implements IUserService {

    @Autowired
    private UserDao userDao;
    @Override
    public User checkUser(String username, String password) {
        return userDao.findByUsernameAndPassword(username,password);
    }
}

BlogController.java

@Controller
@RequestMapping("admin/blogs")
public class BlogController
{
    @Autowired
    private IBlogService blogService;

    @GetMapping
    public String list(@PageableDefault(size = 5,sort = {"id"},direction = Sort.Direction.DESC) Pageable pageable, Model model)
    {
        Page<Blog> page=blogService.listBlog(pageable);
        model.addAttribute("page",page);
        return "admin/blogs";
    }

    @GetMapping("{id}/delete")
    public String delete(@PathVariable Long id)
    {
        blogService.deleteBlog(id);
        return "redirect:/admin/blogs";
    }
}

LoginController.java


@Controller
@RequestMapping("/admin")
public class LoginController
{
    @Autowired
    private IUserService userService;

    @GetMapping
    public String toLogin()
    {
        return "admin/login";
    }
    @PostMapping("/login")
    public String login(String username, String password, HttpSession session, RedirectAttributes redirectAttributes)
    {
        User user=userService.checkUser(username,password);
        if (user!=null)
        {
            session.setAttribute("user",user);
            return "admin/index";
        }
        else
        {
            redirectAttributes.addFlashAttribute("message","用户名和密码错误");
            return "redirect:/admin";
        }

    }
    @GetMapping("/logout")
    public String logout(HttpSession session)
    {
        session.removeAttribute("user");
        return "admin/login";
    }
}

TagController.java

@Controller
@RequestMapping("admin/tags")
public class TagController
{
    @Autowired
    private ITagService tagService;

    @GetMapping
    public String list(@PageableDefault(size = 5,sort = {"id"},direction = Sort.Direction.DESC) Pageable pageable, Model model)
    {
        Page<Tag> page=tagService.listTag(pageable);
        model.addAttribute("page",page);
        return "admin/tags";
    }
    @GetMapping("{id}/delete")
    public String delete(@PathVariable Long id)
    {
        tagService.deleteTag(id);
        return "redirect:/admin/tags";
    }
    @GetMapping("input")
    public String input(Model model)
    {
        model.addAttribute("tag",new Tag());
        return "admin/tags-input";
    }
    @PostMapping("add")
    public String add(Tag tag)
    {
        tagService.addTag(tag);
        return "redirect:/admin/tags";
    }
    @GetMapping("{id}/toUpdate")
    public String toUpdate(@PathVariable Long id,Model model)
    {
        Tag tag=tagService.getTag(id);
        model.addAttribute("tag",tag);
        return "admin/tags-input";
    }

    @PostMapping("update/{id}")
    public String update(Tag tag,@PathVariable Long id)
    {
        tagService.update(id,tag);
        return "redirect:/admin/tags";
    }
}

TypeController.java

@Controller
@RequestMapping("/admin/types")
public class TypeController
{
    @Autowired
    private ITypeService typeService;
    @GetMapping
    public String list(@PageableDefault(size = 5,sort = {"id"},direction = Sort.Direction.DESC) Pageable pageable, Model model)
    {

        Page<Type> page=typeService.listType(pageable);
        model.addAttribute("page",page);
        return "admin/types";
    }
    @GetMapping("{id}/delete")
    public String delete(@PathVariable Long id)
    {
        typeService.deleteType(id);
        return "redirect:/admin/types";
    }

    @GetMapping("input")
    public String input(Model model)
    {
         model.addAttribute("type",new Type());
         return "admin/types-input";
    }
    @PostMapping("add")
    public String add(Type type)
    {
        typeService.addType(type);
        return "redirect:/admin/types";
    }
    @GetMapping("{id}/toUpdate")
    public String toUpdate(@PathVariable Long id,Model model)
    {
        Type type=typeService.getType(id);
        model.addAttribute("type",type);
        return "admin/types-input";
    }

    @PostMapping("update/{id}")
    public String update(Type type,@PathVariable Long id)
    {
        typeService.update(id,type);
        return "redirect:/admin/types";
    }
}

BlogApplication.java

@SpringBootApplication
public class BolgApplication {

    public static void main(String[] args) {
        SpringApplication.run(BolgApplication.class, args);
    }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
核心功能 文章/图片/视频发布、喜欢、统计阅读次数。 文章标签tag功能、支持按tag分类 文章支持ueditor/markdown编辑器切换(后台配置) 评论功能,支持回复,支持表情。 第三方(微博、QQ)登录。 lucene实现的站内搜索。 响应式布局 支持用户订阅 先看效果图 SpringBoot开发非常美观的java博客系统(包含后台管理功能) SpringBoot开发非常美观的java博客系统(包含后台管理功能) SpringBoot开发非常美观的java博客系统(包含后台管理功能) http://localhost:8080/admin/group/list SpringBoot开发非常美观的java博客系统(包含后台管理功能) SpringBoot开发非常美观的java博客系统(包含后台管理功能)SpringBoot开发非常美观的java博客系统(包含后台管理功能) 技术选型: JDK8 数据库MySQL 主框架 (Spring-bootSpring-data-jpa) 安全权限 Shiro 搜索工具 Lucene 缓存 Ehcache 视图模板 Freemarker 其它 Jsoup、fastjson jQuery、Seajs Bootstrap 前端框架 UEditor/Markdown编辑器 font-Awesome 字体/图标 准备工作(sql文件在项目里面) 安装 Jdk8 安装 Maven 准备 IDE (如果你不看源码,可以忽略下面的步骤,直接通过Maven编译war包:mvn clean package -DskipTests) IDE 需要配置的东西 编码方式设为UTF-8 配置Maven 设置Jdk8 关于这些配置,网上有一大把的资料,所以此处不再重复。 获取代码导入到IDE 下载代码 导入到IDE的时候请选择以Maven的方式导入 项目配置参考 系统配置手册 配置完毕 启动项目,在控制台看到Mblog加载完毕的信息后,表示启动成功 打开浏览器输入:http//localhost/mblog/ (此处仅是示例,具体具体端口因人而异),访问成功即部署完毕 后台管理的地址是 /admin, 如果你是管理员账号点导航栏的头像会看到"后台管理" 启动成功后,你应该去后台的系统配置里配置你的网站信息等。 常见问题总结 进入系统后, 菜单加载不出来, 那应该是你没有导 db_init.sql 点标签显示乱码, 请设置Tomcat的 URIEncoding 为 UTF-8 项目截图 SpringBoot开发非常美观的java博客系统(包含后台管理功能) 转自:https://gitee.com/mtons/mblog SpringBoot开发非常美观的java博客系统(包含后台管理功能) 注意: 一、java main方式运行mblog-web下的BootApplication.java时抛出异常的解决方案 Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean. SpringBoot开发非常美观的java博客系统(包含后台管理功能) 注释掉后下面图片的这段后,记得maven要重新reimport SpringBoot开发非常美观的java博客系统(包含后台管理功能) SpringBoot开发非常美观的java博客系统(包含后台管理功能) 否则maven依赖不生效还是会抛出以上的异常 二、第三方登录点击后无响应,那是因为第三方开放平台回调的url失效导致,需要你去对应的第三方开放平台注册app后获取对应的oauth帐号 SpringBoot开发非常美观的java博客系统(包含后台管理功能) 三、idea以maven项目导入该项目后,发现没有maven的依赖包时,需要对每个maven module进行clear和install,并且注意maven的依赖顺序 SpringBoot开发非常美观的java博客系统(包含后台管理功能) SpringBoot开发非常美观的java博客系统(包含后台管理功能) 四、访问地址是http://localhost:8080 登录时,帐号,密码只要自己找个密码,然后md5下在更新到db中即可登录成功。 比如:zuidaima 111111,md5后密码是 3931MUEQD1939MQMLM4AISPVNE,md5的java类 SpringBoot开发非常美观的java博客系统(包含后台管理功能) SpringBoot开发非常美观的java博客系统(包含后台管理功能)

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值