125.【江道原项目总结】-程序员宅基地

技术标签: spring  spring boot  java  

1.项目简介

Gitee官网: https://gitee.com/lwt121788/hot-port-resault
基本环境:

SpringBoot 2.7.7 + Thymeleaf 2.7.7 + mail + aliyunpay

Maven依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.7</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.jsxs</groupId>
    <artifactId>HotPotRestaurant</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>HotPotRestaurant</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!--    修改成我们所需要的mysql版本     -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.6</version>
        </dependency>
        <!--  thymeleaf  -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
            <version>2.7.7</version>
        </dependency>
        <!--   mybatis     -->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.1</version>
        </dependency>
        <!--   lombok     -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <!--邮箱任务-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
        <!--  阿里巴巴云支付      -->
        <dependency>
            <groupId>com.alipay.sdk</groupId>
            <artifactId>alipay-sdk-java</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

项目介绍:

本项目设置的目的主要是: “练习自己的springBoot+thymeleaf”。在《江道原火锅店》项目中我们有三大特色:“1.页面逻辑好看、2.邮箱联系卖家、3.支付宝支付、4.门店导航”。页面我们采用 "模板之家"但对其页面进行修改调整,邮箱和支付宝较为重要

2.收获成果

邮箱发送
application.properties

#  邮箱
#  用户名
[email protected]
#  授权码
spring.mail.password=fvjumghtshkyechc
#  链接主机
spring.mail.host=smtp.qq.com
# 开启加密验证
spring.mail.properties.mail.smtp.ssl.enable=true

controller层

    @Resource
    JavaMailSenderImpl sender;
    //  发送邮件-功能
    @RequestMapping("/sendMail")
    @ResponseBody
    public String hotPotRestaurantSend(String emails,String information){
    
        if (emails.trim().substring(emails.length()-7).equals("@qq.com")){
    
            SimpleMailMessage message = new SimpleMailMessage();
            message.setSubject("火锅店-固墙店--用户联系");   //  主题
            message.setText(information);   // 文章内容

            message.setFrom(emails.trim());   //  发送人
            message.setTo("[email protected]");
            sender.send(message);
            return "信息已发送";
        }else {
    
            return "对不起您的邮箱不支持被Java所调用.请直接联系咨询热线: 18844129422 或开启STMP协议";
        }
    }

地图
地图html页面

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>吉先生的店-北京</title>
    <style type="text/css">
    #container{
      
        /*地图(容器)显示大小*/
        width:100%;
        height:100%;
    }
    </style>
    <!--引入Javascript API GL,参数说明参见下文-->
    <script src="https://map.qq.com/api/gljs?v=1.exp&key=XZUBZ-LJELP-XKEDX-V4N4F-TUSWS-NAFCV"></script>
	<script charset="utf-8" src="https://map.qq.com/api/gljs?v=1.exp&key=XZUBZ-LJELP-XKEDX-V4N4F-TUSWS-NAFCV"></script>
    <script>
        //地图初始化函数,本例取名为init,开发者可根据实际情况定义
        function initMap() {
      
            //定义地图中心点坐标
            var center = new TMap.LatLng(39.984120, 116.307484)
            //定义map变量,调用 TMap.Map() 构造函数创建地图
            var map = new TMap.Map(document.getElementById('container'), {
      
                center: center,//设置地图中心点坐标
                zoom: 17.2,   //设置地图缩放级别
                pitch: 43.5,  //设置俯仰角
                rotation: 45    //设置地图旋转角度
            });
        }
		function loadScript() {
      
		     var script = document.createElement("script");
		     script.type = "text/javascript";
		     script.src = "https://map.qq.com/api/gljs?v=1.exp&key=XZUBZ-LJELP-XKEDX-V4N4F-TUSWS-NAFCV&callback=initMap";
		     document.body.appendChild(script);
		}
		  
		window.onload = loadScript;
    </script>
</head>
<!-- 页面载入后,调用init函数 -->
<body onload="initMap()">
    <!-- 定义地图显示容器 -->
    <div id="container"></div>
</body>
</html>

