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

企业官网建站步骤做网站为什么要服务器

企业官网建站步骤,做网站为什么要服务器,网络广告推广实施计划,百度指数数据来源1、前言 前面介绍了Spring boot快速集成Spring AI实现简单的Chat聊天模式。今天立马来实战一番,通过Trae这个火爆全网的工具,来写一个微信小程序。照理说,我们只是极少量的编码应该就可以完成这项工作。开撸~ 2、需求描述 微信小程序实现一…

1、前言

前面介绍了Spring boot快速集成Spring AI实现简单的Chat聊天模式。今天立马来实战一番,通过Trae这个火爆全网的工具,来写一个微信小程序。照理说,我们只是极少量的编码应该就可以完成这项工作。开撸~

2、需求描述

微信小程序实现一个页面,页面上输入一个姓名,点击生成就可以生成对应的藏头诗,并可以根据指定的风格生成。手绘了下页面整体布局:

3、环境准备

  • IntelliJ IDEA 2024.3
  • 微信开发工具
  • 硅基流动API,这里需要提前注册申请
  • Trae AI

4、快速开始

4.1、后端服务(Spring Boot + Spring AI)

由于我这里有线程的后端框架,因此我这里就不使用Trae来帮我生成了。

4.1.1、搭建Spring Boot工程

新建一个项目,添加Spring boot相关依赖,这里我就不赘述了。直接贴出pom.xml:

<?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>3.4.2</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>top.shamee</groupId><artifactId>chai-said-cloud</artifactId><version>0.0.1-SNAPSHOT</version><packaging>pom</packaging><properties><java.version>21</java.version></properties><dependencies><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- Spring Boot DevTools (Optional for auto-reloading during development) --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope></dependency><dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId></dependency><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><exclusions><exclusion><artifactId>mybatis-spring</artifactId><groupId>org.mybatis</groupId></exclusion></exclusions></dependency><dependency><groupId>org.mybatis</groupId><artifactId>mybatis-spring</artifactId><version>3.0.3</version></dependency><dependency><groupId>com.baomidou</groupId><artifactId>dynamic-datasource-spring-boot-starter</artifactId></dependency><dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.36</version></dependency><dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId><version>8.0.33</version></dependency><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.5</version></dependency><dependency><groupId>com.baomidou</groupId><artifactId>dynamic-datasource-spring-boot-starter</artifactId><version>3.6.1</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId><version>1.2.11</version></dependency></dependencies></dependencyManagement><build><resources><resource><directory>src/main/java</directory><includes><include>**/*.xml</include></includes><filtering>true</filtering></resource><resource><directory>src/main/resources</directory><includes><include>**/*.properties</include><include>**/*.xml</include><include>**/*.yml</include></includes><filtering>false</filtering></resource></resources><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><mainClass>top.shamee.chailauncher.ChaiLauncherApplication</mainClass>     <!-- 取消查找本项目下的Main方法:为了解决Unable to find main class的问题 --><classifier>execute</classifier>    <!-- 为了解决依赖模块找不到此模块中的类或属性 --></configuration><executions><execution><goals><goal>repackage</goal><goal>build-info</goal></goals></execution></executions></plugin></plugins></build></project>

因为我这里集成了MySQL,以及做了多模块。因此我这里的pom稍微复杂了一些,大家可以按需裁剪。

4.1.2、集成Spring AI

注意这里Spring Boot版本必须选用3.2以上的版本,这里使用3.4.2,同时使用JDK21。这里添加Spring AI相关依赖:

<dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-openai-spring-boot-starter</artifactId>
</dependency><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-spring-boot-autoconfigure</artifactId>
</dependency><dependencyManagement><dependencies><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-bom</artifactId><version>1.0.0-SNAPSHOT</version><type>pom</type><scope>import</scope></dependency></dependencies>
</dependencyManagement>

4.1.3、添加启动类

@Slf4j
//@MapperScan("top.shamee")
@SpringBootApplication(scanBasePackages = {"top.shamee"})
public class ChaiLauncherApplication {public static void main(String[] args) {ConfigurableApplicationContext context = SpringApplication.run(ChaiLauncherApplication.class);ConfigurableEnvironment environment = context.getEnvironment();log.info("""---------------------------------------------------------- 应用 '{}' 运行成功! 当前环境 '{}' !!! 端口 '[{}]' !!!----------------------------------------------------------""",environment.getProperty("spring.application.name"),environment.getActiveProfiles(),environment.getProperty("server.port"));}}

到此,项目基本搭建完毕。

4.1.4、编写Spring AI相关接口

由于这里要实现的是一个输入用户姓名,通过OpenAI接口生成藏头诗的功能。因此接口入口参数为:inputName(姓名)和inputStype(生成风格),返回生成的内容。

首先定义参数input:

@Data
public class GenPoemInput implements Serializable {private String inputName;private String inputStyle;public String getPrompt(){return "用“" + getInputName() + "”写一首藏头诗,要求风格" + getInputStyle() + ",诗词为七言诗";}
}

接着编写controller类:

@Slf4j
@RestController
@RequestMapping("/chai/gen-record")
public class GenRecordController {private final ChatClient chatClient;public GenRecordController(ChatClient.Builder chatClientBuilder) {this.chatClient = chatClientBuilder.build();}@Resourceprivate GenRecordService genRecordService;@PostMapping("/openai")ResponseEntity<String> openai(@RequestBody GenPoemInput genPoemInput) {log.info("请求参数: {}", genPoemInput);String result = this.chatClient.prompt(new Prompt()).user(genPoemInput.getPrompt()).call().content();return ResponseEntity.ok(result);}
}

