当前位置: 首页 > wzjs >正文

公司做网站要多少钱如何让人帮忙做网站

公司做网站要多少钱,如何让人帮忙做网站,太仓市质监站网址,聚震网站开发以下是一个完整的 Spring Boot Thymeleaf 整合示例&#xff0c;包含项目结构、代码和运行说明&#xff1a; 1. 项目依赖配置&#xff08;Maven&#xff09; 在 pom.xml 中添加 Thymeleaf 依赖&#xff1a; <dependencies><!-- Spring Boot Web Starter --><d…

以下是一个完整的 Spring Boot + Thymeleaf 整合示例,包含项目结构、代码和运行说明:


1. 项目依赖配置(Maven)

pom.xml 中添加 Thymeleaf 依赖:

<dependencies><!-- Spring Boot Web Starter --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- Thymeleaf Starter --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency><!-- Spring Boot DevTools (可选,用于热更新) --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope></dependency>
</dependencies>

2. 项目结构

src/
├── main/
│   ├── java/
│   │   └── com.example.demo/
│   │       ├── DemoApplication.java      // 启动类
│   │       └── controller/               // 控制器包
│   │           └── HelloController.java  // 示例控制器
│   └── resources/
│       ├── static/                       // 静态资源(CSS/JS)
│       ├── templates/                    // Thymeleaf 模板文件
│       │   └── hello.html               // 示例模板
│       └── application.properties        // 配置文件(可选)
└── test/└── ...                               // 测试代码

3. 启动类(DemoApplication.java)

package com.example.demo;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class DemoApplication {public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);}
}

4. 控制器(HelloController.java)

package com.example.demo.controller;import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;@Controller
public class HelloController {@GetMapping("/hello")public String hello(Model model) {// 向模板传递数据model.addAttribute("name", "Thymeleaf");model.addAttribute("users", new String[]{"Alice", "Bob", "Charlie"});return "hello"; // 对应 templates/hello.html}
}

5. Thymeleaf 模板(hello.html)

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head><title>Thymeleaf Example</title>
</head>
<body><h1 th:text="'Hello, ' + ${name} + '!'">Default Text</h1><!-- 条件判断 --><p th:if="${users.size() > 0}">Users list:</p><ul><!-- 遍历用户列表 --><li th:each="user : ${users}" th:text="${user}"></li></ul><!-- 表单示例 --><form action="#" th:action="@{/submit}" method="post"><input type="text" th:field="*{username}" placeholder="Enter name"><button type="submit">Submit</button></form>
</body>
</html>

6. 配置(application.properties 可选)

# Thymeleaf 配置(可选,默认配置已足够)
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.cache=false # 开发时关闭缓存

7. 运行与验证

  1. 启动应用:运行 DemoApplicationmain 方法。
  2. 访问 http://localhost:8080/hello,页面显示:
    • 标题:Hello, Thymeleaf!
    • 用户列表:Alice, Bob, Charlie
    • 表单输入框

关键点总结

功能实现方式
模板路径src/main/resources/templates/ 目录下的 HTML 文件,后缀为 .html.xhtml
数据绑定通过 Model 对象传递数据到模板,使用 ${variable} 语法引用变量
条件渲染th:if, th:unless 控制元素显示
循环遍历th:each 遍历集合数据
表单绑定th:field 自动绑定表单字段到后端对象

扩展示例:带表单提交的控制器

@Controller
public class FormController {@GetMapping("/form")public String showForm(Model model) {model.addAttribute("user", new User()); // 表单对象return "form";}@PostMapping("/submit")public String submitForm(@ModelAttribute User user) {// 处理提交数据return "redirect:/success";}
}

对应的表单模板 form.html

<form th:object="${user}" action="#" th:action="@{/submit}" method="post"><input type="text" th:field="*{name}" placeholder="Name"><input type="email" th:field="*{email}" placeholder="Email"><button type="submit">Submit</button>
</form>

文章转载自:

http://YfjPYYwi.hqscg.cn
http://gO4Sv1tD.hqscg.cn
http://o3hXfyCR.hqscg.cn
http://ilF76waw.hqscg.cn
http://l4XQuMxT.hqscg.cn
http://Xxd7isbf.hqscg.cn
http://YxIiaHIe.hqscg.cn
http://5Lla0Pd7.hqscg.cn
http://aDZH0GiB.hqscg.cn
http://BJreMhCj.hqscg.cn
http://34OaLLSz.hqscg.cn
http://2ILNuMCo.hqscg.cn
http://GXuV2aiV.hqscg.cn
http://crz0wOvr.hqscg.cn
http://NTJ4ppkb.hqscg.cn
http://5oBuWoR2.hqscg.cn
http://axQd2nAx.hqscg.cn
http://dSdjV50j.hqscg.cn
http://tcOXSWjS.hqscg.cn
http://hJEYpgUe.hqscg.cn
http://m1Nl2IBG.hqscg.cn
http://dxED8WtM.hqscg.cn
http://nkWfHMlZ.hqscg.cn
http://euHgThEP.hqscg.cn
http://NpdrerjQ.hqscg.cn
http://iUHL0a6G.hqscg.cn
http://x3Q6uelw.hqscg.cn
http://ajkWRA5x.hqscg.cn
http://8MNy8oKD.hqscg.cn
http://jdpJ3Uax.hqscg.cn
http://www.dtcms.com/wzjs/636163.html

相关文章:

  • 福建省建设信息网站咖啡网站模板
  • 全国知名网站主题网站设计
  • 荣耀手机商城官方网站登录入口网络编程基础知识
  • 河西网站建设开发国建设银行e路通网站申
  • 创建学校网站吗商标注册查询网官网
  • 2017民非单位年检那个网站做档案网站的建设
  • 网站个人中心wordpress石家庄百度推广家庄网站建设
  • 家教网站如何建设子商务网站建设的一般流程图
  • 深圳网站设计 商城wordpress域名邮箱
  • 建设家具网站的目的及功能定位天津营销网站建设联系方式
  • 厦门网站建设制作wordpress翻页图片效果
  • 网站建设资质要求网站建设公司网站建设公司
  • 建设银行怎么加入信用网站网站创建需要多少钱
  • 建立网站的注意事项无锡网站建设 首选无锡立威云商
  • 网站建设方案怎样写wordpress 存储
  • 网站ps照片怎么做优秀电商网站设计
  • 深圳市罗湖建设局网站洛阳做网站公司
  • 石化建设分会网站百度如何添加店铺位置信息
  • 长春网站架设企业网站建设的目的论文
  • 启蒙自助建站邢台做移动网站的地方
  • 网站欢迎屏怎么做怎样套用wordpress模板
  • 网站建设公司专业公司如何做网站seo排名优化
  • 网站系统jsp模板推广赚钱软件排行
  • 个人可以做的外贸网站wordpress默认摘要
  • 江苏省中医院网站建设全球十大搜索引擎排名
  • 蓝海网站建设南昌整站优化
  • 自己做的网站怎么放上网官方网站举例
  • 企业网站手机端和pc端一个后台吗芜湖的公司
  • 射洪做网站微信音乐做mp3下载网站
  • 高端企业站wordpress添加附件下载