Commit 8a873039 by yanru

扫黑除恶项目搭建,springboot+mybatis+html

parents
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.founder</groupId>
<artifactId>shce</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>SHCE</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- Spring Boot Web 依赖 核心 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Spring Boot Test 依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- 数据库驱动包 -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0</version>
</dependency>
<!-- alibaba的druid数据库连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.11</version>
</dependency>
<!--mybatis 依赖-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
<!--@Getter @Setter-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.6</version>
</dependency>
<!--redis连接-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!--jstl标签-->
<!-- JSTL for JSP spring boot搭建web项目,跳转到jsp一定要添加下面的jar包,否则出现跳转的时候,变成下载的功能,保存该页面-->
<!--<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
&lt;!&ndash; 解析JSP &ndash;&gt;
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- 热部署配置, 改完直接生效, 不用重启服务 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<!--<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2.5.RELEASE</version>
</dependency>-->
<!--<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>-->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!--注意:需要指定版本,否则打成的包静态资源无法访问-->
<version>1.4.2.RELEASE</version>
<!--默认true 需要设置为false mvn spring-boot:run启动项目 debug才有效果-->
<configuration>
<fork>false</fork>
</configuration>
</plugin>
<!--使得测试出错不影响项目的编译-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
<!--<resources>
<resource>
<directory>${basedir}/src/main/webapp</directory>
&lt;!&ndash;注意此次必须要放在此目录下才能被访问到&ndash;&gt;
<targetPath>META-INF/resources</targetPath>
<includes>
<include>**/**</include>
</includes>
</resource>
<resource>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>**/**</include>
</includes>
</resource>
</resources>-->
<!-- 去掉版本号 -->
<finalName>shce</finalName>
</build>
</project>
package com.founder;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
public class ShceApplication {
public static void main(String[] args) {
SpringApplication.run(ShceApplication.class, args);
}
}
package com.founder.business.demo.controller;
import com.founder.business.demo.service.IDemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;
import java.util.Set;
/**
* @Author yanru
* @Date 2020/9/121:30
*/
@Controller
public class DemoController {
@Autowired
private IDemoService demoService;
@Autowired
private StringRedisTemplate redisTemplate;
@ResponseBody
@RequestMapping("/demo")
public String demo(){
return "欢迎来到扫黑除恶页面";
}
@ResponseBody
@RequestMapping("/jsp")
public ModelAndView demojsp(){
ModelAndView modelAndView=new ModelAndView();
modelAndView.setViewName("test");
modelAndView.addObject("username","admin");
return modelAndView;
}
@ResponseBody
@RequestMapping("/dao")
public String testDao() {
return demoService.testDao();
}
@ResponseBody
@RequestMapping("/dicitem")
public Set<String> getDicitem(String type) throws Exception{
//先删除指定key缓存,再加入缓存
String keys="44:*";
if(null!=type && "null"!=type){
keys="44:"+type+"*";
}
Set<String> dictitemKeys = redisTemplate.keys(keys);
return dictitemKeys;
}
}
package com.founder.business.demo.dao;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Component;
/**
* Created by Administrator on 2020/9/2.
*/
@Component
@Mapper
public interface DemoDao {
public String testDao();
}
package com.founder.business.demo.service;
/**
* @Author yanru
* @Date 2020/9/215:17
*/
public interface IDemoService {
public String testDao();
}
package com.founder.business.demo.service.impl;
import com.founder.business.demo.dao.DemoDao;
import com.founder.business.demo.service.IDemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @Author yanru
* @Date 2020/9/215:18
*/
@Service
public class DemoServiceImpl implements IDemoService{
@Autowired
private DemoDao demoDao;
@Override
public String testDao() {
return demoDao.testDao();
}
}
package com.founder.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/*
* 跨域访问配置(访问本系统)
*/
@Configuration
public class CorsConfig extends WebMvcConfigurerAdapter {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowCredentials(true)
.allowedMethods("GET", "POST", "DELETE", "PUT")
.maxAge(3600);
}
}
package com.founder.config;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import javax.sql.DataSource;
@Configuration
public class DataSourceConfig {
@Bean(name="shcedbProperties")
@Qualifier("shcedb")
@ConfigurationProperties(prefix = "spring.datasource.shcedb")
@Primary
public DataSourceProperties secondDbProperties(){
return new DataSourceProperties();
}
@Bean(name="shcedb")
@Qualifier("shcedb")
@ConfigurationProperties(prefix = "spring.datasource.shcedb")
@Primary
public DataSource secondDataSource(){
return secondDbProperties().initializeDataSourceBuilder().build();
}
}
package com.founder.config;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import javax.sql.DataSource;
@Configuration
@MapperScan(basePackages = {"com.founder.business.**.dao"},sqlSessionFactoryRef = "shceSqlSessionFactory")
public class MybatisOrclConfig {
static final String MAPPER_LOCATION = "classpath:mapper/orcl/*.xml";
@Autowired
@Qualifier("shcedb")
private DataSource shcedb;
@Bean(name="shceSqlSessionFactory")
public SqlSessionFactory shceSqlSessionFactory() throws Exception {
SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
factoryBean.setDataSource(shcedb);
factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(MAPPER_LOCATION));
return factoryBean.getObject();
}
@Bean(name="shceSqlSessionTemplate")
public SqlSessionTemplate jwzhSqlSessionTemplate() throws Exception {
return new SqlSessionTemplate(shceSqlSessionFactory());
}
}
#扫黑除恶数据库配置
spring.datasource.shcedb.url=jdbc:oracle:thin:@47.92.129.99:1600:orcl
spring.datasource.shcedb.username=XZXT
spring.datasource.shcedb.password=XZXT
spring.datasource.shcedb.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.shcedb.type: com.alibaba.druid.pool.DruidDataSource
#redis配置
spring.redis.database=0
spring.redis.host=127.0.0.1
spring.redis.port=6379
spring.redis.pass=
\ No newline at end of file
#开发环境使用dev,正式环境使用prod
spring.profiles.active=dev
spring.mvc.static-path-pattern=/**
spring.resources.static-locations=classpath:/static/,classpath:/templates/
spring.mvc.view.prefix=classpath:/templates/
spring.mvc.view.suffix=.html
spring.thymeleaf.encoding=UTF-8
#能够通过${}显示数据
spring.thymeleaf.cache=false
# 页面默认前缀目录
#spring.mvc.view.prefix=/WEB-INF/jsp/
# 响应页面默认后缀
#spring.mvc.view.suffix=.jsp
#静态资源路径
#spring.mvc.static-path-pattern=/**
#spring.resources.static-locations=classpath:/webapp/static/
logging.path=/logs
#日志的级别logging.level
#由低到高 trace<debug<info<warn<error
#com.founder文件夹下所有文件的输出级别为debug,如果不设置该配置,默认输出级别从info开始
logging.level.com.founder = debug
# 在控制台输出的日志的级别
logging.pattern.level=debug
\ No newline at end of file
<?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="com.founder.business.demo.dao.DemoDao">
<select id="testDao" resultType="string">
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual
</select>
</mapper>
\ No newline at end of file
<?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="com.founder.business.demo.dao.DemoDao">
<select id="testDao" resultType="string">
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual
</select>
</mapper>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>测试页面</title>
</head>
<body>
<div>这是一个页面</div>
<input th:value="${username}"/>
<img src="/static/images/bg.jpg" />
</body>
</html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--设置编码,防止页面乱码-->
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>测试页面</title>
</head>
<body>
<div>这是一个页面${username}</div>
<img src="/static/images/bg.jpg" />
</body>
</html>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
</web-app>
\ No newline at end of file
package com.founder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
class ShceApplicationTests {
@Test
void contextLoads() {
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment