小编sta*_*000的帖子

Org.Hibernate.AnnotationException:没有为实体指定的标识符我的表中没有id

我正在使用数据库中的表,并且该表没有主键或具有可作为主键的唯一值的正确列,我没有权限来更改该表.

我该怎么办?我尝试将@id注释放在一个随机列中并且它有效,但我不知道这是否会在以后带来任何麻烦.我能做什么?

我的课

@Entity
@Table(name="my_table")
public class TheTable {
@Column (name="name", nullable=false)
    private String name;

    @Id <--- I just put this id in this random column but this column should not be a id column
    @Column (name="anyfield", nullable=false)
    private String anyfield;
}
Run Code Online (Sandbox Code Playgroud)

java hibernate jpa spring-mvc spring-data

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

Thymeleaf的Spring Security简单示例

嗨,我正在尝试按照一个简单的例子来做一个我在这个页面中找到的简单登录表单页面 http://docs.spring.io/autorepo/docs/spring-security/4.0.x/guides/form.html

问题是我每次尝试登录时都会收到此错误我收到此错误: Expected CSRF token not found. Has your session expired?

当我收到此错误时,我按下浏览器中的后退按钮并尝试第二次登录,当我这样做时,我收到此错误: HTTP 403 - Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'

在教程页面中是这条消息: We use Thymeleaf to automatically add the CSRF token to our form. If we were not using Thymleaf or Spring MVCs taglib we could also manually add the CSRF token using <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>

"所以因为我也在使用百里香,我没有把这个标签添加到我的页面"

我找到了另一个解决方案,它的工作原理,这个解决方案是将此添加到我的安全配置类.csrf().disable()这个解决方案有效,但我想这样做是为了禁用我的页面中的csrf保护,我不想禁用这种类型的保护.

这是我的security-config类:

@Configuration
@EnableWebSecurity
public class ConfigSecurity extends WebSecurityConfigurerAdapter {