利用RestFul风格降低controller冗余性

    //  门店的地图
    @RequestMapping({
    "/GPS/{address}","/GPS.html/{address}"})
    public String hotPotRestaurantBranch(@PathVariable("address") String address){
    
        return "GPS/GPS_"+address;
    }

支付宝支付
config配置类

package com.jsxs.config;

import java.io.FileWriter;
import java.io.IOException;

public class AlipayConfig {
    

    // 应用ID,您的APPID,收款账号既是您的APPID对应支付宝账号,开发时使用沙箱提供的APPID,生产环境改成自己的APPID
    public static String APP_ID = "2021000122620920";

    // 商户私钥,您的PKCS8格式RSA2私钥
    public static String APP_PRIVATE_KEY = "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQChoH3Kn7TelVQCBswpjMlu2c8Jr7ATH/JAs3COEBzDDespl/lAhUs8+sxCCmSySXN+uYshA6+Akov4UXF6+7XgMQTRHjcdZINT5U/ZnxBZlF1fALUXzqS41cOjHrRkkNK+Qs2Yi1jB9htWFJOmGJALU8vo7Qy9evJoW97J4sie+5lYviaawuGBF0pGukmiByk4e3gFsMkh4y73zMYnqbpoZGKLSlHBABmeq6ladIEf5A/xUTHcV6Un0c5B4YZH8d0t4voKYhnf0B51l51C17+oOHqyiVJHpl58vwbCIiirqTKTR8SqwoPPBpodoOC2F/IqanlXq4823nTodVEXCYOhAgMBAAECggEBAI2MtR4jyI+3UB+GPH+XIULH1p6xEw9sxwkLHeQNEGNzaSTASDbNhhsduo2L9Kx/z3qInOSJCccckSEkkrIWiC6UP5e1UqeXQ7zR86Cvwe3yFeQCBpeXDoQiEnhlh68bdrXSY6TZRR55n29ADh9FG8IP3WFdWe8IIgxriS5eQz2XzYOmSJAQsW69LreD+q5Lp97VPEjLAfPOaeMfsNSoaP40pZ+2/uQYsaaPcq0aIVO1idgxqzsJcSdtncbbYGBSYH8b248zjhqMX/PwgK/0jQBsvXJAG8IJLW9E7i5skFbQzqtxFCk4onfg8u00pWopMkEugUlQcBROh3f/ZZ0/mtECgYEA4W2nhxrc+VqsLl6/LwsCplyLlq6W26ihEePCYgcYcJHEmBDkRnBbmWyclsIDIJ+VEqaZ9VRwMfUeJf+IkxsWgxUEfApPHyzU+AVgpD6yZUEQog/Yql3m0A+KVBbyXGzrrd3gixQeSNV9FAvOZnPhcosot6Ao+O/BmcV89cL/+fcCgYEAt4vM+X8tyAnzTOmFYR95BVY7XooBNKWFInEJ2ykbmiD+8AOOo3wRwEQJpLp2RbtHKwvUGw7eNSAd8sddUwk751HQ3h0fiJQ2UUXpak3lGoKWWEY2ofHTeB+WTKOcIjk0WbX1GRuNnAJssrK2wkUlHpwz4h3o2GAPgw/07JGVSScCgYAvEou5/ZUJCLMNl8FKXH04KfkIBPsBcUv5BVtQxvSGhRnNOzG/t7SY7AIixO6MQGaLl3hsry4icHHUM3DcbvqbcqcWE70D4IO0KsNMaL8tv5FuleqDYMpSxfv3pTcEr8Xi74L058WPJe1RY0m9QRNhrMda2LnViZMevgti8k4rbwKBgQCs2EYKni1qt5Qa1b35HD5HPFFkUemYvlaFfJWfgTKxDmmFdJQaeHfu6yN5sO439IisjNMNOA8hUEFjo0LLM2LqDy32PM65O3l7R67roLcjI96Y+mXwU16lPHm5aklaISyfXq6VGlFcnRvnnExm3d562PYy9Z+UQ8HX1mr7bI18+QKBgQDO2bDicEShwtWcnT1Nooa4J0v/LILC1exBSX12OdjVCPkn52x/RmI7nQu/nzfwJB8/Spw5Kh93BGZr4qDMFSfE81L9ApWAtvQpbZ8oz22SRrCxno2rKHO4I2Bh50BtXjtTfO4u9TBIXdV1lr9+ivQCsup6KeslS9+xWsP92n58IQ==\n";