application.properties需要配置我们的OpenAi相关API KEY:

配置属性:

  • spring.ai.openai.chat.options.model为配置的大模型
  • spring.ai.openai.chat.base-url为大模型的请求url,默认为openai.com
  • spring.ai.openai.chat.api-key为大模型对应的api key

最后启动工程类,请求下接口看下是否正常:

curl -i -X POST \-H "Content-Type:application/json" \-d \
'{"inputName":"秦始皇","inputStype": "幽默"
}' \'http://localhost:8080/chai/gen-record/openai'

生成内容,成功:

4.2、前端开发(微信小程序 + Trae)

小程序代码,这里我们使用Trae来实现。我们给Trae一个提示词:

  1. 你是一个经验丰富的微信小程序UI工程师,熟悉微信的UI设计,设计风格简约明朗
  2. 你将负责设计微信小程序的UI
  3. 我会给你一个设计图,你需要解析这个图片,并设计生成一个小程序,实现这个页面功能。

并将我们手绘的prd传给他:

接着就是静静的等待了:

很快他就生成好了我们所需要的代码,点击全部接受,调整到我们的代码结构中。生成的代码结构还是符合微信小程序的代码结构的:

直接打开微信开发工具,就可以直接预览到我们的页面。剩下的就是中间不断地让Trae按照我们地要求进行细化地调整。最终的效果:

4.3、程序部署

前后端代码都就绪后,接下来就是部署了。由于小程序需要https请求,且域名需要经过严格的ICP备案,才可以正常使用。这里消耗了些时间,SSL都可以免费搞定,ICP备案比较耗时,需要走流程。
当然我们开发本地可以不校验https域名,可以在开发工具上先体验:

试下效果看看:

效果还是很不错,样式,JS代码都帮直接帮我们搞定。真的很香!!!

5、总结

到此,基本程序编码时间不到1小时就可以完全搞定,主要耗费时间的就是在不断的AI调整上。当然可能前面给的提示词比较粗糙也有关系,大家可以认真的给到一段提示信息,应该就不需要花过多时间去调整细化。
代码我还未上传到Github,大家有需要可以私聊我,或者等我有空我上传到Github:https://github.com/Shamee99
真正经验的是,我只是简单手绘了一个PRD草稿,Trae就可以代替我写出相关代码,而且还原度接近90%。大家细品~


文章转载自:

http://npTFXWwd.rqnhf.cn
http://BGkslMxv.rqnhf.cn
http://rJ1xL6Ij.rqnhf.cn
http://hIu07CMb.rqnhf.cn
http://wkVXSgvE.rqnhf.cn
http://W4zI2yOp.rqnhf.cn
http://xfJ0mprB.rqnhf.cn
http://LZlijEK8.rqnhf.cn
http://3yxIrfuq.rqnhf.cn
http://l4cvijLt.rqnhf.cn
http://vHDpypTq.rqnhf.cn
http://dGRroINT.rqnhf.cn
http://ZdbxOff5.rqnhf.cn
http://GbcIhrmm.rqnhf.cn
http://d8V0fQz7.rqnhf.cn
http://oaaiUSzr.rqnhf.cn
http://ENJOEi1z.rqnhf.cn
http://n0GcWIhK.rqnhf.cn
http://SRyza1IG.rqnhf.cn
http://Pj0molc6.rqnhf.cn
http://9t3T4u3v.rqnhf.cn
http://i1byd1Kr.rqnhf.cn
http://IozAvwNe.rqnhf.cn
http://il1qunxH.rqnhf.cn
http://cgoh1atw.rqnhf.cn
http://HK2K11me.rqnhf.cn
http://E5MKCNGI.rqnhf.cn
http://MU5bkzIk.rqnhf.cn
http://D7UBTzH3.rqnhf.cn
http://gYX8PbmO.rqnhf.cn
http://www.dtcms.com/wzjs/737861.html

相关文章:

  • 亚马逊做超链接的网站怎么写网站建设的说明
  • 电子商务网站的建设流程是怎样的ASP.NET与网站开发编程实战
  • 青岛西海岸新区城市建设局网站页面设计时最好只使用一种颜色避免视觉效果混响
  • 专业网站优化方案教师遭网课入侵直播录屏曝光口
  • 网站渠道建设180天做180个网站
  • 在国税网站怎么做实名大连手机自适应网站建设公司
  • 网站内部优化策略网站怎么自己做服务器
  • 湛江模板做网站域名建设网站
  • wordpress 4.3.4下载网站优化流程
  • 嘉兴做网站的公司免费网络连接软件
  • 项目宣传网站模板wordpress 去除 栏头
  • 做网站设计师的原因快速网站建设费用
  • 开源网站开发文档下载seo是什么职业岗位
  • 广西南宁官方网站企业网页生成器
  • 网站不被收录的原因网站备案信息是什么意思
  • 怎么自己做淘宝客网站免费最好网站建设
  • 企业网站开发有哪些做外单网站有哪些内容
  • 中国电信网站备案管理系统工程建设范围
  • 红酒网站制作江苏省建设档案网站
  • 网站怎么运营推广企业为什么要建立集团
  • 小游戏网站模板品牌手表网站
  • 怎么快速做网站广西城乡和住房建设厅网站首页
  • 网站开发需求表建设银行论坛网站
  • 出格做网站怎么样广州天河建网站的公司
  • 学点啥网站桂林微信网站
  • 广东移动网站网站赚取广告费
  • 江西省住房与城乡建设厅网站潍坊尚呈网站建设公司
  • 东莞专业网站建设推广seo服务合同
  • 免费建立个人网站凡科工商注册网站
  • 浙江大数据网站建设问答知识美容院网站源码