Archive for February, 2017

sql find duplicate record using fields

 

SELECT COUNT(id)
FROM  Employee
GROUP BY id
HAVING ( COUNT(id )>1 )

 

using two fields

SELECT
    name, email, COUNT(*)
FROM
    users
GROUP BY
    name, email
HAVING 
    COUNT(*) > 1

Leave a comment

MappingJackson2HttpMessageConverter

@SpringBootApplication
public class MainController extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MainController.class);
}

public static void main(String[] args) throws Exception {
SpringApplication.run(MainController.class, args);
}

@Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
MappingJackson2HttpMessageConverter converter =
new MappingJackson2HttpMessageConverter(mapper);
return converter;
}
}

, , ,

Leave a comment

Using Matcher search in list

String value=”java”;

List result = searchIn(list, new Matcher() {
public boolean matches(MyObjectp) {
return p.getName().equals(value);
}
});

public List searchIn(List list, Matcher m) {
List r = new ArrayList();
for (T t : list) {
if (m.matches(t)) {
r.add(t);
}
}
return r;
}
interface Matcher {
public boolean matches( T t );
}

Leave a comment