    // 支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
    public static String ALIPAY_PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAx0R/5SJaYXD9uBTfzbQJvYIh07GHVoeppfndAaoy/HNJrlot1zU9YfRl+1gJVN1J8yAuVBoXRVPpIiMi8K/fVjWWk7T6SbCRbBEKe0YVP/zUSrNP5FmYA+OLYPSsoy19DNbzkdtQA05mtoHcPNf5lzgeq6phLLWwQtpBbxb9gu29HT3oAfyio6PuslEdnRWVV+fMVK0BkgEa/XNdC8nKMgeeo9uzuzksW6INdVVN8DlElEr4GChAU6VN0FfK5szH0rTYYxAclJPwLEudVWF3hSXqf1kafXTGfKBCRYTYCoGywm0fQNXH7fZuqYpOu7duKkQJDB+RNxOMWRmU4cemdwIDAQAB\n";

    // 服务器异步通知页面路径  需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问
    public static String notify_url = "http://www.jsxs1.cn:8089/";

    // 页面跳转同步通知页面路径 需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问(其实就是支付成功后返回的页面)
    public static String return_url = "http://www.jsxs1.cn:8089/";

    // 签名方式
    public static String sign_type = "RSA2";

    // 字符编码格式
    public static String CHARSET = "utf-8";

    // 支付宝网关,这是沙箱的网关(你自己的)
    public static String gatewayUrl = "https://openapi.alipaydev.com/gateway.do";

    // 支付宝网关
    public static String log_path = "C:\\";


//↑↑↑↑↑↑↑↑↑↑请在这里配置您的基本信息↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

    /**
     * 写日志,方便测试(看网站需求,也可以改成把记录存入数据库)
     * @param sWord 要写入日志里的文本内容
     */
    public static void logResult(String sWord) {
    
        FileWriter writer = null;
        try {
    
            writer = new FileWriter(log_path + "alipay_log_" + System.currentTimeMillis()+".txt");
            writer.write(sWord);
        } catch (Exception e) {
    
            e.printStackTrace();
        } finally {
    
            if (writer != null) {
    
                try {
    
                    writer.close();
                } catch (IOException e) {
    
                    e.printStackTrace();
                }
            }
        }
    }
}

控制层使用Result风格

package com.jsxs.controller;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.jsxs.config.AlipayConfig;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

@Controller
public class PayController {
    


    @RequestMapping("/pay/{payMoney}")
    public void payController(HttpServletRequest request, HttpServletResponse response, @PathVariable("payMoney") String payMoney) throws IOException {
    
        //获得初始化的AlipayClient
        AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.APP_ID, AlipayConfig.APP_PRIVATE_KEY, "json", AlipayConfig.CHARSET, AlipayConfig.ALIPAY_PUBLIC_KEY, AlipayConfig.sign_type);

        //设置请求参数
        AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
        alipayRequest.setReturnUrl(AlipayConfig.return_url);
        alipayRequest.setNotifyUrl(AlipayConfig.notify_url);

        //商户订单号,商户网站订单系统中唯一订单号,必填

        //   订单号   order
        String order = UUID.randomUUID().toString().replaceAll("-", "");
        // 付款金额  money

        //订单名称
        String orderName="JSXS-JDYHGD";
        String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S").format(new Date());
        //商品描述
        String orderDescription=format+"";
        //
        String out_trade_no = new String(order.getBytes("ISO-8859-1"), "UTF-8");
        //付款金额,必填
        String total_amount = new String(payMoney.getBytes("ISO-8859-1"), "UTF-8");
        //订单名称,必填
        String subject = new String(orderName.getBytes("ISO-8859-1"), "gbk");
        //商品描述,可空
        String body = new String(orderDescription.getBytes("ISO-8859-1"), "gbk");

