日报202536
继续学习了Springboot,感觉有点麻烦:

User
package com.xxx.demo1.pojo;
public class User {
String id;
String name;
@Override
public String toString() {
return "User{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
'}';
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
UserMapper
package com.xxx.demo1.mapper;
import com.xxx.demo1.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
@Mapper
public interface UserMapper {
@Select("select * from user where id=#{id}")
public User findById(String id);
}
UserService
package com.xxx.demo1.service;
import com.xxx.demo1.pojo.User;
public interface UserService {
public User findById(String id);
}
UserServiceImpl
package com.xxx.demo1.service.impl;
import com.xxx.demo1.mapper.UserMapper;
import com.xxx.demo1.pojo.User;
import com.xxx.demo1.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
@Override
public User findById(String id) {
return userMapper.findById(id);
}
}
UserController
package com.xxx.demo1.controller;
import com.xxx.demo1.pojo.User;
import com.xxx.demo1.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class UserController {
@Autowired
private UserService userService;
@RequestMapping("/findById")
public User findById(String id){
return userService.findById(id);
}
}

浙公网安备 33010602011771号