JeecgBoot配置及前后端分离HelloWorld项目

JeecgBoot 专栏收录该内容
18 篇文章 1 订阅

1、Maven私服配置

JEECG存在自定义JAR包,放在自己的Maven私服上面,所以有的时候会遇到下载失败。一般遇到下载失败的情况,是因为用户设置了本地镜像,导致无法从JEECG私服下载资源,参考下面的方式进行镜像排除配置即可。
找到 maven安装目录中 conf/settings.xml,在标签内增加下面方式的阿里云maven镜像(删除自己的镜像配置), 最终结果见下面:

<mirrors>
       <mirror>
            <id>nexus-aliyun</id>
            <mirrorOf>*,!jeecg,!jeecg-snapshots,!getui-nexus</mirrorOf>
            <name>Nexus aliyun</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public</url>
        </mirror> 
 </mirrors>

然后执行maven命令,依赖就会顺利下载;此配置重点在这句话:

<mirrorOf>*,!jeecg,!jeecg-snapshots</mirrorOf>

如果不加这句话,默认所有的依赖都会去阿里云仓库下载,加上后jeecg的依赖包就可以从jeecg私服下载了。这里!的意思是排除,就是对所有仓库做镜像,除了jeecg仓库和jeecg-snapshots仓库,这两个仓库在下面的pom.xml文件中配置。
jeecg-boot-parent中的pom.xml设置:

<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.jeecgframework.boot</groupId>
  <artifactId>jeecg-boot-parent</artifactId>
  <version>2.2.1</version>
  <packaging>pom</packaging>
  
  	<parent>
	    <groupId>org.springframework.boot</groupId>
	    <artifactId>spring-boot-starter-parent</artifactId>
	    <version>2.1.3.RELEASE</version>
	    <relativePath/>
	</parent>

	<modules>
		<module>jeecg-boot-base-common</module>
		<module>jeecg-boot-module-system</module>
		<module>jeecg-boot-module-activiti</module>
	</modules>

	<distributionManagement>
	  	<repository>
            <id>jeecg</id>
            <name>jeecg Repository</name>
            <url>http://maven.jeecg.com:8090/nexus/content/repositories/jeecg</url>
        </repository>
        <snapshotRepository>
	        <id>jeecg-snapshots</id>
            <name>jeecg Snapshot Repository</name>
            <url>http://maven.jeecg.com:8090/nexus/content/repositories/snapshots/</url>
	    </snapshotRepository>
	</distributionManagement>
	
	<repositories>
		<repository>
            <id>aliyun</id>
            <name>aliyun Repository</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public</url>
            <snapshots>
				<enabled>false</enabled>
			</snapshots>
        </repository>
		<repository>
            <id>jeecg</id>
            <name>jeecg Repository</name>
            <url>http://maven.jeecg.org/nexus/content/repositories/jeecg</url>
            <snapshots>
				<enabled>false</enabled>
			</snapshots>
        </repository>
	</repositories>
	
    <properties>
        <jeecgboot.version>2.2.1</jeecgboot.version>
        <java.version>1.8</java.version>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <mybatis-plus.version>3.3.2</mybatis-plus.version>
        <druid.version>1.1.17</druid.version>
        <jwt.version>0.9.1</jwt.version>
        <commons.version>2.6</commons.version>
		<aliyun-java-sdk-dysmsapi.version>1.0.0</aliyun-java-sdk-dysmsapi.version>
		<aliyun.oss.version>3.6.0</aliyun.oss.version>
		<guava.version>26.0-jre</guava.version>
    </properties>
    
	<dependencies>
		<!--集成springmvc框架并实现自动配置 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<!-- websocket -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-websocket</artifactId>
		</dependency>
		<dependency>
    		<groupId>org.springframework.boot</groupId>
    		<artifactId>spring-boot-starter-mail</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-aop</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
	    <!-- <dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
			<optional>true</optional>
		</dependency> -->
		
		<!-- commons -->
		<dependency>
			<groupId>commons-io</groupId>
			<artifactId>commons-io</artifactId>
			<version>${commons.version}</version>
		</dependency>
		<dependency>
			<groupId>commons-lang</groupId>
			<artifactId>commons-lang</artifactId>
			<version>${commons.version}</version>
		</dependency>

		<!-- freemarker -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-freemarker</artifactId>
		</dependency>
		
		<!-- Lombok -->
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
		</dependency>
		
		<!-- mybatis-plus -->
		 <dependency>
	        <groupId>com.baomidou</groupId>
	        <artifactId>mybatis-plus-boot-starter</artifactId>
	        <version>${mybatis-plus.version}</version>
	    </dependency>
		
		<!-- druid -->
       <dependency>
		   <groupId>com.alibaba</groupId>
		   <artifactId>druid-spring-boot-starter</artifactId>
		   <version>${druid.version}</version>
		</dependency>
		
		<!-- 动态数据源 -->
		<dependency>
		  <groupId>com.baomidou</groupId>
		  <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
		  <version>2.5.4</version>
		</dependency>
				
		<!-- json -->
		<dependency>
         	<groupId>com.alibaba</groupId>
         	<artifactId>fastjson</artifactId>
         	<version>1.2.72</version>
        </dependency>
      
		<!--mysql-->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>8.0.20</version>
			<scope>runtime</scope>
		</dependency>
		<!--  sqlserver-->
		<dependency>
		    <groupId>com.microsoft.sqlserver</groupId>
		    <artifactId>sqljdbc4</artifactId>
		    <version>4.0</version>
		    <scope>runtime</scope>
		</dependency>
		<!-- oracle驱动 -->
		<dependency>
		    <groupId>com.oracle</groupId>
		    <artifactId>ojdbc6</artifactId>
		    <version>11.2.0.3</version>
			<scope>runtime</scope>
		</dependency>
        <!-- postgresql驱动 -->
		<dependency>
			<groupId>org.postgresql</groupId>
			<artifactId>postgresql</artifactId>
			<version>42.2.6</version>
			<scope>runtime</scope>
		</dependency>

		 <!-- Quartz定时任务 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-quartz</artifactId>
        </dependency>
        
		<!--JWT-->
		<dependency>
			<groupId>com.auth0</groupId>
			<artifactId>java-jwt</artifactId>
			<version>3.7.0</version>
		</dependency>
		
		<!--shiro-->
		<dependency>
		    <groupId>org.apache.shiro</groupId>
		    <artifactId>shiro-spring-boot-starter</artifactId>
		    <version>1.4.0</version>
		</dependency>
		<!-- shiro-redis -->
        <dependency>
            <groupId>org.crazycake</groupId>
            <artifactId>shiro-redis</artifactId>
            <version>3.1.0</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.shiro</groupId>
                    <artifactId>shiro-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

		<!--  online form-->
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-re</artifactId>
			<version>2.2.1</version>
		</dependency>
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-core</artifactId>
			<exclusions>
				<exclusion>
					<groupId>commons-collections</groupId>
					<artifactId>commons-collections</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

		<!-- Swagger API文档 -->
        <dependency>
		    <groupId>io.springfox</groupId>
		    <artifactId>springfox-swagger2</artifactId>
		    <version>2.9.2</version>
			<exclusions>
				<exclusion>
					<groupId>io.swagger</groupId>
					<artifactId>swagger-annotations</artifactId>
				</exclusion>
				<exclusion>
					<groupId>io.swagger</groupId>
					<artifactId>swagger-models</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-swagger-ui</artifactId>
			<version>2.9.2</version>
		</dependency>
		<dependency>
			<groupId>com.github.xiaoymin</groupId>
			<artifactId>swagger-bootstrap-ui</artifactId>
			<version>1.9.6</version>
		</dependency>
		<!-- # 增加两个配置解决 NumberFormatException -->
		<dependency>
			<groupId>io.swagger</groupId>
			<artifactId>swagger-annotations</artifactId>
			<version>1.5.22</version>
		</dependency>
		<dependency>
			<groupId>io.swagger</groupId>
			<artifactId>swagger-models</artifactId>
			<version>1.5.22</version>
		</dependency>

		<!-- Redis -->
		<dependency>
			 <groupId>org.springframework.boot</groupId>
			  <artifactId>spring-boot-starter-data-redis</artifactId>
		</dependency>
		<dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-pool2</artifactId>
        </dependency>
        
		<!-- 代码生成器 -->
		<!-- 如下载失败,请参考此文档  http://doc.jeecg.com/1273965 -->
		<dependency>
			<groupId>org.jeecgframework.boot</groupId>
			<artifactId>codegenerate</artifactId>
			<version>1.2.0</version>
		</dependency>
		
        <!-- AutoPoi Excel工具类-->
		<dependency>
			<groupId>org.jeecgframework</groupId>
			<artifactId>autopoi-web</artifactId>
			<version>1.2</version>
			<exclusions>
				<exclusion>
					<groupId>commons-codec</groupId>
					<artifactId>commons-codec</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

		<dependency>
		    <groupId>cn.hutool</groupId>
		    <artifactId>hutool-all</artifactId>
		    <version>5.3.8</version>
		</dependency>

		<!-- mini文件存储服务 -->
		<dependency>
			<groupId>io.minio</groupId>
			<artifactId>minio</artifactId>
			<version>4.0.0</version>
		</dependency>
		<dependency>
			<groupId>com.google.guava</groupId>
			<artifactId>guava</artifactId>
			<version>${guava.version}</version>
		</dependency>

		<!-- 阿里云短信 -->
		<dependency>
			<groupId>com.aliyun</groupId>
			<artifactId>aliyun-java-sdk-dysmsapi</artifactId>
			<version>${aliyun-java-sdk-dysmsapi.version}</version>
		</dependency>
		<!-- aliyun oss -->
		<dependency>
			<groupId>com.aliyun.oss</groupId>
			<artifactId>aliyun-sdk-oss</artifactId>
			<version>${aliyun.oss.version}</version>
		</dependency>

		<!-- 第三方登录 -->
		<dependency>
			<groupId>com.xkcoding.justauth</groupId>
			<artifactId>justauth-spring-boot-starter</artifactId>
			<version>1.3.2</version>
		</dependency>

	</dependencies>

	<dependencyManagement>
		<dependencies>
			<!-- jeecg-boot-base-common -->
			<dependency>
	    		<groupId>org.jeecgframework.boot</groupId>
	    		<artifactId>jeecg-boot-base-common</artifactId>
	    		<version>${jeecgboot.version}</version>
	    	</dependency>
	    	<!-- 七牛云SDK -->
			<dependency>
				<groupId>com.qiniu</groupId>
				<artifactId>qiniu-java-sdk</artifactId>
				<version>7.2.23</version>
			</dependency>
		</dependencies>
	</dependencyManagement>
	<build>
		<plugins>
			<!--<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
			 指定JDK编译版本 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <!-- 打包跳过测试 -->
            <plugin>
		        <groupId>org.apache.maven.plugins</groupId>
		        <artifactId>maven-surefire-plugin</artifactId>
		        <configuration>
		          <skipTests>true</skipTests>
		        </configuration>
	        </plugin>
	         <!-- 避免font文件的二进制文件格式压缩破坏 -->
	         <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <nonFilteredFileExtensions>
                        <nonFilteredFileExtension>woff</nonFilteredFileExtension>
                        <nonFilteredFileExtension>woff2</nonFilteredFileExtension>
                        <nonFilteredFileExtension>eot</nonFilteredFileExtension>
                        <nonFilteredFileExtension>ttf</nonFilteredFileExtension>
                        <nonFilteredFileExtension>svg</nonFilteredFileExtension>
                    </nonFilteredFileExtensions>
                </configuration>
            </plugin>
		</plugins>
		<resources>
			<resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
			<resource>
				<directory>src/main/java</directory>
				<includes>
					<include>**/*.xml</include>
					<include>**/*.json</include>
					<include>**/*.ftl</include>
				</includes>
			</resource>
		</resources>
	</build>
</project>

2、数据库切换Oracle/SqlServer/Postgresql

Oracle数据

  1. 添加oracle驱动,修改pom.xml:
<!-- oracle驱动 -->
<dependency>
	<groupId>com.oracle</groupId>
	<artifactId>ojdbc6</artifactId>
	<version>11.2.0.3</version>
</dependency>
  1. 修改数据库连接
    修改druid配置:
validationQuery: SELECT 1 FROM DUAL

driver-class-name: oracle.jdbc.OracleDriver
url: jdbc:oracle:thin:@192.168.1.200:1521:ORCL
username: jeecgboot
password: jeecgboot

SQL Server数据

  1. 添加SQL server驱动,修改pom.xml:
<!--  sqlserver-->
<dependency>
	<groupId>com.microsoft.sqlserver</groupId>
	<artifactId>sqljdbc4</artifactId>
	<version>4.0</version>
	<scope>runtime</scope>
</dependency>
  1. 修改数据库连接
    修改druid配置:
validationQuery: SELECT 1
filters: stat,slf4j

driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
url: jdbc:sqlserver://192.168.1.200:1433;SelectMethod=cursor;DatabaseName=jeecg-boot
username: sa
password: SA

postgresql数据库

  1. 添加postgresql驱动,修改pom.xml
    (根据不同版本的数据库引入对应版本的驱动,下载地址:https://jdbc.postgresql.org/download.html)
<!--  postgresql-->
<dependency>
	<groupId>postgresql</groupId>
	<artifactId>postgresql</artifactId>
	<version>42.2.5</version>
</dependency>
  1. 修改数据库连接
    增加spring下的配置:
spring:
  #postgresql 报错问题
  jpa:
      properties:
          hibernate:
              temp:
                  use_jdbc_metadata_defaults: false

修改druid配置:

validationQuery: SELECT 1

url: jdbc:postgresql://localhost:5432/postgres
username: postgres
password: root
driver-class-name: org.postgresql.Driver

3、前端配置后台API地址

public/index.html页面配置后台服务API URL

src/utils/request.js 配置

此处默认不需要修改,配合下面操作的时候,可以手工指定后台项目名字。

vue.config.js配置

此处可以设置多个代理映射(如果要映射多个,则request.js需要手工指定项目名)

4、前后端分离HelloWorld项目

后台服务代码实现

@RestController
@RequestMapping("/test/jeecgDemo")
@Slf4j
public class JeecgDemoController {

	/**
	 * hello world
	 * 
	 * @param id
	 * @return
	 */
	@GetMapping(value = "/hello")
	public Result<String> hello() {
		Result<String> result = new Result<String>();
		result.setResult("Hello World!");
		result.setSuccess(true);
		return result;
	}
}

