我正在使用Intellij IDE来编写spring Boot代码.
Spring Initializr在new project选项中不适用于我.
您可以在下面找到我的IDE的屏幕截图.请让我知道我在这里缺少什么?
在具体
我想只为特定的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) 当我IdentityUser在Asp.Net中 使用模型Identity时EntityFramework,它会在数据库中创建一些标准字段.除以下两个字段外,所有字段都是自解释的.
NormalizedUsername - 其中包含用户名的大写值NormalizedEmail - 其中包含电子邮件的大写值我的怀疑是:
在具体
我需要一种方法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但我需要一种方法来做到这一点来自百万美分:) 我正在尝试使用一些字节数组数据动态创建一个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) 具体而言
我想在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在屋顶下工作.
我累了很多才发现这个.但最终在SO社区的帮助下结束了.请帮帮我.
简而言之
我希望在一次写入多个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)
但是上面的代码失败了,错误
Run Code Online (Sandbox Code Playgroud)org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "'COMPLETE','INVALID'"...
注意:我知道上述错误消息的原因.我只需要知道一种方法来实现单个输出的多个案例的切换
.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')]我知道我可以通过在模型类中使用来更改生成的表名称。
但是,我需要的是一种以全局方式执行此操作的方法。
我正在使用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,它会中断并给出错误.
当我尝试在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:元素的内容必须由格式良好的字符数据或标记组成.
我怎么解决这个问题?
java ×7
spring ×5
spring-boot ×4
spring-mvc ×4
thymeleaf ×3
c# ×2
javascript ×2
.net ×1
.net-core ×1
asp.net ×1
asp.net-mvc ×1
html ×1
json ×1