项目---显示某一列详情

1.点击显示

    <a th:href="@{/provider/} + ${p.pid}" href="view.html"><img th:src="@{/img/read.png}"  alt="查看" title="查看"/></a>

2.dao类

package com.cc.springboot.dao;import com.cc.springboot.entities.Provider;
import org.springframework.stereotype.Repository;
import org.springframework.util.ObjectUtils;import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;@Repository
public class ProviderDao {private static Map<Integer, Provider> providerMap = null;private static Integer initId = 2006;static {providerMap = new HashMap<Integer, Provider>();providerMap.put(2001, new Provider(2001, "PR-AA", "梦学谷供应商111", "小张", "18888666981", "深圳软件园", "0911-0123456", "品质A"));providerMap.put(2002, new Provider(2002, "PR-BB", "梦学谷供应商222", "小李", "18888666982", "深圳软件园", "0911-0123453", "品质B"));providerMap.put(2003, new Provider(2003, "PR-CC", "梦学谷供应商333", "小白", "18888666983", "深圳软件园", "0911-0123454", "品质C"));providerMap.put(2004, new Provider(2004, "PR-DD", "梦学谷供应商444", "小梦", "18888666984", "深圳软件园", "0911-0123451", "品质D"));providerMap.put(2005, new Provider(2005, "PR-EE", "梦学谷供应商555", "小谷", "18888666985", "深圳软件园", "0911-0123452", "品质E"));}public void save(Provider provider){if(provider.getPid() == null){provider.setPid(initId++);}providerMap.put(provider.getPid(), provider);}public Collection<Provider> getAll(){return providerMap.values();}public Collection<Provider> getAll(String providerName){Collection<Provider> providers = getAll();//不为空if( !ObjectUtils.isEmpty( providerName )) {int count = 0;for (Provider provider: providers) {//包含则存在if ( provider.getProviderName().toUpperCase().contains(  providerName.toUpperCase() ) ) {count++;//count>1 表示集合至少有一个存在的用户, 否则创建新的集合providers = count > 1 ? providers : new ArrayList<Provider>();providers.add(provider);}}if(count==0){providers= new ArrayList<Provider>();}}return providers;}public Provider getProvider(Integer pid){return providerMap.get(pid);}public void delete(Integer pid){providerMap.remove(pid);}
}

 3.controller

package com.cc.springboot.controller;import com.cc.springboot.dao.ProviderDao;
import com.cc.springboot.entities.Provider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;import java.util.Collection;
import java.util.Map;@Controller
public class ProviderController {
//    日志Logger logger = LoggerFactory.getLogger(getClass());@AutowiredProviderDao providerDao;
//    @RequestMapping(value="/providers",method= RequestMethod.GET)@GetMapping("/providers")public String list(Map<String,Object> map,@RequestParam(value = "providerName",required = false) String providerName){logger.info("供应商列表查询。。。。"+providerName);Collection<Provider> providers = providerDao.getAll(providerName);map.put("providers",providers);map.put("providerName",providerName);return "provider/list";}@GetMapping("/provider/{pid}")public String view(@PathVariable("pid") Integer pid,Map<String,Object> map){logger.info("查询"+pid+"的供应商详细信息");Provider provider = providerDao.getProvider(pid);map.put("provider",provider);return "provider/view";}
}

3.显示的页面

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="en" th:replace="main/public :: #public_head">
</head>
<body>
<!--头部-->
<header class="publicHeader" th:replace="main/public :: #public_header">
</header>
<!--时间-->
<section class="publicTime"th:replace="main/public :: #public_time"><span id="time">2028年1月1日 11:11  星期一</span><a href="#">温馨提示:为了能正常浏览,请使用高版本浏览器!(IE10+)</a>
</section>
<!--主体内容-->
<section class="publicMian "><div class="left" th:replace="main/public :: #public_left(activeUri='provider')"></div><div class="right"><div class="location"><strong>你现在所在的位置是:</strong><span>供应商管理页面 >> 信息查看</span></div><div class="providerView"><p><strong>供应商编码:</strong><span th:text="${provider.pid}">PRO-CODE—001</span></p><p><strong>供应商名称:</strong><span th:text="${provider.providerName}">测试供应商001</span></p><p><strong>联系人:</strong><span th:text="${provider.people}">韩露</span></p><p><strong>联系电话:</strong><span th:text="${provider.phone}">15918230478</span></p><p><strong>传真:</strong><span th:text="${provider.fax}">15918230478</span></p><p><strong>描述:</strong><span th:text="${provider.describe}">描述</span></p><a th:href="@{/providers}" href="list.html">返回</a></div></div>
</section>
<footer class="footer"><div style="text-align:center;">	<p><a href="http://www.mengxuegu.com/" target="_blank">梦学谷 www.mengxuegu.com</a> 版权所有</p></div></footer>
<!--<script src="js/time.js"></script>-->
</body>
</html>

本文链接:https://my.lmcjl.com/post/11904.html

展开阅读全文

4 评论

留下您的评论.