        alipayRequest.setBizContent("{\"out_trade_no\":\"" + out_trade_no + "\","
                + "\"total_amount\":\"" + total_amount + "\","
                + "\"subject\":\"" + subject + "\","
                + "\"body\":\"" + body + "\","
                + "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");

        //若想给BizContent增加其他可选请求参数,以增加自定义超时时间参数timeout_express来举例说明
        //alipayRequest.setBizContent("{\"out_trade_no\":\""+ out_trade_no +"\","
        //		+ "\"total_amount\":\""+ total_amount +"\","
        //		+ "\"subject\":\""+ subject +"\","
        //		+ "\"body\":\""+ body +"\","
        //		+ "\"timeout_express\":\"10m\","
        //		+ "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");
        //请求参数可查阅【电脑网站支付的API文档-alipay.trade.page.pay-请求参数】章节

        //请求
        String form = "";
        try {
    
            form = alipayClient.pageExecute(alipayRequest).getBody(); //调用SDK生成表单
        } catch (AlipayApiException e) {
    
            e.printStackTrace();
        }
        response.setContentType("text/html;charset=" + AlipayConfig.CHARSET);
        response.getWriter().write(form);//直接将完整的表单html输出到页面
        response.getWriter().flush();
        response.getWriter().close();
    }
    @RequestMapping("/preverpay")
    public String toTest(){
    

        return "aliyunpay";
    }
}

html 定价

						<ul class="clearfix">
							<li>
								<a th:href="@{/pay/10}">
									<figure><img src="/img/kaorou1.png"/></figure>
									<p>经典烤肉10.00元</p>
								</a>
							</li>
							<li>
								<a th:href="@{/pay/19}">
									<figure><img src="/img/kaorou2.png"/></figure>
									<p>烈火烤肉19.00元</p>
								</a>
							</li>
							<li>
								<a th:href="@{/pay/29.99}">
									<figure><img src="/img/kaorou3.png"/></figure>
									<p>五香烤肉29.99元</p>
								</a>
							</li>
							<li>
								<a th:href="@{/pay/46.10}">
									<figure><img src="/img/kaorou4.png"/></figure>
									<p>青醋烤肉46.10元</p>
								</a>
							</li>
							<li>
								<a th:href="@{/pay/100.20}">
									<figure><img src="/img/kaorou5.png"/></figure>
									<p>嘻嘻烤肉100.20元</p>
								</a>
							</li>
							<li>
								<a th:href="@{/pay/99.99}">
									<figure><img src="/img/kaorou6.png"/></figure>
									<p>暮春烤肉99.99元</p>
								</a>
							</li>
						</ul>

