package cn.alisa.myspboracle.entity;
import java.util.Date;
public class Userinfos {
private int userid;
private String username;
private Date birthyear;
private float userhight;
public int getUserid() {
return userid;
}
public void setUserid(int userid) {
this.userid = userid;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public Date getBirthyear() {
return birthyear;
}
public void setBirthyear(Date birthyear) {
this.birthyear = birthyear;
}
public float getUserhight() {
return userhight;
}
public void setUserhight(float userhight) {
this.userhight = userhight;
}
}
创建接口类——UserinfosDAO.java
package cn.alisa.myspboracle.dao;
import cn.alisa.myspboracle.entity.Userinfos;
import org.apache.ibatis.annotations.Select;
import java.util.List;
public interface UserinfosDAO {
@Select("select userid,username,birthyear,userhight from userinfos")
public List<Userinfos>findAll();
@Select("select userid,username,birthyear,userhight from userinfos where username like '%${name}%'")
public List<Userinfos>findUserSameName(String name);
}
创建服务类——UserinfosService.java
package cn.alisa.myspboracle.service;
import cn.alisa.myspboracle.dao.UserinfosDAO;
import cn.alisa.myspboracle.entity.Userinfos;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class UserinfosService {
@Autowired
private UserinfosDAO udao;
public List<Userinfos>searchAll(){
return udao.findAll();
}
public List<Userinfos>sameName(String name){
return udao.findUserSameName(name);
}
}
创建控制层类——InitCtrl.java:
package cn.alisa.myspboracle.ctrl;
import cn.alisa.myspboracle.entity.Userinfos;
import cn.alisa.myspboracle.service.UserinfosService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
public class InitCtrl {
@Autowired
private UserinfosService userinfosService;
@RequestMapping("/all")
public List<Userinfos>init(){
return userinfosService.searchAll();
}
@RequestMapping("/same")
public List<Userinfos>same(String name){
return userinfosService.sameName(name);
}
}
编辑MyspboracleApplication.java类:
package cn.alisa.myspboracle;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@MapperScan("cn.alisa.myspboracle.dao")
public class MyspboracleApplication {
public static void main(String[] args) {
SpringApplication.run(MyspboracleApplication.class, args);
}
}