小编Far*_*ook的帖子

Intellij Spring Initializr不可用

我正在使用Intellij IDE来编写spring Boot代码.

Spring Initializr在new project选项中不适用于我.

http://blog.jetbrains.com/idea/2015/03/develop-spring-boot-applications-more-productively-with-intellij-idea-14-1/

您可以在下面找到我的IDE的屏幕截图.请让我知道我在这里缺少什么?

在此输入图像描述

java spring intellij-idea spring-initializr

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

用于Web的RESTFul和FormLogin(Cookies)的Spring Security HTTP Basic - 注释

在具体

我想只为特定的URL模式进行HTTP基本身份验证.

详细地

我正在为我的应用程序创建一个API接口,需要通过简单的HTTP基本身份验证进行身份验证.但是其他网页应该使用HTTP basic,而应该使用普通的表单登录.

当前配置 - 不工作

@Override
protected void configure(HttpSecurity http) throws Exception {
    http //HTTP Security
            .csrf().disable() //Disable CSRF
            .authorizeRequests() //Authorize Request Configuration
                .antMatchers("/connect/**").permitAll()
                .antMatchers("/", "/register").permitAll()
                .antMatchers("/admin/**").hasRole("ADMIN")
                .antMatchers("/api/**").hasRole("API")
                .anyRequest().authenticated()
            .and() //HTTP basic Authentication only for API
                .antMatcher("/api/**").httpBasic()
           .and() //Login Form configuration for all others
                .formLogin().loginPage("/login").permitAll()
            .and() //Logout Form configuration
                .logout().permitAll();

}
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc spring-security spring-boot

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

.NET核心IdentityUser模型中规范化电子邮件和用户名的用途是什么?

当我IdentityUserAsp.Net中 使用模型IdentityEntityFramework,它会在数据库中创建一些标准字段.除以下两个字段外,所有字段都是自解释的.

  • NormalizedUsername - 其中包含用户名的大写值
  • NormalizedEmail - 其中包含电子邮件的大写值

我的怀疑是:

  1. 为什么我们需要这些标准化字段?
  2. 将其保存在数据库中的目的是什么?
  3. 这个字段在框架中使用的位置是什么?

asp.net entity-framework asp.net-identity .net-core

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

Thymeleaf将JSON字符串作为JSON对象打印到javascript变量中

在具体

我需要一种方法JSON通过thymeleaf将字符串值的表示打印到html页面.

详细地

我有一个model attribute包含字符串的字符串,实际上是字符串表示形式JSON

我的thymeleaf代码

<script th:inline="javascript">
  var value = [[${data.scriptValue}]];
</script>
Run Code Online (Sandbox Code Playgroud)

打印变量如下

var value = '[[\"asd\",\"3\"],[\"asd\",\"1\"],[\"asdasd\",\"1\"]]';
Run Code Online (Sandbox Code Playgroud)

但我想要这样的东西作为一个javascript/JSON数组

var value = [["asd","3"],["asd","1"],["asdasd","1"]];
Run Code Online (Sandbox Code Playgroud)

如何在百里香中做到这一点?


注意:我知道我可以这样做,JSON.Parse但我需要一种方法来做到这一点来自百万美分:)

javascript java json spring-mvc thymeleaf

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

ZipArchive给出了意外的数据结束错误

我正在尝试使用一些字节数组数据动态创建一个zip流,并通过我的MVC动作下载.

但是,在Windows中打开时,下载的文件总是会出现以下损坏的错误.

在此输入图像描述

当我尝试从7z提取时出现此错误

在此输入图像描述

但请注意,从7z中提取的文件未损坏.

我正在使用ZipArchive,以下是我的代码.

    private byte[] GetZippedPods(IEnumerable<POD> pods, long consignmentID)
    {
        using (var zipStream = new MemoryStream())
        {
            //Create an archive and store the stream in memory.                
            using (var zipArchive = new ZipArchive(zipStream, ZipArchiveMode.Create, true))
            {
                int index = 1;
                foreach (var pod in pods)
                {                        
                    var zipEntry = zipArchive.CreateEntry($"POD{consignmentID}{index++}.png", CompressionLevel.NoCompression);                       
                    using (var originalFileStream = new MemoryStream(pod.ByteData))
                    {
                        using (var zipEntryStream = zipEntry.Open())
                        {
                            originalFileStream.CopyTo(zipEntryStream);
                        }
                    }
                }
                return zipStream.ToArray();
            }
        }
    }

    public ActionResult DownloadPOD(long consignmentID) …
Run Code Online (Sandbox Code Playgroud)

.net c# asp.net-mvc system.io.compression

16
推荐指数
2
解决办法
3314
查看次数

如何在Spring Boot中执行多个URL映射(别名)

具体而言

我想在spring boot中进行多URL映射(换句话说别名)

详细地