访问请求http://localhost:8080/jeecg-boot/test/jeecgDemo/hello 会提示token无效,所以需要配置下拦截器ShiroConfig排除。
配置文件:

 jeecg-boot-module-system/src/main/java/org/jeecg/config/ShiroConfig.java

加入配置:

filterChainDefinitionMap.put("/test/jeecgDemo/hello", "anon");

再访问http://localhost:8080/jeect-boot/test/jeecgDemo/hello,会返回结果如下:

{
	"success": true,
	"message": null,
	"code": null,
	"result": "Hello World!",
	"timestamp": 1548833208562
}

前台vue页面实现

创建vue页面src/views/jeecg/helloworld.vue
调用后台请求,获取返回的Hello World! 输出到页面,页面代码如下:

<template>
  <div>
    {{ msg }}
  </div>
</template>

<script>
  import {getAction} from '@/api/manage'
  export default {
    data () {
      return {
        msg: ""
      }
    },
    methods: {
      hello () {
        var url = "/test/jeecgDemo/hello"
        getAction(url).then((res) => {
          if (res.success) {
            this.msg = res.result;
          }
        })
      }
    },
    created() {
      this.hello();
    }
  }
</script>

代码说明:

  1. data() 方法中定义数据对象msg
  2. 数据对象msg输出到页面,表达式如下:
{{ msg }}
  1. 定义一个方法,发起请求获取后台响应,后台实现的是get方法,引入getAction方法
