搭建SSM+Springboot+JSP

目录

 

1.pom.xml

2.application.properties

3.domain

4.mapper

5.mapper.xml

6.service

7.impl

8.controller

9.Application

10.user.jsp

11.根据domain在数据库建对应的表


1.pom.xml

?xml version="1.0" encoding="UTF-8"?
project 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"
    modelVersion4.0.0/modelVersion

    parent
        groupIdorg.springframework.boot/groupId
        artifactIdspring-boot-starter-parent/artifactId
        version2.1.4.RELEASE/version
        relativePath/ !-- lookup parent from repository --
    /parent

    groupIdcn.itsource/groupId
    artifactIddataSafe/artifactId
    version1.0-SNAPSHOT/version

 

    properties
        java.version1.8/java.version
    /properties

    dependencies
        dependency
            groupIdorg.springframework.boot/groupId
            artifactIdspring-boot-starter-web/artifactId
        /dependency
        dependency
            groupIdmysql/groupId
            artifactIdmysql-connector-java/artifactId
            scoperuntime/scope
        /dependency

        !--
                    spring-boot mybatis依赖:

                    请不要使用1.0.0版本,因为还不支持拦截器插件,
                1.1.1 是博主写帖子时候的版本,大家使用最新版本即可
                 --
        dependency
            groupIdorg.mybatis.spring.boot/groupId
            artifactIdmybatis-spring-boot-starter/artifactId
            version1.1.1/version
        /dependency
        dependency
            groupIdorg.springframework.boot/groupId
            artifactIdspring-boot-starter-test/artifactId
            scopetest/scope
        /dependency
        dependency
            groupIdorg.springframework.boot/groupId
            artifactIdspring-boot-starter-tomcat/artifactId
        /dependency
        dependency
            groupIdorg.apache.tomcat.embed/groupId
            artifactIdtomcat-embed-jasper/artifactId
        /dependency
        dependency
            groupIdjavax.servlet/groupId
            artifactIdjstl/artifactId
        /dependency
        !-- https://mvnrepository.com/artifact/com.alibaba/fastjson --
        dependency
            groupIdcom.alibaba/groupId
            artifactIdfastjson/artifactId
            version1.2.47/version
        /dependency

 

    /dependencies

    build
        plugins
            plugin
                groupIdorg.springframework.boot/groupId
                artifactIdspring-boot-maven-plugin/artifactId
            /plugin
        /plugins
    /build

 


/project

 

2.application.properties

spring.datasource.url = jdbc:mysql://localhost:3306/datasafe?useUnicode=truecharacterEncoding=UTF-8useJDBCCompliantTimezoneShift=trueuseLegacyDatetimeCode=falseserverTimezone=UTC
spring.datasource.username = root
spring.datasource.password = root
spring.datasource.driverClassName = com.mysql.jdbc.Driver
spring.datasource.max-active=20
spring.datasource.max-idle=8
spring.datasource.min-idle=8
spring.datasource.initial-size=10
mybatis.type-aliases-package=cn.itsource.datasafe.domain,cn.itsource.datasafe.query
# 页面默认前缀目录
spring.mvc.view.prefix=/WEB-INF/jsp/
# 响应页面默认后缀
spring.mvc.view.suffix=.jsp

 

 

3.domain

package cn.itsource.datasafe.domain;

public class User {

    private Long id;
    private String name;
    private String password;
    private String salt;

    public Long getId() {
        return id;
    }

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

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }

    public User(String name, String password, String salt) {
        this.name = name;
        this.password = password;
        this.salt = salt;
    }

    public User() {
    }


    //不应该在日志或者控制台打印安全信息
    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                '}';
    }
}

 

 

4.mapper

package cn.itsource.datasafe.mapper;

import cn.itsource.datasafe.domain.User;

public interface UserMapper {

    /**
     * 登录
     * @param name
     * @return
     */
    User login(String name);
}

 

 

5.mapper.xml

?xml version="1.0" encoding="UTF-8"?
!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"
mapper namespace="cn.itsource.datasafe.mapper.UserMapper"
    !--User login(String name);--
    select id="login" parameterType="string" resultType="User"
        SELECT * FROM t_user WHERE name =#{NAME }
    /select
/mapper

 

6.service

package cn.itsource.datasafe.service;

import cn.itsource.datasafe.domain.User;
import cn.itsource.datasafe.mapper.UserMapper;
import org.springframework.stereotype.Service;

public interface IUserService {

   User login(String name);
}

 

 

7.impl

package cn.itsource.datasafe.service.impl;

import cn.itsource.datasafe.domain.User;
import cn.itsource.datasafe.mapper.UserMapper;
import cn.itsource.datasafe.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private UserMapper userMapper;
    @Override
    public User login(String name) {
        return userMapper.login(name);
    }
}

 

 

8.controller

package cn.itsource.datasafe.controller;

import cn.itsource.datasafe.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;


    @RequestMapping("/index")
    public String index(Model model){
        model.addAttribute("user",userService.login("zs"));
        return "user";
    }
}

9.Application

package cn.itsource.datasafe;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@MapperScan("cn.itsource.datasafe.mapper")
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class);
    }
}

 

 

10.user.jsp

%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/6/8
  Time: 11:41
  To change this template use File | Settings | File Templates.
--%
%@ page contentType="text/html;charset=UTF-8" language="java" %
html
head
    titleTitle/title
/head
body
${user}
/body
/html

 

11.根据domain在数据库建对应的表

 

 

最新回复(0)
/jishuZhUGMvMTzr9g5RIK6ftLQTbmTp_2F_2FFFl_2FXfd83zXRRLc_3D4858709
8 简首页