徐州如何提高网站建设,删除wordpress站,网站的建设方法不包括什么,短网址还原网站学习springcloud时异常-java: 找不到符号 符号: 方法 getPname()
学习springcloud时#xff0c;遇到获取实体类属性值时出现异常。
项目目前分为两个子模块#xff0c;一个是实体类模块#xff0c;另一个是应用层。 在查询数据后#xff0c;打印pname属性时报错#xff…学习springcloud时异常-java: 找不到符号 符号: 方法 getPname()
学习springcloud时遇到获取实体类属性值时出现异常。
项目目前分为两个子模块一个是实体类模块另一个是应用层。 在查询数据后打印pname属性时报错代码排查一遍没有问题。
问题最后定位在pom.xml文件的打包方式。 实体类的子模块采用的打包方式是pom方式导致出现了问题修改为jar或war方式就正常了 源码
父项目
pom.xml
project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsdmodelVersion4.0.0/modelVersiongroupIdorg.example/groupIdartifactIdspringcloud2/artifactIdpackagingpom/packagingversion1.0-SNAPSHOT/versionmodulesmoduleproduct-domain/modulemoduleproduct-server/module/modulesnamespringcloud2 Maven Webapp/nameurlhttp://maven.apache.org/urlparentartifactIdspring-boot-starter-parent/artifactIdgroupIdorg.springframework.boot/groupIdversion2.3.2.RELEASE/version/parentpropertiesjava.version1.8/java.versionproject.build.sourceEncodingUTF-8/project.build.sourceEncodingproject.reporting.outputEncodingUTF-8/project.reporting.outputEncodingspring-cloud.versionHoxton.SR8/spring-cloud.versionspring-cloud-alibaba.version2.2.5.RELEASE/spring-cloud-alibaba.version/propertiesdependencyManagementdependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-dependencies/artifactIdversion${spring-cloud.version}/versionscopeimport/scopetypepom/type/dependencydependencygroupIdcom.alibaba.cloud/groupIdartifactIdspring-cloud-alibaba-dependencies/artifactIdversion${spring-cloud-alibaba.version}/versionscopeimport/scopetypepom/type/dependency/dependencies/dependencyManagementdependenciesdependencygroupIdjunit/groupIdartifactIdjunit/artifactIdversion3.8.1/versionscopetest/scope/dependency/dependenciesbuildfinalNamespringcloud2/finalName/build/project
实体类模块
pom.xml
project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsdparentartifactIdspringcloud2/artifactIdgroupIdorg.example/groupIdversion1.0-SNAPSHOT/version/parentmodelVersion4.0.0/modelVersionartifactIdproduct-domain/artifactIdpackagingjar/packagingnameproduct-domain Maven Webapp/nameurlhttp://maven.apache.org/urldependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-jpa/artifactId/dependencydependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactId/dependencydependencygroupIdjunit/groupIdartifactIdjunit/artifactIdversion3.8.1/versionscopetest/scope/dependency/dependenciesbuildfinalNameproduct-domain/finalName/build/project
package cn.wolfcode.domain.entity;import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;Data
Entity(name t_shop_product)
NoArgsConstructor
AllArgsConstructor
public class Product {IdGeneratedValue(strategy GenerationType.IDENTITY)private Long pid;private String pname;private Double pprice;private Integer stock;}
应用层模块
pom.xml
project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsdparentartifactIdspringcloud2/artifactIdgroupIdorg.example/groupIdversion1.0-SNAPSHOT/version/parentmodelVersion4.0.0/modelVersionartifactIdproduct-server/artifactIdpackagingjar/packagingnameproduct-server Maven Webapp/nameurlhttp://maven.apache.org/urldependenciesdependencygroupIdjunit/groupIdartifactIdjunit/artifactIdversion3.8.1/versionscopetest/scope/dependencydependencygroupIdmysql/groupIdartifactIdmysql-connector-java/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdcom.alibaba/groupIdartifactIdfastjson/artifactIdversion1.2.83/version/dependencydependencygroupIdorg.example/groupIdartifactIdproduct-domain/artifactIdversion1.0-SNAPSHOT/version/dependency/dependenciesbuildfinalNameproduct-server/finalName/build
/project
ProductController
package cn.wolfcode.domain.controller;import cn.wolfcode.domain.entity.Product;
import cn.wolfcode.domain.service.ProductService;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;RestController
Slf4j
public class ProductController {Autowiredprivate ProductService productService;RequestMapping(value /product/{pid},method RequestMethod.GET)public Product findByPid(PathVariable(pid) Long pid){log.info(接下来要进行{}号商品信息的查询,pid);Product product productService.findByPid(pid);System.out.println(product.getPname());log.info(商品信息查询成功内容为{}, JSON.toJSONString(product));return product;}}
ProductDao
package cn.wolfcode.domain.dao;import cn.wolfcode.domain.entity.Product;
import org.springframework.data.jpa.repository.JpaRepository;public interface ProductDao extends JpaRepositoryProduct,Long {
}
ProductService
package cn.wolfcode.domain.service;import cn.wolfcode.domain.entity.Product;public interface ProductService {Product findByPid(Long pid);
}
ProductServiceImpl
package cn.wolfcode.domain.service.impl;import cn.wolfcode.domain.dao.ProductDao;
import cn.wolfcode.domain.entity.Product;
import cn.wolfcode.domain.service.ProductService;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.util.Optional;Service
public class ProductServiceImpl implements ProductService {Autowiredprivate ProductDao productDao;Overridepublic Product findByPid(Long pid) {OptionalProduct byId productDao.findById(pid);Product product null;if (byId!null byId.isPresent()){System.out.println(pid);System.out.println(1111111111);product byId.get();System.out.println(JSON.toJSONString(product));}else{System.out.println(222222222);}return product;}
}