mirror of
https://gitee.com/many2many/java-web.git
synced 2025-01-11 14:40:55 +08:00
changed
This commit is contained in:
parent
7b8e45ded1
commit
2a078a47cc
@ -15,7 +15,7 @@ public class User {
|
||||
@Column(nullable = false)
|
||||
private String password;
|
||||
|
||||
|
||||
@Column
|
||||
private String email;
|
||||
|
||||
|
||||
|
@ -39,9 +39,9 @@ public class UserController {
|
||||
* - List<User> 用户列表,每个User对象包含id, name, age
|
||||
*/
|
||||
@GetMapping("")
|
||||
public List<User> findUsers(@RequestParam("name") String name, @RequestParam int page, @RequestParam int pageSize){
|
||||
public List<User> findUsers(@RequestParam("name") String name, @RequestParam(required=false) Integer page, @RequestParam(required = false) Integer pageSize){
|
||||
System.out.println("Got name: " + name+ " page: " + page+ " pageSize: " + pageSize);
|
||||
return userService.queryUsers();
|
||||
return userService.queryUsersContaining(name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,18 @@
|
||||
package com.lk.demo;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UserRepository extends JpaRepository<User, Long> {
|
||||
List<User> findByNameLikeOrderByAgeDesc(String name);
|
||||
|
||||
|
||||
@Query("Select u from User u where u.name like %?1% order by u.age desc")
|
||||
List<User> abcd(String name);
|
||||
|
||||
@Query(value = "Select * from Users u where u.name like %?1% order by u.age desc", nativeQuery = true)
|
||||
List<User> queryUsersByName(String name);
|
||||
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ public class UserService {
|
||||
UserRepository userRepository;
|
||||
|
||||
public User getUser(Long id){
|
||||
|
||||
return userRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
@ -23,6 +24,13 @@ public class UserService {
|
||||
return userRepository.findAll();
|
||||
}
|
||||
|
||||
public List<User> queryUsersContaining(String name){
|
||||
|
||||
userRepository.findByNameLikeOrderByAgeDesc(name);
|
||||
userRepository.abcd(name);
|
||||
return userRepository.queryUsersByName(name);
|
||||
}
|
||||
|
||||
|
||||
public User createUser(User user){
|
||||
return userRepository.save(user);
|
||||
|
Loading…
Reference in New Issue
Block a user