大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
接口
服务
sql语句mapper
sql调用接口
1.配置加载库: pom.xml
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-devtools
runtime
true
org.springframework.boot
spring-boot-starter-test
test
org.apache.shiro
shiro-core
1.4.1
org.apache.shiro
shiro-spring
1.4.0
MySQL
mysql-connector-java
runtime
com.alibaba
druid
1.1.6
org.mybatis.spring.boot
mybatis-spring-boot-starter
1.2.0
org.apache.commons
commons-lang3
3.4
org.springframework
spring-context-support
4.2.3.RELEASE
org.apache.tomcat.embed
tomcat-embed-jasper
javax.servlet
servlet-api
2.5
javax.servlet
jstl
org.apache.ibatis
ibatis-core
3.0
2.创建模型
import java.util.HashSet;
import java.util.Set;
public class User {
private Integer uid;
private String username;
private String password;
private Set roles=new HashSet<>();
private Set permissions=new HashSet<>();
public Integer getUid() {
return uid;
}
public void setUid(Integer uid) {
this.uid = uid;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Set getRoles() {
return roles;
}
public void setRoles(Set roles) {
this.roles = roles;
}
public Set getPermissions() {
return permissions;
}
public void setPermissions(Set permissions) {
this.permissions = permissions;
}
}
import java.util.HashSet;
import java.util.Set;
public class Role {
private Integer rid;
private String rname;
private Set permissions=new HashSet<>();
public Integer getRid() {
return rid;
}
public void setRid(Integer rid) {
this.rid = rid;
}
public String getRname() {
return rname;
}
public void setRname(String rname) {
this.rname = rname;
}
public Set getPermissions() {
return permissions;
}
public void setPermissions(Set permissions) {
this.permissions = permissions;
}
}
public class Permission {
private Integer pid;
private String name;
private String url;
public Integer getPid() {
return pid;
}
public void setPid(Integer pid) {
this.pid = pid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}
3.创建数据库查询
public interface UserMapper {
User findByUsername(@Param("username") String username);
}
public interface UserService {
User findByUsername(String username);
}
@Service
public class UserServiceImpl implements UserService {
@Resource
private UserMapper userMapper;
@Override
public User findByUsername(String username) {
return userMapper.findByUsername(username);
}
}
6.测试查询用户信息
@RestController
public class HomeController {
@Autowired
private UserService userService;
// 登录页面
@RequestMapping("/test")
public String login(){
User user=userService.findByUsername("admin");
if (user==null){
return "用户找不到";
}else{
return "用户名是: "+user.getUsername();
}
}
}