import {getAction} from '@/api/manage'

定义方法调用:

hello () {
   var url = "/test/jeecgDemo/hello"
   getAction(url).then((res) => {
     if (res.success) {
       this.msg = res.result;
     }
   })
 }
  1. Vue生命周期 created 中调用方法
created() {
  this.hello();
}

hello方法中

this.msg = res.result;

把请求返回的Hello World! 赋值给msg数据对象,msg值改变则页面显示也改变。

配置菜单

  1. 配置helloworld菜单【系统管理】-【菜单管理】
  • 其中前端组件配置相对src/views/目录下的 目录名+文件名
  • 例如页面src/views/jeecg/helloworld.vue 前端组件配置 jeecg/helloworld
  1. 用户角色授权【系统管理】-【角色管理】-授权


    点击菜单访问页面展示Hello World!
  • 1
    点赞
  • 1
    评论
  • 2
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

打赏
文章很值,打赏犒劳作者一下
相关推荐
<ul style="color:rgba(0,0,0,.560784);font-size:14px;background-color:#FFFFFF;"> <li> <span>Tensorflow2.0介绍:</span> </li> </ul> <p style="color:rgba(0,0,0,.560784);font-size:14px;background-color:#FFFFFF;"> tensorflow是GOOGLE在2015年底发布的一款深度学习框架,也是目前全世界用得最多,发展最好的深度学习框架。2019年3月8日,GOOGLE发布最新tensorflow2版本。新版本的tensorflow有很多新特征,更快更容易使用更人性化。但是老版的tensorflow程序在新版本中几乎都无法继续使用,所以我们有必要学习新版tensorflow2的新用法。 </p> <ul style="color:rgba(0,0,0,.560784);font-size:14px;background-color:#FFFFFF;"> <li> <span>课程介绍:</span> </li> </ul> <p style="color:rgba(0,0,0,.560784);font-size:14px;background-color:#FFFFFF;"> 我们的这门课程适合小白学习,也适合有基础的同学学习。课程会从0开始学习,从python环境安装,python入门,numpy,pandas,matplotlib使用,深度学习基础,一直讲到tensorflow基础,进阶,项目实战。不管你是0基础小白,想进入AI行业,还是有一定基础,想学习最新的tensorflow2的使用,都适合我们这门课程。 </p> <ul style="color:rgba(0,0,0,.560784);font-size:14px;background-color:#FFFFFF;"> <li> <span>讲师介绍:</span> </li> </ul> <p style="color:rgba(0,0,0,.560784);font-size:14px;background-color:#FFFFFF;"> 覃秉丰,物理系毕业转AI行业,想转行同学可以找我聊聊。机器学习、深度学习神经网络领域多年研究开发授课经验,精通算法原理与编程实践;曾完成过多项图像识别、目标识别、语音识别等企业项目,一线实战经验丰富;长期为多家包括世界五百强在内的大型企业总部做人工智能技术内训服务(中国移动、中国银行,华夏银行,中国太平洋,国家电网、中海油等)。上课特点:公式尽量一个一个符号推,代码尽量一行一行讲,希望所有人都能学有所得。 </p>
©️2020 CSDN 皮肤主题: 书香水墨 设计师:CSDN官方博客 返回首页

打赏

魏晓蕾

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值