a标签提交表单

						<ul class="clearfix">
							<li>
								<form th:action="@{/pay}" id="price" method="post">
									<input type="hidden"  name="payMoney" value="10.00">
									<a href="#" onclick="document.getElementById('price').submit();return false;">
										<figure><img src="/img/kaorou1.png"/></figure>
										<p>经典烤肉10.00</p>
									</a>
								</form>
							</li>
							<li>
								<form th:action="@{/pay}" id="price2" method="post">
									<input type="hidden"  name="payMoney" value="19.00">
									<a href="#" onclick="document.getElementById('price2').submit();return false;">
									<figure><img src="/img/kaorou2.png"/></figure>
									<p>烈火烤肉19.00</p>
								</a>
								</form>
							</li>
							<li>
								<form th:action="@{/pay}" id="price3" method="post">
									<input type="hidden"  name="payMoney" value="29.99">
									<a href="#" onclick="document.getElementById('price3').submit();return false;">
									<figure><img src="/img/kaorou3.png"/></figure>
									<p>五香烤肉29.99</p>
								</a>
								</form>
							</li>
							<li>
								<form th:action="@{/pay}" id="price4" method="post">
									<input type="hidden"  name="payMoney" value="46.10">
									<a href="#" onclick="document.getElementById('price4').submit();return false;">
									<figure><img src="/img/kaorou4.png"/></figure>
									<p>青醋烤肉46.10</p>
								</a>
								</form>
							</li>
							<li>
								<form th:action="@{/pay}" id="price5" method="post">
									<input type="hidden"  name="payMoney" value="100.20">
									<a href="#" onclick="document.getElementById('price5').submit();return false;">
									<figure><img src="/img/kaorou5.png"/></figure>
									<p>嘻嘻烤肉100.20</p>
								</a>
								</form>
							</li>
							<li>
								<form th:action="@{/pay}" id="price6" method="post">
									<input type="hidden"  name="payMoney" value="10">
									<a href="#" onclick="document.getElementById('price6').submit();return false;">
									<figure><img src="/img/kaorou6.png"/></figure>
									<p>暮春烤肉99.99</p>
								</a>
								</form>
							</li>
						</ul>
   @RequestMapping("/pay")
    public void payController(HttpServletRequest request, HttpServletResponse response, String payMoney) throws IOException {
    
        //获得初始化的AlipayClient
        AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.APP_ID, AlipayConfig.APP_PRIVATE_KEY, "json", AlipayConfig.CHARSET, AlipayConfig.ALIPAY_PUBLIC_KEY, AlipayConfig.sign_type);

        //设置请求参数
        AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
        alipayRequest.setReturnUrl(AlipayConfig.return_url);
        alipayRequest.setNotifyUrl(AlipayConfig.notify_url);

        //商户订单号,商户网站订单系统中唯一订单号,必填

        //   订单号   order
        String order = UUID.randomUUID().toString().replaceAll("-", "");
        // 付款金额  money

        //订单名称
        String orderName="JSXS-JDYHGD";
        String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S").format(new Date());
        //商品描述
        String orderDescription=format+"";
        //
        String out_trade_no = new String(order.getBytes("ISO-8859-1"), "UTF-8");
        //付款金额,必填
        String total_amount = new String(payMoney.getBytes("ISO-8859-1"), "UTF-8");
        //订单名称,必填
        String subject = new String(orderName.getBytes("ISO-8859-1"), "gbk");
        //商品描述,可空
        String body = new String(orderDescription.getBytes("ISO-8859-1"), "gbk");

        alipayRequest.setBizContent("{\"out_trade_no\":\"" + out_trade_no + "\","
                + "\"total_amount\":\"" + total_amount + "\","
                + "\"subject\":\"" + subject + "\","
                + "\"body\":\"" + body + "\","
                + "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");

        //若想给BizContent增加其他可选请求参数,以增加自定义超时时间参数timeout_express来举例说明
        //alipayRequest.setBizContent("{\"out_trade_no\":\""+ out_trade_no +"\","
        //		+ "\"total_amount\":\""+ total_amount +"\","
        //		+ "\"subject\":\""+ subject +"\","
        //		+ "\"body\":\""+ body +"\","
        //		+ "\"timeout_express\":\"10m\","
        //		+ "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");
        //请求参数可查阅【电脑网站支付的API文档-alipay.trade.page.pay-请求参数】章节

        //请求
        String form = "";
        try {
    
            form = alipayClient.pageExecute(alipayRequest).getBody(); //调用SDK生成表单
        } catch (AlipayApiException e) {
    
            e.printStackTrace();
        }
        response.setContentType("text/html;charset=" + AlipayConfig.CHARSET);
        response.getWriter().write(form);//直接将完整的表单html输出到页面
        response.getWriter().flush();
        response.getWriter().close();
    }
    @RequestMapping("/preverpay")
    public String toTest(){
    

        return "aliyunpay";
    }
}

3.经验总结

  1. 切记第一件事情请勿把配置文件的文件名写错。

  2. springBoot的静态资源 不用指明路径。

  3. 在a标签中利用Resultful风格对数据

  4. 使用表的时候,表名一定要飘号

