springboot入门,eclipse搭建springboot开发框架ssm框架。 |
您所在的位置:网站首页 › 手动搭建springboot › springboot入门,eclipse搭建springboot开发框架ssm框架。 |
Spring+SpringMVC+Mybatis开发框架ssm框架demo搭建|html|jsp step1:java环境配置,安装jdk8,此步略。 step2:工具准备,安装java版eclipse https://www.eclipse.org/ step3:安装 Spring Tool Suite help->Install New Software->通过下面地址进行安装 http://download.springsource.com/release/TOOLS/update/e4.9/或者(Version: 2019-03 (4.11.0)): help->Eclipse Marketplace->search关键字,spring-tool-suite 多了如上图标,这表示工具安装成功。 step5:手动创建springboot项目 New->Project->Spring Boot->Spring Starter Project step6:项目名称 step7:根据你项目具体情况进行选择,这里选择Web+Mysql+DevTools+MyBatis+Thymeleaf 目录及文件创建情况: step8:文件源码: DolearnApplication.java:自动创建 StringUtil.java package com.example.demo.common; public class StringUtil { public static boolean isNullOrZero (String str) { if(str == null || str.trim().length() == 0) { return true; } return false; } }LoginController.java package com.example.demo.controller; import org.mybatis.spring.annotation.MapperScan; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import com.example.demo.entity.Member; import com.example.demo.service.IMember; @Controller @MapperScan("com.example.demo.dao") //mapper扫描 public class LoginController{ @Autowired IMember iMemberFunc; @RequestMapping(value = "/hello") public String hello(){ System.out.println("Hello"); return "Log"; } @RequestMapping(value = "/login",method = RequestMethod.GET) public String addUser1(String name,String password) { System.out.println("loginName is:"+name); System.out.println("loginPassword is:"+password); try { Member member = iMemberFunc.login(name, password); if(member == null){ System.out.println("登录失败"); return "Log_fail"; }else { System.out.println("登录成功"); return "Log_success"; } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.println(e.getMessage()); System.out.println("登录异常"); } return null; } }MemberDao.java package com.example.demo.dao; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import com.example.demo.entity.Member; import org.apache.ibatis.annotations.Select; //@Mapper public interface MemberDao { @Select("select * from Member where name = #{name}") Member selectMemberByName(@Param("name")String name)throws Exception; }Member.java package com.example.demo.entity; public class Member { private int id; private String name; private String password; public Member(){} public Member(int id, String name, String password) { super(); this.id = id; this.name = name; this.password = password; } public int getId() { return id; } public void setId(int 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; } @Override public String toString() { return "Member [id=" + id + ", name=" + name + ", password=" + password + "]"; } }IMember.java package com.example.demo.service; import com.example.demo.entity.Member; public interface IMember { Member login(String name, String passsword) throws Exception; }MemberImpl.java package com.example.demo.service; import com.example.demo.service.IMember; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.example.demo.common.StringUtil; import com.example.demo.entity.Member; import com.example.demo.dao.MemberDao; @Service public class MemberImpl implements IMember { @Autowired private MemberDao mDao; public Member login(String name, String password) throws Exception { // System.out.println(name + password); if (StringUtil.isNullOrZero(name)) { System.out.println("登录名不能为空"); return null; } if (StringUtil.isNullOrZero(password)) { System.out.println("密码不能为空"); return null; } Member member = mDao.selectMemberByName(name); if (member == null) System.out.println("登录名错误"); if (member != null&&member.getName().equals(name)&&!password.equals(member.getPassword())) { System.out.println("密码错误"); return null; } return member; } }Log_fail.html 登录失败 .center { margin: auto; width: 20%; border: 3px solid #73AD21; padding: 5px; text-align: center; } 登录失败 账号或密码错误 [返回]Log_success.html 登录成功 .center { margin: auto; width: 20%; border: 3px solid #73AD21; padding: 5px; text-align: center; } 登录成功 [退出]Log.html 登录页面 .center { margin: auto; width: 15%; border: 3px solid #73AD21; padding: 5px; text-align: center; }application.properties spring.datasource.url=jdbc:mysql://192.168.190.**:3306/test spring.datasource.username=root spring.datasource.password=123456 #mybatis.config-location=classpath:mybatis-config.xml #mybatis.mapper-locations=classpath*:mapper/**/*.xml mybatis.type-aliases-package=com.example.demo spring.mvc.view.prefix=/WEB-INF/views/ spring.mvc.view.suffix=.jsp数据库member表 CREATE TABLE `member` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(20) DEFAULT NULL, `password` varchar(20) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;运行项目,浏览器访问 http://localhost:8080/hello 【异常】| unrecognized or represents more than one time zone. You must configure either the server or JDBC driver 修改application.properties配置文件中的mysql配置,问题解决 spring.datasource.url=jdbc:mysql://192.168.190.68:3306/test?characterEncoding=utf8&serverTimezone=UTC 写完了 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |