Merge branch 'master' of https://github.com/eugenp/tutorials into BAEL-16733

This commit is contained in:
amit2103 2019-08-25 10:05:04 +05:30
commit 03977951bb
31 changed files with 112 additions and 37 deletions

View File

@ -1,4 +1,4 @@
package com.baeldung.http; package com.baeldung.httprequest;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;

View File

@ -1,4 +1,4 @@
package com.baeldung.http; package com.baeldung.httprequest;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;

View File

@ -1,8 +1,11 @@
package com.baeldung.http; package com.baeldung.httprequest;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.junit.Test; import org.junit.Test;
import com.baeldung.httprequest.FullResponseBuilder;
import com.baeldung.httprequest.ParameterStringBuilder;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;

View File

@ -1,4 +1,4 @@
package org.baeldung.guava; package org.baeldung.guava.maps.initialize;
import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.*; import static org.junit.Assert.*;

View File

@ -1,4 +1,4 @@
package org.baeldung.sample; package org.baeldung.autowire.sample;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;

View File

@ -1,10 +1,10 @@
package org.baeldung.sample; package org.baeldung.autowire.sample;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@Configuration @Configuration
@ComponentScan("org.baeldung.sample") @ComponentScan("org.baeldung.autowire.sample")
public class AppConfig { public class AppConfig {
} }

View File

@ -1,4 +1,4 @@
package org.baeldung.sample; package org.baeldung.autowire.sample;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;

View File

@ -0,0 +1,5 @@
package org.baeldung.autowire.sample;
public class FooDAO {
}

View File

@ -1,4 +1,4 @@
package org.baeldung.sample; package org.baeldung.autowire.sample;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;

View File

@ -1,4 +1,4 @@
package org.baeldung.sample; package org.baeldung.autowire.sample;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;

View File

