当前位置:   article > 正文

uni-app 前后端调用实例 基于Springboot_uniapp后端

uniapp后端

锋哥原创的uni-app视频教程:

2023版uniapp从入门到上天视频教程(Java后端无废话版),火爆更新中..._哔哩哔哩_bilibili2023版uniapp从入门到上天视频教程(Java后端无废话版),火爆更新中...共计23条视频,包括:第1讲 uni-app简介、第2讲 uni-app环境搭建、第3讲 uni-app之HelloWorld实现等,UP主更多精彩视频,请关注UP账号。icon-default.png?t=N7T8https://www.bilibili.com/video/BV1eG411N71c/

SpringBoot后端实例搭建

新建数据库db_uni

打开idea 新建项目uni-pro1

pom.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <parent>
  6. <groupId>org.springframework.boot</groupId>
  7. <artifactId>spring-boot-starter-parent</artifactId>
  8. <version>2.3.2.RELEASE</version>
  9. <relativePath/> <!-- lookup parent from repository -->
  10. </parent>
  11. <groupId>com.java1234</groupId>
  12. <artifactId>uni-pro1</artifactId>
  13. <version>0.0.1-SNAPSHOT</version>
  14. <name>uni-pro1</name>
  15. <description>uni-pro1</description>
  16. <properties>
  17. <java.version>1.8</java.version>
  18. </properties>
  19. <dependencies>
  20. <dependency>
  21. <groupId>org.springframework.boot</groupId>
  22. <artifactId>spring-boot-starter-web</artifactId>
  23. </dependency>
  24. <dependency>
  25. <groupId>mysql</groupId>
  26. <artifactId>mysql-connector-java</artifactId>
  27. <scope>runtime</scope>
  28. </dependency>
  29. <!-- 连接池 -->
  30. <dependency>
  31. <groupId>com.alibaba</groupId>
  32. <artifactId>druid</artifactId>
  33. <version>1.1.10</version>
  34. </dependency>
  35. <!-- mybatis-plus -->
  36. <dependency>
  37. <groupId>com.baomidou</groupId>
  38. <artifactId>mybatis-plus-boot-starter</artifactId>
  39. <version>3.3.2</version>
  40. </dependency>
  41. <dependency>
  42. <groupId>com.baomidou</groupId>
  43. <artifactId>mybatis-plus-boot-starter</artifactId>
  44. <version>3.3.2</version>
  45. </dependency>
  46. <dependency>
  47. <groupId>org.projectlombok</groupId>
  48. <artifactId>lombok</artifactId>
  49. <optional>true</optional>
  50. </dependency>
  51. </dependencies>
  52. <build>
  53. <plugins>
  54. <plugin>
  55. <groupId>org.springframework.boot</groupId>
  56. <artifactId>spring-boot-maven-plugin</artifactId>
  57. <version>2.3.2.RELEASE</version>
  58. </plugin>
  59. </plugins>
  60. </build>
  61. </project>

application.yml

  1. server:
  2. port: 80
  3. servlet:
  4. context-path: /
  5. spring:
  6. datasource:
  7. type: com.alibaba.druid.pool.DruidDataSource
  8. driver-class-name: com.mysql.cj.jdbc.Driver
  9. url: jdbc:mysql://localhost:3306/db_uni?serverTimezone=Asia/Shanghai
  10. username: root
  11. password: 123456
  12. mybatis-plus:
  13. global-config:
  14. db-config:
  15. id-type: auto
  16. configuration:
  17. map-underscore-to-camel-case: true
  18. auto-mapping-behavior: full
  19. log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  20. mapper-locations: classpath:mapper/*.xml

目录结构:

启动类 UniPro1Application 加下 扫描注解:

@MapperScan("com.java1234.mapper")

新建NewsController类

  1. /**
  2. * 新闻Controller控制器
  3. * @author java1234_小锋 (公众号:java1234)
  4. * @site www.java1234.vip
  5. * @company 南通小锋网络科技有限公司
  6. */
  7. @RestController
  8. @RequestMapping("/news")
  9. public class NewsController {
  10. @Autowired
  11. private NewsService newsService;
  12. /**
  13. * 测试
  14. * @return
  15. */
  16. @GetMapping("/test")
  17. public R test(){
  18. return R.ok("测试");
  19. }
  20. }

测试:http://localhost/news/test

uni-app前端实例搭建

新建uni-app项目 java1234Pro2

新建两个页面

pages.json

  1. {
  2. "pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
  3. {
  4. "path": "pages/list/list",
  5. "style": {
  6. "navigationBarTitleText": "列表页",
  7. "enablePullDownRefresh": true
  8. }
  9. },
  10. {
  11. "path": "pages/detail/detail",
  12. "style": {
  13. "navigationBarTitleText": "详情页"
  14. }
  15. },
  16. {
  17. "path": "pages/index/index",
  18. "style": {
  19. "navigationBarTitleText": "uni-app"
  20. }
  21. }
  22. ],
  23. "globalStyle": {
  24. "navigationBarTextStyle": "black",
  25. "navigationBarTitleText": "uni-app",
  26. "navigationBarBackgroundColor": "#F8F8F8",
  27. "backgroundColor": "#F8F8F8"
  28. },
  29. "uniIdRouter": {}
  30. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Li_阴宅/article/detail/861137
推荐阅读
相关标签
  

闽ICP备14008679号