IDEA使用(3 springboot 整合SSM框架)

pom.xml 

xml version="1.0" encoding="UTF-8"?>
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   4.0.0

   com.example
   demo
   1
   jar

   demo
   Demo project for Spring Boot

   
      org.springframework.boot
      spring-boot-starter-parent
      2.0.3.RELEASE
       
   

   
      UTF-8
      UTF-8
      1.8
   

   
      
         org.springframework.boot
         spring-boot-starter-web
      

      
         org.springframework.boot
         spring-boot-starter-test
         test
      
      
      
         org.springframework.boot
         spring-boot-starter-jdbc
      

      
      
         jstl
         jstl
         1.2
      

      
      
         org.springframework.boot
         spring-boot-starter-tomcat
         
      

      
      org.apache.tomcat.embed
      tomcat-embed-jasper
         
      


      
      
      
      
         com.mchange
         c3p0
         0.9.2.1
      
      
         com.mchange
         mchange-commons-java
         0.2.3.4
      
      
         org.springframework
         spring-tx
         5.0.4.RELEASE
      
      
         org.mybatis
         mybatis
         3.4.0
      
      
         org.mybatis
         mybatis-spring
         1.3.0
      
      
      
         org.mybatis.spring.boot
         mybatis-spring-boot-starter
         1.1.1

      
      
         org.junit.jupiter
         junit-jupiter-api
         5.0.0
      
      
         org.springframework.boot
         spring-boot-test
      
      
         org.springframework
         spring-test
         5.0.4.RELEASE
      
      
         org.springframework
         spring-web
         5.0.4.RELEASE
      
      
         commons-io
         commons-io
         2.4
      

      
         org.springframework
         spring-webmvc
         5.0.4.RELEASE
      
      
         mysql
         mysql-connector-java
         5.1.38
      
      
      
      
         org.apache.poi
         poi
         3.10.1
      

      
         junit
         junit
      

   


   
      
         
            org.springframework.boot
            spring-boot-maven-plugin
         
      

      
         
         
            
            src/main/webapp
            
            META-INF/resources
            
               **/**
            
         
         
            src/main/resources
            
               **/**
            
            false
         
      



   



 
  
配置文件
#jdbc
#别名
mybatis.type-aliases-package=com.example.bean
#直接配置MyBatis
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql:///zdyfy?characterEncoding=utf8&useSSL=true
spring.datasource.username=root
spring.datasource.password=mysql

#拦截规则
#server.servlet.context-path=/demo
#视图解析器
spring.mvc.view.prefix=/
spring.mvc.view.suffix=.jsp

实体类

package com.example.bean;

import org.springframework.stereotype.Component;

@Component
public class Emplyee {
    private Integer id;

    private String name;

    private String logname;

    private String logpass;

    private String realname;

    private String address;

    private String idcard;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name == null ? null : name.trim();
    }

    public String getLogname() {
        return logname;
    }

    public void setLogname(String logname) {
        this.logname = logname == null ? null : logname.trim();
    }

    public String getLogpass() {
        return logpass;
    }

    public void setLogpass(String logpass) {
        this.logpass = logpass == null ? null : logpass.trim();
    }

    public String getRealname() {
        return realname;
    }

    public void setRealname(String realname) {
        this.realname = realname == null ? null : realname.trim();
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address == null ? null : address.trim();
    }

    public String getIdcard() {
        return idcard;
    }

    public void setIdcard(String idcard) {
        this.idcard = idcard == null ? null : idcard.trim();
    }

    @Override
    public String toString() {
        return "Emplyee{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", logname='" + logname + '\'' +
                ", logpass='" + logpass + '\'' +
                ", realname='" + realname + '\'' +
                ", address='" + address + '\'' +
                ", idcard='" + idcard + '\'' +
                '}';
    }
}


mapper 接口

package com.example.mapper;

import com.example.bean.Emplyee;
import org.apache.ibatis.annotations.Select;

import java.util.List;


public interface EmplyeeMapper {

    @Select("select * from emplyee\n" +
            "    where id = #{id}")
    Emplyee selectByPrimaryKey(Integer id);
    @Select(" select * from emplyee\n" +
            "    where logname = #{logname}\n" +
            "    and logpass=#{logpass}")
    Emplyee seleteEmpByNamePass(Emplyee u);


    @Select("select * from emplyee")
    List selectAll();
}

service接口

import com.example.bean.Emplyee;


import java.util.List;


public interface UserService {

    /**
     * 查询所有人
     *
     * @return
     */
    List<Emplyee> selectAll();

}
实现类

@Service
public class UserServiceImpl implements UserService {

@Resource
private EmplyeeMapper emplyeeMapper;

@Override
public List selectAllUser() {

    return emplyeeMapper.selectAllEmp();
}
}

controller


 
  
@Controller
@RequestMapping("*.do")
public class UserController {

    @Resource
    private UserService userService;

   

    @RequestMapping("/selectAll")
    public  String selectAll(HttpServletRequest request){
        List users=userService.selectAllUser();
request.getSession().setAttribute("users",users);
 return "selectAll";
 }

    }


selectAll.jsp页面

<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/7/12
  Time: 13:56
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


    </span>测试显示<span style="color:#e8bf6a;">


border="1px solid red" >
                                <c:forEach var="u" items="${users}">                        c:forEach>




 
  


查看结果

IDEA使用(3 springboot 整合SSM框架)_第1张图片



刚开始是无法直接建立jsp文件的,需要配置之后才能建立jsp

IDEA使用(3 springboot 整合SSM框架)_第2张图片

IDEA使用(3 springboot 整合SSM框架)_第3张图片


设置JSp的模板

IDEA使用(3 springboot 整合SSM框架)_第4张图片





你可能感兴趣的:(SSM,springboot,IDEA)

姓名 角色 登录账号
${u.name} ${u.realname} ${u.logname}