    @Autowired …
Run Code Online (Sandbox Code Playgroud)

java security spring-mvc spring-security thymeleaf

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

@EnableSpringConfigured导入

嗨,我正在使用spring mvc项目,我希望能够做这个注释

@EnableSpringConfigured

在我的一个类的顶部像这样

@Configuration
@EnableSpringConfigured  <---- this one gives me troubles
@ComponentScan( basePackages = {"com.abc.dom", "com.abc.repo", "com.abc.auth"})
@EnableJpaRepositories(basePackages="com.abc.repo")
public class ConfigJPA 
{

....

}
Run Code Online (Sandbox Code Playgroud)

我应该在pom.xml中使用什么maven依赖来执行此导入:

import org.springframework.context.annotation.aspectj.EnableSpringConfigured;
Run Code Online (Sandbox Code Playgroud)

我的春季版是4.0.6.RELEASE

java import spring spring-mvc maven

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

在spring mvc中引用一个带有百里香的.css文件

我正在做一个春季MVC和Thymeleaf的项目.如果我有这个文件夹结构,我有一个关于如何引用我的CSS文件的问题:

src
  main
    webapp
     resources
       myCssFolder
         myCssFile.css
     web-inf
       spring
       views
         myViewFolder
           index.html
Run Code Online (Sandbox Code Playgroud)

我的配置类是这样的:

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/css/**").addResourceLocations("/css/**");
    registry.addResourceHandler("/img/**").addResourceLocations("/img/**");
    registry.addResourceHandler("/js/**").addResourceLocations("/js/**");
    registry.addResourceHandler("/sound/**").addResourceLocations("/sound/**");
    registry.addResourceHandler("/fonts/**").addResourceLocations("/fonts/**");
}
Run Code Online (Sandbox Code Playgroud)

href在我的索引文件中调用如下:

href="resources/css/bootstrap.min.css"
Run Code Online (Sandbox Code Playgroud)

但是有一些元素在我的页面中搞砸了,例如CSS无效.

html css spring spring-mvc thymeleaf

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

Spring Data JPA如何传递日期参数

我正在使用Spring工具套件处理弹簧MVC项目和弹簧数据,我想将日期参数传递给本机查询,到目前为止我已经这样做了.

我的查询方法在扩展JpaRepository的接口中

 @Query(value  = 
            "SELECT "
                + "a.name, a.lastname
            + "FROM "
                + "person  a, "
                + "myTable b "
            + "WHERE "
            + "a.name= ?1' "
            + "AND a.birthday = ?2 ",
         nativeQuery = true)
    public ArrayList<Object> personInfo(String name, String dateBirthDay);
Run Code Online (Sandbox Code Playgroud)

实现此接口定义的方法:

public ArrayList<Object> getPersonsList(String name, String dateBirthDay) {

            ArrayList<Object> results= null;

            results= serviceAutowiredVariable.personInfo(name, dateBirthDay);

            return results;
        }
Run Code Online (Sandbox Code Playgroud)

这就是我从控制器类中调用它的方式.

personsList= _serviceAutowiredVariable.getPersonsList("Jack", "TO_DATE('01-08-2013', 'DD-MM-YYYY')" );
Run Code Online (Sandbox Code Playgroud)

我想在这一行中"AND a.birthday = ?2 " ,?2is等于这个字符串TO_DATE('01-08-2013', 'DD-MM-YYYY')

但是当我运行我的代码时,我收到此错误

    [Request processing failed; …
Run Code Online (Sandbox Code Playgroud)

java spring jpa spring-mvc spring-data

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

错误尝试在spring mvc中使用maven从WSDL生成类

嗨,我试图按照这个例子https://spring.io/guides/gs/consuming-web-service/,我在我的pom.xml文件中收到以下错误

这是我的pom.xml文件,我添加的新部分是评论< - WEB SERVICES - >之后的部分

这是问题的一部分:

<plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>       
                <configuration>
                    <schemaLanguage>WSDL</schemaLanguage>
                    <generatePackage>hello.wsdl</generatePackage>
                    <forceRegenerate>true</forceRegenerate>
                    <schemas>
                        <schema>
                            <url>http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl</url>
                        </schema>
                    </schemas>
                </configuration>
            </plugin>
Run Code Online (Sandbox Code Playgroud)

这是整个pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.pruebaWsCompany</groupId>
    <artifactId>app</artifactId>
    <name>PruebaWSproy</name>
    <packaging>war</packaging>
    <version>1.0.0-BUILD-SNAPSHOT</version>
    <properties>
        <java-version>1.6</java-version>
        <org.springframework-version>3.1.1.RELEASE</org.springframework-version>
        <org.aspectj-version>1.6.10</org.aspectj-version>
        <org.slf4j-version>1.6.6</org.slf4j-version>
    </properties>
    <dependencies>
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${org.springframework-version}</version>
            <exclusions>
                <!-- Exclude Commons Logging in favor of SLF4j -->
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                 </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework-version}</version> …
Run Code Online (Sandbox Code Playgroud)

spring wsdl web-services spring-mvc maven

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

如何在春天的mvc中用百里香填充一个简单的桌子

我有一个对象列表,我想在表中显示这些对象的值thymeleaf,这是我到目前为止:

这是我的控制器类,它添加了我的对象列表:

@RequestMapping(value = "/showTableWithValues", method = RequestMethod.GET)
    public String showTableWithValues(Model model) 
    {
        //list with Persons
        ArrayList<Persons>  personsList= 
                new ArrayList<Persons>();

        personsList=  this.getListOfPersons();

        model.addAttribute("list", personsList);

        return "showTableWithValues";
    }
Run Code Online (Sandbox Code Playgroud)

这是我的.html文件,我想显示我的值:

<html lang="en"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">

<head>
    <title>Home</title>
</head>
<body>
<h1>
    Show Values 
</h1>

<table class="table table-striped">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>Name</th>
                    <th>Cost</th>
                    <th>Mins to prepare</th>
                    <th>Action</th>
                </tr>
                </thead>
                <tbody>

                    <tr th:each="persons : ${list}">

                    </tr>   

                </tbody>
</table>
</body>
</html> 
Run Code Online (Sandbox Code Playgroud)

而我的Person.java班级:

public class Person {

private String name;
private String last_name;
private …
Run Code Online (Sandbox Code Playgroud)

html java spring spring-mvc thymeleaf

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