4.全部记录数据

  1. 切记第一件事情请勿把配置文件的文件名写错。

  2. springBoot的静态资源 不用指明路径。(就是在static的css js img可以直接被templates访问)

        <link rel=stylesheet type="text/css" href="/css/1024_768.css">
        <link type="text/css" href="/css/nav.css" rel="stylesheet"/>
        <script language="javascript" src="/js/jquery-1.7.2.min.js"></script>
        <script language="javascript" src="/js/nav.js"></script>
        <script language="javascript" src="/js/jquery.pack.js"></script>
        <script language="javascript" src="/js/slide.js"></script>
        <script language="javascript" src="/js/png.js"></script>
        <script type="text/javascript" src="/jwplayer.js"></script>
    
  3. 在a标签中利用Resultful风格实现对页面的跳转

    <a th:href="@{/news.html}" class="news">新闻中心</a>
    
  4. 只有thymeleaf才能去访问templates

  5. 如果没有在配置文件中配置数据库的信息,那就不要导入相关依赖。否则会报错

  6. document实现对页面的跳转 :

    <li class="roll_pic r_01" onclick="document.location.href='/cun/Pay'">
    
  7. 利用ResultFul风格试图降低Controller层的冗余性

        @RequestMapping("/cun/{tail}")
        public String cunPay(Model model,@PathVariable("tail") String tail){
          
            //   村委会账单公告
    
            double sum=0;
            List<payMoney> payMonies = liloucuncunweihuiServer.allPay();
            for (payMoney payMony : payMonies) {
          
                sum+=payMony.getMoney();
            }
            model.addAttribute("cunPay",payMonies);
            model.addAttribute("sumMomey","总支出: "+sum+"元");
    
            //   村委选举
    
            List<cunXuan> cunXuans = liloucuncunweihuiServer.allXuan();
    
            model.addAttribute("cunCount","村选人数: "+cunXuans.size());
            model.addAttribute("cunXuans",cunXuans);
    
            return "cunPublic/cun"+tail;
        }
    
    
  8. 表名可以驼峰,字段名要和实体类一致,在xml语法中表名和字段名也要和数据库的一致

  9. @{}标签与${}标签共用:

    <a th:href="@{/cunAdd/{id}(id=${cunxuan.id})}">投票</a>
    
  10. 如果我们在用controller重定向某一个路由的时候,第一个"/"一定要加上

        @RequestMapping("/cunAdd/{id}")
        public String addTickets(@PathVariable("id") int id){
          
            List<cunXuan> cunXuans = liloucuncunweihuiServer.allXuan();
            cunXuan cunXuan = cunXuans.get(id-1);
            int count = cunXuan.getSum_ticket();
            count+=1;
            int i = liloucuncunweihuiServer.addTicket(id, count);
            return "redirect:/cun/Xuan";
        }
    
  11. img实现对表单的提交

    <form th:action="@{/pay}" id="price5" method="post">
    <input type="hidden"  name="payMoney" value="100.20">
    <a href="#" onclick="document.getElementById('price5').submit();return false;">
    <figure><img src="/img/kaorou5.png"/></figure>
    <p>嘻嘻烤肉100.20元</p>
    </a>
    
  12. 如果使用了ResultFul风格的话,普通的路径就不能用了。

  13. 假如说在templates包中创建另一个news包,那么静态资源前面需要加上 “/“templates下的html页面也需要添加”/”

      <link rel=stylesheet type="text/css" href="/css/1024_768.css">
      <link type="text/css" href="/css/nav.css" rel="stylesheet"/>
      <link type="text/css" href="/css/about.css" rel="stylesheet"/>
      <script language="javascript" src="/js/jquery-1.7.2.min.js"></script>
      <script language="javascript" src="/js/nav.js"></script>
      <script language="javascript" src="/js/png.js"></script>
      <script language="javascript" src="/js/jquery.pack.js"></script>
      <script language="javascript" src="/js/slide.js"></script>
    