在我的Spring启动应用程序中, Customer Controller类主要映射到/customerURL,如下所示我想创建易于更改的别名

@Controller
@RequestMapping(value = "/customer")
public class CustomerController{
Run Code Online (Sandbox Code Playgroud)

在我正常的spring应用程序中,我在XML中进行映射,我可以进行如下的URL映射.

<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
   <property name="mappings">
    <props>
       <prop key="/customer.htm">customerController</prop>
       <prop key="/tester.htm">customerController</prop>
     </props>
   </property>
</bean>

<bean id="customerController" 
    class="com. ... .controller.CustomerController" />
Run Code Online (Sandbox Code Playgroud)

Spring boot,属性文件配置在大多数情况下是有用的,因为autoconfig在屋顶下工作.

  1. 有什么办法可以使用属性文件做同样的事情.
  2. 在spring boot中进行URL映射时要遵循的最佳做法是什么,我可以在编译后轻松更改.

我累了很多才发现这个.但最终在SO社区的帮助下结束了.请帮帮我.

java spring spring-mvc spring-boot

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

Thymleaf switch语句有多个case

简而言之

我希望在一次写入多个case语句时,在thymeleaf中使用switch语句.

详细地

我想在百里香中实现这一点

switch(status.value){
  case 'COMPLETE':
  case 'INVALID':
     //print exam is not active
     break;
  case 'NEW':
     //print exam is new and active
     break;
}
Run Code Online (Sandbox Code Playgroud)

我当前的thymleaf代码因运行时错误而失败

 <div th:switch="${status.value}">
      <div th:case="'COMPLETE','INVALID'">
         <!-- print object is not active -->
      </div>
      <div th:case="NEW'">
         <!-- print object is new and active -->
      </div>
 </div>                             
Run Code Online (Sandbox Code Playgroud)

但是上面的代码失败了,错误

org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "'COMPLETE','INVALID'"...
Run Code Online (Sandbox Code Playgroud)

注意:我知道上述错误消息的原因.我只需要知道一种方法来实现单个输出的多个案例的切换

java thymeleaf spring-boot

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

.net core实体框架(EF Core)表命名约定

.net core实体框架(EF Core)表命名约定复数到单/简单/下划线

作为表名称命名约定的爱好者,我对EF core命名表的single simple underscore方式感到不舒服。Plural PascalCase

模型

public class SourceType {
   ... 
Run Code Online (Sandbox Code Playgroud)

数据库上下文

public class ApplicationDbContext : DbContext {
    public DbSet<SourceType> SourceTypes { get; set; }
    ...
Run Code Online (Sandbox Code Playgroud)

这将创建具有名称(PascalCase 和 Plural)的表SourceTypes

[table('source_type')]我知道我可以通过在模型类中使用来更改生成的表名称。

但是,我需要的是一种以全局方式执行此操作的方法。

c# entity-framework entity-framework-core

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

如何自定义Spring Data REST以使用存储库资源的多段路径?

我正在使用Spring Data JPA和Spring Data REST开发基于组件的CRUD应用程序.我有几个组件.例如,系统组件具有User模型和UserRepository.组件由包名称区分.喜欢com.example.app.<component_name>

因此,为了使我的REST API看起来更干净,我需要实现API URL,如下所示.

host:8080/<component_name>/<model_collection_name>

例如

host:8080/system/users

我在我的存储库中执行了以下操作

@RepositoryRestResource(collectionResourceRel = "users", path = "system/users")
public interface UserRepository extends PagingAndSortingRepository<User, Long> {
   ...
}
Run Code Online (Sandbox Code Playgroud)

当我转到时,这会生成以下内容 http://localhost:8080

{
   "_links": {
   "users": {
   "href": "http://localhost:8080/system/users{?page,size,sort}",
    "templated": true
},
...
Run Code Online (Sandbox Code Playgroud)

但是当我转到 http://localhost:8080/system/users

它给出了一个错误

5月22日星期五17:56:37 IST 2015出现意外错误(type = Not Found,status = 404).没有可用的消息

注意:如果我将路径映射到system-users那么它工作正常,但是当我/在路径中使用a 时system/users,它会中断并给出错误.

java spring spring-mvc spring-data-rest spring-boot

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

大于>小于<内百里面javascript ...错误:元素的内容必须包含格式良好的字符数据或标记

当我尝试在javascript中插入<>运算符时,我收到此错误thymeleaf.

我的代码

<script th:inline="javascript">
    $(document).ready(function () {
        ...
        if(timeRemain < 0){
            ...
        }
        ...
        var result = (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds  < 10 ? "0" + seconds : seconds);
        ...         
    });
</script>
Run Code Online (Sandbox Code Playgroud)

错误信息

org.xml.sax.SAXParseException:元素的内容必须由格式良好的字符数据或标记组成.

我怎么解决这个问题?

html javascript java spring thymeleaf

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