@ -1,4 +1,4 @@
package org.baeldung.sample; package org.baeldung.autowire.sample;
public interface Formatter { public interface Formatter {

View File

@ -1,4 +1,4 @@
package org.baeldung.sample; package org.baeldung.autowire.sample;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;

View File

@ -1,4 +1,4 @@
package org.baeldung.startup; package org.baeldung.profiles;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;

View File

@ -1,5 +0,0 @@
package org.baeldung.sample;
public class FooDAO {
}

View File

@ -1,4 +1,4 @@
package org.baeldung.sample; package org.baeldung.autowire.sample;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;

View File

@ -1,4 +1,4 @@
package com.baeldung.annotations; package com.baeldung.responseentity;
import java.io.IOException; import java.io.IOException;
import java.time.Year; import java.time.Year;

View File

@ -1,4 +1,4 @@
package com.baeldung.annotations; package com.baeldung.responseentity;
import java.time.Year; import java.time.Year;

View File

@ -1,4 +1,4 @@
package com.baeldung.properties; package com.baeldung.configurationproperties;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;

View File

@ -0,0 +1,13 @@
package com.baeldung.configurationproperties;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@SpringBootApplication
@EnableConfigurationProperties(ConfigProperties.class)
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}

View File

@ -1,4 +1,4 @@
package com.baeldung.properties.conversion; package com.baeldung.configurationproperties;
public class Employee { public class Employee {

View File

@ -1,4 +1,4 @@
package com.baeldung.properties.conversion; package com.baeldung.configurationproperties;
import org.springframework.boot.context.properties.ConfigurationPropertiesBinding; import org.springframework.boot.context.properties.ConfigurationPropertiesBinding;
import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.Converter;

View File

@ -1,4 +1,4 @@
package com.baeldung.properties; package com.baeldung.configurationproperties;
public class Item { public class Item {

View File

@ -1,4 +1,4 @@
package com.baeldung.properties.conversion; package com.baeldung.configurationproperties;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;

View File

@ -1,4 +1,4 @@
package com.baeldung.properties.conversion; package com.baeldung.configurationproperties;
import java.time.Duration; import java.time.Duration;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;

View File

@ -4,6 +4,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import com.baeldung.configurationproperties.ConfigProperties;
@SpringBootApplication @SpringBootApplication
@ComponentScan(basePackageClasses = { ConfigProperties.class, JsonProperties.class, CustomJsonProperties.class }) @ComponentScan(basePackageClasses = { ConfigProperties.class, JsonProperties.class, CustomJsonProperties.class })
public class ConfigPropertiesDemoApplication { public class ConfigPropertiesDemoApplication {

View File

@ -1,4 +1,4 @@
package com.baeldung.properties; package com.baeldung.configurationproperties;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -8,6 +8,10 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import com.baeldung.configurationproperties.ConfigProperties;
import com.baeldung.properties.AdditionalProperties;
import com.baeldung.properties.ConfigPropertiesDemoApplication;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(classes = ConfigPropertiesDemoApplication.class) @SpringBootTest(classes = ConfigPropertiesDemoApplication.class)
@TestPropertySource("classpath:configprops-test.properties") @TestPropertySource("classpath:configprops-test.properties")

View File

@ -1,4 +1,4 @@
package com.baeldung.properties.conversion; package com.baeldung.configurationproperties;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
@ -12,8 +12,8 @@ import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.unit.DataSize; import org.springframework.util.unit.DataSize;
import com.baeldung.properties.conversion.PropertiesConversionApplication; import com.baeldung.configurationproperties.PropertiesConversionApplication;
import com.baeldung.properties.conversion.PropertyConversion; import com.baeldung.configurationproperties.PropertyConversion;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(classes = PropertiesConversionApplication.class) @SpringBootTest(classes = PropertiesConversionApplication.class)

View File

@ -1,9 +1,10 @@
package com.baeldung.freemarker.controller; package com.baeldung.freemarker.controller;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Locale;
import com.baeldung.freemarker.method.LastCharMethod;
import freemarker.template.DefaultObjectWrapperBuilder;
import freemarker.template.Version;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
@ -43,4 +44,12 @@ public class SpringController {
return "redirect:/cars"; return "redirect:/cars";
} }
@RequestMapping(value = "/commons", method = RequestMethod.GET)
public String showCommonsPage(Model model) {
model.addAttribute("statuses", Arrays.asList("200 OK", "404 Not Found", "500 Internal Server Error"));
model.addAttribute("lastChar", new LastCharMethod());
model.addAttribute("random", new Random());
model.addAttribute("statics", new DefaultObjectWrapperBuilder(new Version("2.3.28")).build().getStaticModels());
return "commons";
}
} }

View File

@ -0,0 +1,16 @@
package com.baeldung.freemarker.method;
import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;
import org.springframework.util.StringUtils;
import java.util.List;
public class LastCharMethod implements TemplateMethodModelEx {
public Object exec(List arguments) throws TemplateModelException {
if (arguments.size() != 1 || StringUtils.isEmpty(arguments.get(0)))
throw new TemplateModelException("Wrong arguments!");
String argument = arguments.get(0).toString();
return argument.charAt(argument.length() - 1);
}
}

View File

@ -0,0 +1,28 @@
<p>Testing is a property exists: ${student???c}</p>
<#if status??>
<p>Property value: ${status.reason}</p>
<#else>
<p>Missing property</p>
</#if>
<p>Iterating a sequence:</p>
<#list statuses>
<ul>
<#items as status>
<li>${status}</li>
</#items>
</ul>
<#else>
<p>No statuses available</p>
</#list>
<p>Using static methods</p>
<#assign MathUtils=statics['java.lang.Math']>
<p>PI value: ${MathUtils.PI}</p>
<p>2*10 is: ${MathUtils.pow(2, 10)}</p>
<p>Using bean method</p>
<p>Random value: ${random.nextInt()}</p>
<p>Use custom method</p>
<p>Last char example: ${lastChar('mystring')}</p>

View File

@ -1,4 +1,4 @@
package com.baeldung.spring.controller; package com.baeldung.spring.requestparam;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -47,7 +47,7 @@ public class RequestParamController {
@GetMapping("/api/foos4") @GetMapping("/api/foos4")
@ResponseBody @ResponseBody
public String getFoos4(@RequestParam List<String> id){ public String getFoos4(@RequestParam List<String> id){
return "ID are " + id; return "IDs are " + id;
} }
@GetMapping("/foos/{id}") @GetMapping("/foos/{id}")