springboot+jsp+mybatis项目实例(后台成功,但是无法跳转jsp页面,没有实体类的注解,看springboot+jsp第二弹相关配置,即可成功配置jsp)
SpringBoot是用来简化SpringMvc开发的项目,这里自然要整合mybatis等持久化框架!
先看看项目目录:
一、在pom.xml中配置依赖jar包:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mfc</groupId>
<artifactId>springboot</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>springboot Maven Webapp</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.21</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet.jsp.jstl/jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
提示:springboot热部署配置:
热部署:修改java代码后直接保存即可在浏览器上运行,不需要手动重启服务器
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
二、项目入口:
package com.mfc;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
三、控制器类:
package com.mfc.ctrl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import com.mfc.dao.UserMapper;
import com.mfc.entity.User;
@RestController
@RequestMapping("/userController")
public class UserController {
@Autowired
private UserMapper userMapper;
@RequestMapping(value={"/selectUserById"}, method=RequestMethod.GET)
public ModelAndView selectUserById(String id){
User user = userMapper.selectUserById(Integer.parseInt(id));
ModelAndView mav = new ModelAndView("updateUser");
mav.addObject("user", user);
return mav;
}
@RequestMapping(value={"/selectAllUser"}, method=RequestMethod.GET)
public ModelAndView selectAllUser(){
List<User> list = userMapper.selectAllUser();
ModelAndView mav = new ModelAndView("alluser");
mav.addObject("users", list);
return mav;
}
@RequestMapping(value={"/addUserPage"}, method=RequestMethod.GET)
public ModelAndView addUserPage(){
ModelAndView mav = new ModelAndView("adduser");
return mav;
}
@RequestMapping(value={"/addUser"}, method=RequestMethod.POST)
public ModelAndView addUser(User user){
userMapper.addUser(user);
ModelAndView mav = new ModelAndView("redirect:selectAllUser");
return mav;
}
@RequestMapping(value={"/updateUser"}, method=RequestMethod.POST)
public ModelAndView updateUser(User user){
userMapper.updateUser(user);
ModelAndView mav = new ModelAndView("redirect:selectAllUser");
return mav;
}
@RequestMapping(value={"/deleteUser"}, method=RequestMethod.GET)
public ModelAndView deleteUser(String id){
userMapper.deleteUser(Integer.parseInt(id));
ModelAndView mav = new ModelAndView("redirect:selectAllUser");
return mav;
}
}
四、资源配置文件:application.properties
#配置数据库连接数据
spring.datasource.url=jdbc:mysql://localhost:3306/springboot
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#配置控制器里面返回页面的前后缀
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
五、dao层以及service层和springmvc中一样使用,实体类省略!
这里的dao层使用注解实现:
package com.mfc.dao;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import com.mfc.entity.User;
@Mapper
public interface UserMapper {
@Select("select * from user where id = #{id}")
public User selectUserById(int id);
@Select("select * from user")
public List<User> selectAllUser();
@Insert("insert into user(userName,userAge,userAddress) values (#{userName},#{userAge},#{userAddress})")
public void addUser(User user);
@Update("update user set userName=#{userName},userAge=#{userAge},userAddress=#{userAddress} where id=#{id}")
public void updateUser(User user);
@Delete("delete from user where id=#{id}")
public void deleteUser(int id);
}
springboot+jsp+mybatis项目实例(后台成功,但是无法跳转jsp页面,没有实体类的注解,看springboot+jsp第二弹相关配置,即可成功配置jsp)的更多相关文章
- springboot + swagger的实体类属性注解
@Api:用在类上,说明该类的作用 @ApiOperation:用在方法上,说明方法的作用 @ApiImplicitParams:用在方法上包含一组参数说明 @ApiImplicitParam:用在@ ...
- 阶段3 1.Mybatis_09.Mybatis的多表操作_4 完成account一对一操作-建立实体类关系的方式
定义user的实体.然后生成getter和setter 定义一个可以封装Account和User的Map type这里虽然是account类型 这一段只能保证account的数据完成.并不能保证use ...
- springboot 整合 mybatis 入门
springboot整合mybatis 0.yml 配置文件 1.创建数据库表. 2.创建实体类. 3.创建 Mapper 接口 ,添加 @Mapper 注解. 4.创建 Mapper 映射文件. & ...
- SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 后端篇(一): 搭建基本环境、整合 Swagger、MyBatisPlus、JSR303 以及国际化操作
相关 (1) 相关博文地址: SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 前端篇(一):搭建基本环境:https://www.cnblogs.com/l-y- ...
- SpringBoot集成Mybatis实现多表查询的两种方式(基于xml)
下面将在用户和账户进行一对一查询的基础上进行介绍SpringBoot集成Mybatis实现多表查询的基于xml的两种方式. 首先我们先创建两个数据库表,分别是user用户表和account账户表 ...
- springboot整合mybatis与thymeleaf
1.创建springboot项目 (1)选择Spring Initializr (2)填写自己的Group 与 Artifact (3)选择依赖框架 等待maven下载好依赖和插件即可 2.主配置文件 ...
- SpringBoot 整合 MyBatis,实现 CRUD 示例
目录 前言 创建项目/模块 SpringBoot Console Application CommandLineRunner SpringBoot 集成 MyBatis 创建数据库/表 配置数据源/连 ...
- SpringBoot整合Mybatis使用注解或XML的方式开发
2018-6-4 补充mybatis-spring-boot注解的使用 1.导包 只需要再导入mysql+mybatis两个包 <dependency> <groupId>or ...
- springboot系列七:springboot 集成 MyBatis、事物配置及使用、druid 数据源、druid 监控使用
一.MyBatis和druid简介 MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.M ...
随机推荐
- 20180708-Java变量类型
public class Test{ public void pupAge(){ int age = 0; age = age + 7; System.out.println("Puppy ...
- jsc2019_qualE Card Collector
题目大意 给你n个点的坐标和权值 问先在每一行选一个点再在每一列选一个没选过的点 求最大权值和 分析 可以想到将点转化为边,将两个坐标对应两个点 所以问题转化为选H+W个边 使得所有边的度都不为0 则 ...
- Chrome开发小技巧--浏览器控制台现写并运行js代码--snippets
想简单等运行一段js代码,以前可能会新建一个html 里面包含script标签,或者引入一个js,然后chrome浏览器打开.这样很麻烦. 想再console控制台写,也不方便,换行处理麻烦. 基于在 ...
- github信息安全开源课
尽可能的减少信息差:兄弟们,该知足了,这些资源非常的宝贵了. ### github探索-主题-令人敬畏的名单 令人敬畏的名单: https://github.com/topics/awesome 进入 ...
- Vue2.0响应式原理以及重写数组方法
// 重写数组方法 let oldArrayPrototype = Array.prototype; let proto = Object.create(oldArrayPrototype); ['p ...
- Survey Results for Rebecca Murpheys Learning JavaScript Survey
时间 2016-01-27 05:40:46 Raymond Camden's Blog 原文 http://www.raymondcamden.com/2016/01/25/survey-res ...
- flask为blueprint增加error_handler
对整个app增加errorhandler,只需如下: @portal_page.errorhandler(404) def page_not_found(error): cats = Category ...
- hive Hsql
show databases; use flume; show tables; desc flume; alter table table_name add columns(dt string); a ...
- P3452 [POI2007]BIU-Offices(链表+bfs)
P3452 [POI2007]BIU-Offices 新姿势:链表存图快速删除 显然两个没有直接相连的点要放到同一个集合里 但是直接搞一个图的补图会挂掉 考虑用链表维护点序列 每次bfs删除一个点和与 ...
- 解决java.net.BindException: Address already in use(Bind failed)端口占用问题
问题描述: 解决办法: sudo lsof -i:20101ps -ef|grep 9905kill -9 9905ps -ef|grep 9905 ------------------------- ...