环境 :
Spring 4 REST
Spring MVC
过冬
问题 :
我们正在开发一个低于堆栈的应用程序.
Spring REST Web服务将为客户端公开API,它将在UI(ASP .NET)上显示它.响应以JSON格式发送.
考虑以下情况:
客户端调用REST api以获取具有ID的用户.dao层提取用户实体并将被提交给客户端.
以下场景的问题/观察:
由于用户可以使用与Hibernate映射相关的其他实体(例如userRoles使用oneToMany),因此还需要获取这些实体,否则抛出LazyInitialization异常,因为UI尝试通过User对象访问这些集合.
并非响应中需要User对象中的所有属性(例如:某些请求不需要用户拥有的角色).
考虑到上面的图片,通过Spring REST向客户端发送User对象(或响应)的最佳设计方法是什么?
创建一个模拟实体对象的中间对象层(如DTO).根据要求在服务层中填充此DTO.由于服务层在交易中运行,因此将解决第1号问题.但这需要在实体和DTO之间进行额外的复制
在Hibernate实体/查询级别处理问题编号1/2(连接获取查询或修改映射)并通过注释排除响应中不需要的属性,如:@JsonIgnore.但是这种方法不灵活,需要非常仔细地设计实体类
任何人都可以对此发表评论吗?还有更好的选择吗?
环境 :
雄猫8
Spring Boot 1.5
JSF 2.2
Apache MyFaces
Spring MVC
代码:
我在Servlet 3.0环境中集成了Spring Boot和JSF 2.2.
配置类:
JSFConfig.java - JSF的配置.
@Configuration
@ComponentScan({"com.atul.jsf"})
public class JSFConfig {
@Bean
public ServletRegistrationBean servletRegistrationBean() {
FacesServlet servlet = new FacesServlet();
return new ServletRegistrationBean(servlet, "*.jsf");
}
}
Run Code Online (Sandbox Code Playgroud)
Spring Boot主类:
@SpringBootApplication
@Import({ // @formatter:off
JPAConfig.class,
ServiceConfig.class, // this contains UserServiceImpl.java class.
WebConfig.class,
JSFConfig.class,
})
public class SpringbootJpaApplication extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(SpringbootJpaApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return …Run Code Online (Sandbox Code Playgroud) 当我运行前端maven插件时,我无法安装npm和node
我收到以下错误:
[ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.0:install-node-and-npm (install node and npm) on project : Could not download Node.js from: https://nodejs.org/dist/v0.9.9/x64/node.exe: Could not download https://nodejs.org/dist/v0.9.9/x64/node.exe: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target -> [Help 1]
Run Code Online (Sandbox Code Playgroud)
由于这是与证书相关的问题,我已执行以下步骤来解决此问题:
1)从节点站点提取证书
2)通过keytool命令在JDK/JRE/LIB/Securitykeystore cacerts中安装证书
3)证书安装成功
我仍然遇到同样的问题。
我真的无法解决这个问题
有人可以帮忙吗?
配置:
<configuration>
<nodeVersion>v8.9.1</nodeVersion>
<npmVersion>6.1.0</npmVersion>
</configuration>
Run Code Online (Sandbox Code Playgroud) 我有两个正则表达式,它们在独立使用时运行良好。
First : ^.+\.((jpeg)|(gif)|(png))\s*$ : search for .jpeg,gif or png at the end of url
Second : ^.+(javax.faces.resource|rfRes).* : search for two url patterns
Run Code Online (Sandbox Code Playgroud)
我想组合上述两个表达式,以便“ url 以任何图像结尾” 或“ url 在其路径中有 javax.faces.resource 或 rfRes”
我尝试使用 | 操作员加入两者,但它似乎不起作用,如下所示:
^.+\.((jpeg)|(gif)|(png))\s*$ | ^.+(javax.faces.resource|rfRes).*
Run Code Online (Sandbox Code Playgroud)
但它不工作。
有人可以帮忙加入以上两个正则表达式吗?
我正在从JBoss Seam到CDI的迁移项目.以下是技术堆栈:
1)WildFly 8.2.0(CDI 1.2,Weld作为CDI提供商)
2)JSF 2.2
3)JPA 2
我们正在使用容器管理的JTA事务:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="surveillenace" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>java:/surveillenaceDS</jta-data-source>
<!-- other configurations not shown here -->
</persistence>
Run Code Online (Sandbox Code Playgroud)
并使用@PersistenceContext注释将EntityManager注入DAO对象.
我们正在@Transaction为容器管理的事务使用注释.
我的问题/理解如下.
任何人都可以证实这一点,因为这对我来说是一个相对较新的领域.
1)据我所知,CDI通过@Transaction拦截器为CMT提供支持.哪个类/依赖实际上实现了这个拦截器?我们需要在pom.xml中为此导入哪些工件?
2)由于使用了CMT,我们不需要划分任何事务,容器将管理它.我们只需要使用EntityManager API来持久保存Db中的更改.这种理解是否正确?
@Transactional
public String finishOperation() {
log.debug("in finishOperation() ") ;
try {
//operations done on managed entities
//no transaction demarcation code is required here
dao.getEntityManager.commit();
}catch(Throwable xx){
}
}
Run Code Online (Sandbox Code Playgroud)
3)考虑使用上述配置执行的以下简单场景:
Component1.somemethod() - 在事务内部运行并持久保存实体(例如:用户)并提交事务.在此之后,如下调用Component2:
Component2.somemethod()- 在转换内运行,但实体User似乎不处于托管状态, em.contains(user) …
我有一个重新排序java泛型的问题.据我所知,通用信息仅在编译时可用,通过称为"类型擦除"的过程,一旦编译代码并且生成.class文件,所有TYPE信息都会消失.
一旦.java文件被编译,List myList = new arrayList(),就是.class文件字节码所具有的,即使该列表被声明为.java文件中的字符串列表.
话虽如此,请考虑以下情况.
我有一个带有签名方法的jar
public void check(List<String> p)
Run Code Online (Sandbox Code Playgroud)
当我从另一个代码调用此方法时,编译器强制执行check方法的参数应该List<String>只是,没有别的.
既然检查方法存在于jar(.class文件)中List<String>,如果在生成.class文件时TYPE信息已经被REMOVED,编译器如何知道所需的TYPE信息?
我们正在从jsf 1.2升级到jsf 2.我们正在使用apache myfaces 2.1和富面4.3.
以下是xhtml代码:
迁移之前:
<h:selectBooleanCheckbox id="comp1" value="#{bean.select}">
<a4j:support event="onclick" ajaxSingle="true" actionListener="#{bean.processInput}" reRender="compId">
<f:param name="name" value="paramValue"/>
</a4j:support>
</h:selectBooleanCheckbox>
Run Code Online (Sandbox Code Playgroud)
我们传递一个参数,并在actionListener方法中接受参数: (String)context.getExternalContext().getRequestParameterMap().get("name1");
迁移后:
<h:selectBooleanCheckbox id="comp1" value="#{bean.select}">
<a4j:ajax event="click" listener="#{bean.processInput}" execute="@this" render="compId"/>
</h:selectBooleanCheckbox>
Run Code Online (Sandbox Code Playgroud)
我想将参数传递给bean.processInput方法,该方法具有以下签名:
public void processInput(AjaxBehaviorEvent event){
Run Code Online (Sandbox Code Playgroud)
根据这篇文章 - 在f:ajax中传递参数的问题,我们不能使用<f:param>(它也不工作),我们没有使用EL 2.2来排除方法签名中的传递参数.
由于我们不能使用context.getApplication().evaluateExpressionGet由于我们的xhtml页面中的约束只有可用选项<a4j:param name="" value="" assignTo=""/>.
但是这需要在bean中定义一个需要代码更改的变量.
所以我的问题是我们可以在第二种情况下将参数从UI传递给侦听器,而无需更改代码.
版本:
Apache MyFaces 2.0 Rich Faces 4.3
问题 :
我们正在从JSF 1.2迁移到JSF 2.
由于没有内置支持对rich:dataTable进行排序,因此我们根据富面展示使用自定义排序解决方案.排序工作正常,唯一的问题是因为a4j:commandLink用于排序操作触发器,列标题文本带有"下划线"样式.有没有办法删除下划线a4j:commandLink?丰富的面孔展示没有显示任何造型a4j:commandLink?
请帮忙.
环境: Hibernate 4 Tomcat 6
问题 :
我在 MySQL 数据库中有一个 DATETIME 类型的列(abhishekDate 是列名)。
我想将用户提供的日期与此 DATETIME 列进行比较。
但比较不应包括DATETIME 列的时间部分。比较应仅基于DATE 部分。
由于查询是动态的,因此我使用 Criteria API。但我无法使用 Criteria API 实现相同的目标。我已经尝试过下面的代码,但它不起作用。
您能帮忙看看如何编写这个查询吗?
我是否使用了正确的方法?
我得到的例外是:
Mar 08, 2016 9:26:59 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet mvc-dispatcher threw exception
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'abhishekDate' in 'where clause'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3558)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3490)
Run Code Online (Sandbox Code Playgroud)
但 abhishekDate 存在于 User 类(或表)中
代码 : …
我正在使用 Karma运行Angular 6 单元测试,下面是我的配置:
karma.conf.js :
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
customLaunchers: {
CustomHeadlessChrome: {
base: "ChromeHeadless",
flags: [
"--headless",
"--disable-gpu",
"--disable-web-security",
"--disable-site-isolation-trials",
"--remote-debugging-port-9222",
"--no-sandbox"
]
}
},
client:{
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, 'coverage'), reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},
angularCli: {
environment: 'dev'
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: …Run Code Online (Sandbox Code Playgroud) 我正在学习反应并有以下观察。
我无法理解错误背后的原因。
我有下面的代码 -
反应:
useEffect(()=>{
console.log()
axios.get('http://localhost:8000/api/records/').then((data) => {console.log('server returned ... ',typeof(data));setRecords(data)}
).catch( e => console.log(e))
},[])
const [records,setRecords] = useState([]);
Run Code Online (Sandbox Code Playgroud)
当仅data在侧面使用时then clause in axios,我收到以下错误,Uncaught TypeError: records.map is not a function
但是,当我更改如下代码时 - 请注意{data}而不是仅仅data,上述错误得到解决。
axios.get('http://localhost:8000/api/records/').then(({data}) => {...}
有人可以解释一下上述行为吗?
我尝试打印type of variable data,但在这两种情况下它都是object
{data}为什么当使用 代替时上述错误消失了{data}
表达:
const express = require('express')
const app = express()
var cors = require('cors')
const port = 8000
app.use(cors())
const Records = …Run Code Online (Sandbox Code Playgroud)