Selaa lähdekoodia

合作公司以及首页控制跳转

5 vuotta sitten
vanhempi
commit
f2e3a090e4

+ 14 - 4
website/src/main/java/com/hssx/website/controller/ArticleController.java

@@ -1,7 +1,9 @@
 package com.hssx.website.controller;
 
 
+import com.hssx.website.entity.Cooperations;
 import com.hssx.website.service.ArticleService;
+import com.hssx.website.service.CooperationsService;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
@@ -21,12 +23,14 @@ public class ArticleController {
 
     @Autowired
     private ArticleService articleService;
+    @Autowired
+    private CooperationsService cooperationsService;
 
-    @ApiOperation("添加/修改公司")
-    @GetMapping("/add")
-    public String indexHtml(Model model) {
+    @ApiOperation("案例")
+    @GetMapping("/article")
+    public String index(Model model) {
         model = articleService.getList(model);
-        return "hello";
+        return "index";
     }
 //    @GetMapping("/")
 //    public String index(Model model) {
@@ -34,5 +38,11 @@ public class ArticleController {
 //        return "index";
 //    }
 
+    @ApiOperation("合作伙伴")
+    @GetMapping("/cooperations")
+    public String cooperations(Model model) {
+        model = cooperationsService.getList(model);
+        return "index";
+    }
 }
 

+ 1 - 1
website/src/main/java/com/hssx/website/defaultviewconfig/DefaultView.java

@@ -12,7 +12,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
 public class DefaultView extends WebMvcConfigurerAdapter {
   @Override
   public void addViewControllers(ViewControllerRegistry registry) {
-    registry.addViewController("/").setViewName("login");
+    registry.addViewController("/").setViewName("index");
     registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
     super.addViewControllers(registry);
   }

+ 2 - 0
website/src/main/java/com/hssx/website/service/CooperationsService.java

@@ -2,6 +2,7 @@ package com.hssx.website.service;
 
 import com.hssx.website.entity.Cooperations;
 import com.baomidou.mybatisplus.extension.service.IService;
+import org.springframework.ui.Model;
 
 /**
  * <p>
@@ -13,4 +14,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface CooperationsService extends IService<Cooperations> {
 
+    Model getList(Model model);
 }

+ 2 - 3
website/src/main/java/com/hssx/website/service/impl/ArticleServiceImpl.java

@@ -27,9 +27,8 @@ public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> impl
 
     @Override
     public Model getList(Model model) {
-        List<Article> list = articleMapper.selectList(new QueryWrapper<Article>().orderByAsc("id"));
-        model.addAttribute("list", list);
-        model.addAttribute("name", "name");
+        List<Article> articles = articleMapper.selectList(new QueryWrapper<Article>().orderByAsc("id"));
+        model.addAttribute("articles", articles);
         return model;
     }
 }

+ 14 - 1
website/src/main/java/com/hssx/website/service/impl/CooperationsServiceImpl.java

@@ -1,10 +1,16 @@
 package com.hssx.website.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.hssx.website.entity.Article;
 import com.hssx.website.entity.Cooperations;
 import com.hssx.website.mapper.CooperationsMapper;
 import com.hssx.website.service.CooperationsService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
+import org.springframework.ui.Model;
+
+import javax.annotation.Resource;
+import java.util.List;
 
 /**
  * <p>
@@ -16,5 +22,12 @@ import org.springframework.stereotype.Service;
  */
 @Service
 public class CooperationsServiceImpl extends ServiceImpl<CooperationsMapper, Cooperations> implements CooperationsService {
-
+    @Resource
+    private CooperationsMapper cooperationsMapper;
+    @Override
+    public Model getList(Model model) {
+        List<Cooperations> cooperations = cooperationsMapper.selectList(new QueryWrapper<Cooperations>().orderByAsc("id"));
+        model.addAttribute("cooperations", cooperations);
+        return model;
+    }
 }

+ 1 - 1
website/src/main/resources/templates/index.html

@@ -1,5 +1,5 @@
 <!DOCTYPE html>
-<html>
+<html xmlns:th="http://www.thymeleaf.org">
     <head>
         <meta charset="utf-8">
         <meta http-equiv="X-UA-Compatible" content="IE=edge">