在这里插入图片描述

  1. 利用RestFul风格实现换内容不换页面的操作.

        @RequestMapping("/article/{id}")
        public String article(Model model,@PathVariable("id") int id){
          
            model.addAttribute("title1","关于卫生问题的公告!!");
            model.addAttribute("title2","关于卫生问题的公告!!2");
            article article = liloucuncunweihuiServer.articleById(id);
            model.addAttribute("article",article.getText());
            return "article/article1";
        }
    
  2. 日期格式化

    String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S").format(new Date());
    
  3. 新闻日期更新排序,(最新更新的文章放到最前面)

        @RequestMapping("/article/{id}")
        public String article(Model model, @PathVariable("id") int id) {
          
            // 这里是正文中的标题
            model.addAttribute("title1", "关于卫生问题的公告!!");
            model.addAttribute("title2", "关于卫生问题的公告!!2");
            model.addAttribute("title3", "关于卫生问题的公告!!3");
            model.addAttribute("title4", "关于卫生问题的公告!!4");
            model.addAttribute("title5", "关于卫生问题的公告!!5");
            model.addAttribute("title6", "关于卫生问题的公告!!6");
            // 查询全部文章信息
            List<article> articles = liloucuncunweihuiServer.allArticle();
    /**
     *     链表需要反转!!
     *     这里我们实现了对内容的更新,并且实现了把最新的内容放到了最前面
     */
            article article = liloucuncunweihuiServer.articleById(articles.size() + (1 - id));
            model.addAttribute("article", article.getText());
            return "article/article1";
        }
    
  4. List链表反向遍历

    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>31.0.1-jre</version>
    </dependency>
    
    List<String> reversedList = Lists.reverse(list);
    

    然后我们遍历reversedList,就是逆向输出。

  5. 数据库的表设置自增、那么我们如果利用Java的时候,那么我们只需要对sql语句进行整改就好

        <insert id="addArticle" parameterType="String">
            insert into article(title,text,date) values(#{title},#{text},#{date})
        </insert>
    
  6. 在主键自增的数据库语句中,我们如果想对这个表进行新增。那么接口我们只需要写除了自增字段意外的字段即可。在Sql语句中,我们的参数类型是这个表对应的类。

        //添加五好村民
        public int addHero(String name,String groups,String date);
    
        <insert id="addHero" parameterType="com.jsxs.pojo.hero">
            insert into hero(name,groups,date) values(#{name},#{groups},#{date})
    
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_69683957/article/details/129322597

智能推荐

稀疏编码的数学基础与理论分析-程序员宅基地

文章浏览阅读290次,点赞8次,收藏10次。1.背景介绍稀疏编码是一种用于处理稀疏数据的编码技术,其主要应用于信息传输、存储和处理等领域。稀疏数据是指数据中大部分元素为零或近似于零的数据,例如文本、图像、音频、视频等。稀疏编码的核心思想是将稀疏数据表示为非零元素和它们对应的位置信息,从而减少存储空间和计算复杂度。稀疏编码的研究起源于1990年代,随着大数据时代的到来,稀疏编码技术的应用范围和影响力不断扩大。目前,稀疏编码已经成为计算...

EasyGBS国标流媒体服务器GB28181国标方案安装使用文档-程序员宅基地

文章浏览阅读217次。EasyGBS - GB28181 国标方案安装使用文档下载安装包下载,正式使用需商业授权, 功能一致在线演示在线API架构图EasySIPCMSSIP 中心信令服务, 单节点, 自带一个 Redis Server, 随 EasySIPCMS 自启动, 不需要手动运行EasySIPSMSSIP 流媒体服务, 根..._easygbs-windows-2.6.0-23042316使用文档

【Web】记录巅峰极客2023 BabyURL题目复现——Jackson原生链_原生jackson 反序列化链子-程序员宅基地

文章浏览阅读1.2k次,点赞27次,收藏7次。2023巅峰极客 BabyURL之前AliyunCTF Bypassit I这题考查了这样一条链子:其实就是Jackson的原生反序列化利用今天复现的这题也是大同小异,一起来整一下。_原生jackson 反序列化链子

一文搞懂SpringCloud,详解干货,做好笔记_spring cloud-程序员宅基地

文章浏览阅读734次,点赞9次,收藏7次。微服务架构简单的说就是将单体应用进一步拆分,拆分成更小的服务,每个服务都是一个可以独立运行的项目。这么多小服务,如何管理他们?(服务治理 注册中心[服务注册 发现 剔除])这么多小服务,他们之间如何通讯?这么多小服务,客户端怎么访问他们?(网关)这么多小服务,一旦出现问题了,应该如何自处理?(容错)这么多小服务,一旦出现问题了,应该如何排错?(链路追踪)对于上面的问题,是任何一个微服务设计者都不能绕过去的,因此大部分的微服务产品都针对每一个问题提供了相应的组件来解决它们。_spring cloud

Js实现图片点击切换与轮播-程序员宅基地

文章浏览阅读5.9k次,点赞6次,收藏20次。Js实现图片点击切换与轮播图片点击切换<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> <script type="text/ja..._点击图片进行轮播图切换

tensorflow-gpu版本安装教程(过程详细)_tensorflow gpu版本安装-程序员宅基地

文章浏览阅读10w+次,点赞245次,收藏1.5k次。在开始安装前,如果你的电脑装过tensorflow,请先把他们卸载干净,包括依赖的包(tensorflow-estimator、tensorboard、tensorflow、keras-applications、keras-preprocessing),不然后续安装了tensorflow-gpu可能会出现找不到cuda的问题。cuda、cudnn。..._tensorflow gpu版本安装

随便推点

物联网时代 权限滥用漏洞的攻击及防御-程序员宅基地

文章浏览阅读243次。0x00 简介权限滥用漏洞一般归类于逻辑问题,是指服务端功能开放过多或权限限制不严格,导致攻击者可以通过直接或间接调用的方式达到攻击效果。随着物联网时代的到来,这种漏洞已经屡见不鲜,各种漏洞组合利用也是千奇百怪、五花八门,这里总结漏洞是为了更好地应对和预防,如有不妥之处还请业内人士多多指教。0x01 背景2014年4月,在比特币飞涨的时代某网站曾经..._使用物联网漏洞的使用者

Visual Odometry and Depth Calculation--Epipolar Geometry--Direct Method--PnP_normalized plane coordinates-程序员宅基地

文章浏览阅读786次。A. Epipolar geometry and triangulationThe epipolar geometry mainly adopts the feature point method, such as SIFT, SURF and ORB, etc. to obtain the feature points corresponding to two frames of images. As shown in Figure 1, let the first image be ​ and th_normalized plane coordinates

开放信息抽取(OIE)系统(三)-- 第二代开放信息抽取系统(人工规则, rule-based, 先抽取关系)_语义角色增强的关系抽取-程序员宅基地

文章浏览阅读708次,点赞2次,收藏3次。开放信息抽取(OIE)系统(三)-- 第二代开放信息抽取系统(人工规则, rule-based, 先关系再实体)一.第二代开放信息抽取系统背景​ 第一代开放信息抽取系统(Open Information Extraction, OIE, learning-based, 自学习, 先抽取实体)通常抽取大量冗余信息,为了消除这些冗余信息,诞生了第二代开放信息抽取系统。二.第二代开放信息抽取系统历史第二代开放信息抽取系统着眼于解决第一代系统的三大问题: 大量非信息性提取(即省略关键信息的提取)、_语义角色增强的关系抽取

10个顶尖响应式HTML5网页_html欢迎页面-程序员宅基地

文章浏览阅读1.1w次,点赞6次,收藏51次。快速完成网页设计,10个顶尖响应式HTML5网页模板助你一臂之力为了寻找一个优质的网页模板,网页设计师和开发者往往可能会花上大半天的时间。不过幸运的是,现在的网页设计师和开发人员已经开始共享HTML5,Bootstrap和CSS3中的免费网页模板资源。鉴于网站模板的灵活性和强大的功能,现在广大设计师和开发者对html5网站的实际需求日益增长。为了造福大众,Mockplus的小伙伴整理了2018年最..._html欢迎页面

计算机二级 考试科目,2018全国计算机等级考试调整,一、二级都增加了考试科目...-程序员宅基地

文章浏览阅读282次。原标题:2018全国计算机等级考试调整,一、二级都增加了考试科目全国计算机等级考试将于9月15-17日举行。在备考的最后冲刺阶段,小编为大家整理了今年新公布的全国计算机等级考试调整方案,希望对备考的小伙伴有所帮助,快随小编往下看吧!从2018年3月开始,全国计算机等级考试实施2018版考试大纲,并按新体系开考各个考试级别。具体调整内容如下:一、考试级别及科目1.一级新增“网络安全素质教育”科目(代..._计算机二级增报科目什么意思

conan简单使用_apt install conan-程序员宅基地

文章浏览阅读240次。conan简单使用。_apt install conan