-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38adad1
commit ca86c2f
Showing
12 changed files
with
304 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.bin.demo.config; | ||
|
||
/** | ||
* @Author: xingshulin | ||
* @Date: 2018/12/10 下午5:56 | ||
* @Description: 数据源配置 | ||
* @Version: 1.0 | ||
**/ | ||
public class JdbcDataSource { | ||
} |
22 changes: 19 additions & 3 deletions
22
src/main/java/com/bin/demo/controller/GreetingController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,36 @@ | ||
package com.bin.demo.controller; | ||
|
||
import com.bin.demo.domain.Greeting; | ||
import com.bin.demo.domain.Person; | ||
import com.bin.demo.service.PersonService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
@RestController | ||
@Slf4j | ||
public class GreetingController { | ||
|
||
private static final String template = "Hello,%s!"; | ||
private static final String template = "Hello,%s!,%s"; | ||
|
||
private final AtomicInteger counter = new AtomicInteger(); | ||
|
||
@Autowired | ||
private PersonService personService; | ||
|
||
@RequestMapping("/greeting") | ||
public Greeting greeting(@RequestParam(value = "name", defaultValue = "world") String name) { | ||
return new Greeting(counter.incrementAndGet(), String.format(template, name)); | ||
public Greeting greeting(@RequestParam(value = "age", defaultValue = "10") Integer age) { | ||
//List<Person> persons = personService.getAll(); | ||
/*List<Long> ids = persons.stream().map(person -> person.getId()).collect(Collectors.toList()); | ||
List<Person> personList = personService.getByIds(ids);*/ | ||
Person person = personService.getByAge(age); | ||
/*log.info("日志级别:{}", persons.toString()); | ||
log.debug("日志: {}", persons.toString());*/ | ||
String result = String.format(template, person != null ? person.getName() : "NULL", person != null ? person.toString() : "NULL"); | ||
return new Greeting(counter.incrementAndGet(), result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.bin.demo.dao; | ||
|
||
|
||
import com.bin.demo.domain.Person; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import java.util.List; | ||
|
||
public interface PersonDao extends JpaRepository<Person, Integer> { | ||
|
||
@Override | ||
List<Person> findAll(Sort sort); | ||
|
||
List<Person> findByIdInOrderByAgeDesc(List<Long> ids); | ||
|
||
@Query("FROM Person where age = :age") | ||
Person getByAge(@Param("age") Integer a); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.bin.demo.domain; | ||
|
||
import lombok.Data; | ||
|
||
import javax.persistence.*; | ||
|
||
/** | ||
* @Author: xingshulin | ||
* @Date: 2018/12/10 下午7:13 | ||
* @Description: TODO | ||
* @Version: 1.0 | ||
**/ | ||
@Entity | ||
@Table(name = "t_person") | ||
@Data | ||
public class Person { | ||
@Id | ||
@GeneratedValue | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private String name; | ||
|
||
@Column | ||
private Integer age; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.bin.demo.service; | ||
|
||
import com.bin.demo.domain.Person; | ||
|
||
import java.util.List; | ||
|
||
public interface PersonService { | ||
Person getById(); | ||
|
||
List<Person> getAll(); | ||
|
||
List<Person> getByIds(List<Long> ids); | ||
|
||
Person getByAge(Integer age); | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/bin/demo/service/impl/PersonServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.bin.demo.service.impl; | ||
|
||
import com.bin.demo.dao.PersonDao; | ||
import com.bin.demo.domain.Person; | ||
import com.bin.demo.service.PersonService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @Author: xingshulin | ||
* @Date: 2018/12/10 下午11:23 | ||
* @Description: TODO | ||
* @Version: 1.0 | ||
**/ | ||
@Service | ||
public class PersonServiceImpl implements PersonService { | ||
|
||
@Autowired | ||
private PersonDao personDao; | ||
|
||
@Override | ||
public Person getById() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public List<Person> getAll() { | ||
return personDao.findAll(Sort.by(Sort.Order.asc("age"), Sort.Order.desc("id"))); | ||
} | ||
|
||
@Override | ||
public List<Person> getByIds(List<Long> ids) { | ||
return personDao.findByIdInOrderByAgeDesc(ids); | ||
} | ||
|
||
@Override | ||
public Person getByAge(Integer age) { | ||
return personDao.getByAge(age); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.