小编DaF*_*oot的帖子

为什么我使用H2数据库/ Spring启动应用程序获取JdbcSQLException(非十六进制字符)?

所以简短的版本,我猜我有某种字符编码问题,或者数据库以Hibernate/Spring-jpa格式存储/返回日期由于某种原因不喜欢.

但是,如果我能弄清楚出了什么问题,我会被嘲笑!

使用Hibernate 5在实体道具中使用J8 LocalDate的东西.

正在创建数据库并插入数据(您将在下面的日志片段中看到我得到一个日期值).

日志片段:

2016-10-26 13:25:19.885 ERROR 1028 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: 
Could not read entity state from ResultSet : EntityKey[uk.co.deditech.entity.Person#2]; 
nested exception is org.hibernate.exception.GenericJDBCException: Could not read entity state from ResultSet : 
EntityKey[uk.co.deditech.entity.Person#2]] with root cause org.h2.jdbc.JdbcSQLException: Hexadecimal string contains non-hex character: "2016-03-23" [90004-192]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345) ~[h2-1.4.192.jar:1.4.192]
at org.h2.message.DbException.get(DbException.java:179) ~[h2-1.4.192.jar:1.4.192]
at org.h2.message.DbException.get(DbException.java:155) ~[h2-1.4.192.jar:1.4.192]
at org.h2.util.StringUtils.convertHexToBytes(StringUtils.java:986) ~[h2-1.4.192.jar:1.4.192]
at org.h2.value.Value.convertTo(Value.java:973) …
Run Code Online (Sandbox Code Playgroud)

java hibernate h2 spring-data-jpa spring-boot

14
推荐指数
2
解决办法
9600
查看次数

如何为Spring MVC webapp添加Freemarker支持?依赖问题?

我正在尝试使用Freemarker和Java配置创建Spring MVC应用程序.

我习惯使用JSP,但我想我会给Freemarker一个旋转.

我添加了Freemarker作为依赖,并且Maven正在下载jar:

        <dependency>
        <groupId>org.freemarker</groupId>
        <artifactId>freemarker</artifactId>
        <version>2.3.20</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用3.2.3.RELEASE版本的Spring.

我的MVC配置,通过阅读类似问题组装而成:

@ComponentScan(basePackages="yhj.*")
@EnableWebMvc
public class MvcConfiguration extends WebMvcConfigurerAdapter{


@Bean
public ViewResolver viewResolver() {
    FreeMarkerViewResolver resolver = new FreeMarkerViewResolver();
    resolver.setCache(true);
    resolver.setPrefix("");
    resolver.setSuffix(".ftl");
    return resolver;

}

@Bean
public FreeMarkerConfigurer freemarkerConfig() {
    FreeMarkerConfigurer result = new FreeMarkerConfigurer();
    result.setTemplateLoaderPath("/WEB-INF/views/");
    return result;

}
}
Run Code Online (Sandbox Code Playgroud)

当我尝试运行它时,我得到一个编译错误,我的IDE告诉我无法解析方法'setTemplateLoaderPath(String)'.

那么......看起来像是使用Freemarker配置Spring MVC的正确方法吗?如果这是问题,我需要添加到我的POM的依赖项是什么?

spring freemarker spring-mvc

12
推荐指数
3
解决办法
1万
查看次数

我可以在LibreOffice calc IF语句中使用OR吗?

我正在努力实现以下目标:

= IF(N2 ="string1","high",IF(N2 ="string2"或N2 ="string3","中间","低"))

或者,在伪代码中:

String input = <some value>
if( input.equals("string1") ) {
     return "high"
} else if ( input.equals("string2) || input.equals("string3") ) {
    return "middle"
} 
return "low"
Run Code Online (Sandbox Code Playgroud)

知道如何使用电子表格(理想的Libre Office Calc)公式而不是代码吗?输入变量显然是单元格引用.

if-statement libreoffice libreoffice-calc

10
推荐指数
1
解决办法
1万
查看次数

我应该如何应用自定义角度材质主题?

我在尝试设置自定义 Angular Material 主题时遇到问题。我正在尝试遵循文档(https://material.angular.io/guide/theming)中给出的基本示例,但在应用程序启动期间不断遇到错误:“SassError:缺少参数 $accent”。

这似乎是试图突出 mat-light-theme() 调用,但据我所知,我正在遵循文档中给出的示例文件。

这看起来是否正确......(我希望确信主题文件是正确的,以便我可以开始追踪其他地方引入的问题)?


    @import '~@angular/material/theming';
    @import 'mixins/definitions'; // just another scss file

    // Include the common styles for Angular Material. We include this here so that you only
    // have to load a single css file for Angular Material in your app.
    // Be sure that you only ever include this mixin once!
    @include mat-core();

    $my-app-primary: mat-palette($mat-indigo); 
    $my-app-accent:  mat-palette($mat-pink, A200, A100, A400);
    $my-app-warn:  mat-palette($mat-red, A200, A100, A400);

    // The warn palette is …
Run Code Online (Sandbox Code Playgroud)

angular-material

9
推荐指数
1
解决办法
1841
查看次数

我应该如何在Angular模块中包含模型类?

我有几个类我想成为一个普通的bean/DTO类,它们不是显示@component类,它们不是@Pipe类,也不是@Directive(至少我不认为它应该是!).

我希望能够将它们捆绑到一个模块中(它们将用于其他模块),但是尽管有几个咒语,我仍然会遇到这样的错误:

当我启动我的Angular应用程序(ng服务)时,它编译正常,但在浏览器(Chrome)控制台中我收到错误....

Uncaught Error: Unexpected value 'Accreditation' declared by the module 'ServiceModule'. Please add a @Pipe/@Directive/@Component annotation.
Run Code Online (Sandbox Code Playgroud)

我应该如何将这些类捆绑到一个模块中供其他模块使用?我不介意他们是在我的服务模块中还是在另一个新的'beans'模块中.

给定此模块定义(service.module.ts):

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import {MemberService} from "./member/member.service";
import { Accreditation } from "./accreditation";
import {Player} from "./player";
import {Club} from "./club";
import {Coach} from "./coach";

@NgModule({
  imports: [CommonModule],
  declarations: [Accreditation, Club, Player, Coach],
  exports: [Accreditation, Club, Player, Coach],
  providers: [MemberService]
})
export class ServiceModule { }
Run Code Online (Sandbox Code Playgroud)

accreditation.ts:

export class Accreditation { …
Run Code Online (Sandbox Code Playgroud)

angular-module angular

7
推荐指数
1
解决办法
5122
查看次数

如何将Sitemesh 3与Spring MVC 3集成?

我试图使用Sitemesh 3来控制Spring MVC应用程序的JSP输出的装饰.

当我点击应用程序时,似乎Sitemesh正在向Spring servlet发出请求以尝试并检索其装饰器文件.这可能是,也可能不是正确的行为,但它引起了我很多头痛.

我对Sitemesh 3的理解是它在Spring之后完成它的工作,即在Response对象上.

我在浏览器中遇到的错误是404和日志(配置/代码如下):

INFO: Server startup in 1367 ms
DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 
'springiness' processing GET request for [/clientmanager/]^M
DEBUG: 
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - 
Looking up handler method for path /^M
DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - 
Returning handler method [public java.lang.String 
uk.co.hermes.HomeController.home(java.util.Locale,org.springframework.ui.Model)]^M
DEBUG: org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning 
cached instance of singleton bean 'homeController'^M
DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for 
[/clientmanager/] is: -1^M
INFO : uk.co.hermes.HomeController - Welcome home! The client locale is en_GB.^M
DEBUG: org.springframework.beans.factory.support.DefaultListableBeanFactory - Invoking     
afterPropertiesSet() …
Run Code Online (Sandbox Code Playgroud)

spring-mvc sitemesh

4
推荐指数
1
解决办法
1万
查看次数

如何在刚刚出现的元素上使用jQuery设置焦点

我有一个文件就绪块如下:

$(document).ready(function () {
    $('#addTagLink').click(function () {
        $('#addTagField').show();
        $('#addTagField').val("");
        $('#addTagField').focus();
    });
});
Run Code Online (Sandbox Code Playgroud)

addTagField是一个常规文本输入,在页面加载时由css设置display:none.

当用户单击addTagLink 元素时,输入字段会正确显示,但焦点不会按预期设置到字段.

我认为它必须与display:none/show()功能有关,因此将其更改$('#addTagField').focus();为另一个$('#name').focus();完美运行的字段.

任何人都可以先建议我为什么看到这个问题,其次,如何解决它?

jquery focus show setfocus

2
推荐指数
2
解决办法
4万
查看次数

如何在Sitemesh 3中使用自定义属性

给出了一个由Sitemesh 3渲染的简单模板JSP:

<%@include file="../jsp_inc/taglibs.jsp" %>
<!DOCTYPE html>
<head>
    <link rel="stylesheet" type="text/css" href='<c:url value="/css/global.css" />' >
</head>
<body>
<h1>[HEADING]</h1>
<div>
    <sitemesh:write property='body'/>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)

该模板按预期工作,将JSP元素的内容插入模板中.

正如您对上述内容的期望,我希望能够将JSP中的值集(例如.h1元素)插入到模板中的相应元素中.

我试过了:

<sitemesh:getProperty property="page.heading"></sitemesh:getProperty>
Run Code Online (Sandbox Code Playgroud)

在模板/装饰器中:

<content tag="heading"></content>
Run Code Online (Sandbox Code Playgroud)

在JSP中,关于SO的另一个问题,但我认为可能是指Sitemesh 2.我正在使用Sitemesh 3.

有什么建议?

templates jsp sitemesh

1
推荐指数
1
解决办法
4362
查看次数

我应该如何使用SpringBoot创建H2?

我开始玩Spring Boot,作为其中的一部分,我想创建一个内存DB来与应用程序一起工作和引导程序.

鉴于下面的配置/代码我在启动日志中没有错误并且可以访问应用程序,所以它确实启动(我得到关于不存在的对象的模板错误),但是在调用时我没有从DAO获得任何数据findAll()(或者如果我尝试调用findById(int)).

所以虽然看起来一切正常(日志中没有错误,日志显示它找到sql来创建架构广告尝试运行data.sql语句)当我尝试通过DAO访问数据时我没有得到异常,但没有返回数据.

关于代码可能有问题的任何想法或观察?

我已将Spring Data/H2添加到我的pom中:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

春天DAO:

public interface PersonDao extends CrudRepository<Person, Integer> {
}
Run Code Online (Sandbox Code Playgroud)

application.properties中的数据库道具:

server.contextPath=/
server.port=8080
spring.mvc.view.suffix=.ftl

datasource.mine.jdbcUrl=jdbc:h2:tcp://localhost/mem:clubmanagement
datasource.mine.user=sa
datasource.mine.password=
datasource.mine.poolSize=30

logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=DEBUG

spring.jpa.hibernate.ddl-auto=create
Run Code Online (Sandbox Code Playgroud)

我的服务:

@Service
public class MemberServiceImpl implements MemberService {

@Autowired
PersonDao dao;

@Override
public Optional<ClubMember> getClubMember(int id) {
    Person dbPerson = dao.findOne(id);
    if(dbPerson == null) {
        return Optional.empty();
    }
    return Optional.of(fromEntity(dbPerson));
}

@Override
public List<ClubMember> allMembers() {
    Iterable<Person> people = dao.findAll();
    List<ClubMember> members = new ArrayList<>(); …
Run Code Online (Sandbox Code Playgroud)

spring hibernate h2 spring-data spring-boot

1
推荐指数
1
解决办法
7251
查看次数

Java日期/日历奇怪

我有一点(Java),我试图简单地从当前日期减去7天.在我看来,像Calendar.add(..)应该是使用的方法(以及之前的问题似乎在说),所以这就是我尝试的:

SimpleDateFormat df = new SimpleDateFormat("dd-mm-yyyy");
GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance();
System.out.println("ReportUtil.getDefaultReportStartDate cal: "+cal.toString() );
System.out.println("PRE ReportUtil.getDefaultReportStartDate: "+df.format(cal.getTime()) );
cal.add(Calendar.DATE, -7);
System.out.println("POST ReportUtil.getDefaultReportStartDate: "+df.format(cal.getTime()) );
Run Code Online (Sandbox Code Playgroud)

这看起来不错,但你会从月份字段下面的输出中看到似乎有点......侧身!月/日的日期似乎正确地改变了,但这个月发生了什么?!

ReportUtil.getDefaultReportStartDate cal: java.util.GregorianCalendar[time=1330098699960,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="GB-Eire",offset=0,dstSavings=3600000,useDaylight=true,transitions=242,lastRule=java.util.SimpleTimeZone[id=GB-Eire,offset=0,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]],firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=2012,MONTH=1,WEEK_OF_YEAR=8,WEEK_OF_MONTH=4,DAY_OF_MONTH=24,DAY_OF_YEAR=55,DAY_OF_WEEK=6,DAY_OF_WEEK_IN_MONTH=4,AM_PM=1,HOUR=3,HOUR_OF_DAY=15,MINUTE=51,SECOND=39,MILLISECOND=960,ZONE_OFFSET=0,DST_OFFSET=0]

PRE ReportUtil.getDefaultReportStartDate: 24-51-2012
POST ReportUtil.getDefaultReportStartDate: 17-51-2012
Run Code Online (Sandbox Code Playgroud)

java calendar date

0
推荐指数
1
解决办法
210
查看次数