-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b6dd42b
Showing
16 changed files
with
522 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
<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>xn.xwj.ssmshiro</groupId> | ||
<artifactId>ssmshiro</artifactId> | ||
<packaging>war</packaging> | ||
<version>1.0-SNAPSHOT</version> | ||
<name>ssmshiro Maven Webapp</name> | ||
<url>http://maven.apache.org</url> | ||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
</dependency> | ||
|
||
<!--补全项目依赖--> | ||
<!--1.日志 java日志有:slf4j,log4j,logback,common-logging | ||
slf4j:是规范/接口 | ||
日志实现:log4j,logback,common-logging | ||
使用:slf4j+logback | ||
--> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>1.7.23</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-core</artifactId> | ||
<version>1.2.1</version> | ||
</dependency> | ||
<!--实现slf4j接口并整合--> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<version>1.2.1</version> | ||
</dependency> | ||
|
||
<!--1.数据库相关依赖--> | ||
<dependency> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
<version>6.0.5</version> | ||
<scope>runtime</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>c3p0</groupId> | ||
<artifactId>c3p0</artifactId> | ||
<version>0.9.1.2</version> | ||
</dependency> | ||
|
||
<!--2.dao框架:MyBatis依赖--> | ||
<dependency> | ||
<groupId>org.mybatis</groupId> | ||
<artifactId>mybatis</artifactId> | ||
<version>3.4.1</version> | ||
</dependency> | ||
|
||
<!--mybatis自身实现的spring整合依赖--> | ||
<dependency> | ||
<groupId>org.mybatis</groupId> | ||
<artifactId>mybatis-spring</artifactId> | ||
<version>1.3.0</version> | ||
</dependency> | ||
|
||
<!--3.Servlet web相关依赖--> | ||
<dependency> | ||
<groupId>taglibs</groupId> | ||
<artifactId>standard</artifactId> | ||
<version>1.1.2</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>jstl</artifactId> | ||
<version>1.2</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
<version>2.8.5</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>javax.servlet-api</artifactId> | ||
<version>3.1.0</version> | ||
</dependency> | ||
|
||
<!--4:spring依赖--> | ||
<!--1)spring核心依赖--> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-core</artifactId> | ||
<version>4.3.5.RELEASE</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-beans</artifactId> | ||
<version>4.3.5.RELEASE</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context</artifactId> | ||
<version>4.3.5.RELEASE</version> | ||
</dependency> | ||
|
||
<!--2)spring dao层依赖--> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-jdbc</artifactId> | ||
<version>4.3.5.RELEASE</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-tx</artifactId> | ||
<version>4.3.5.RELEASE</version> | ||
</dependency> | ||
|
||
<!--3)springweb相关依赖--> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-web</artifactId> | ||
<version>4.3.5.RELEASE</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-webmvc</artifactId> | ||
<version>4.3.5.RELEASE</version> | ||
</dependency> | ||
|
||
<!--4)spring test相关依赖--> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-test</artifactId> | ||
<version>4.3.5.RELEASE</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<finalName>ssmshiro</finalName> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package dao; | ||
|
||
import entity.Seckill; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Created by xuweijie on 2017/3/3. | ||
*/ | ||
public interface QueryTestDao { | ||
|
||
Seckill queryById( long seckillId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package entity; | ||
|
||
import java.util.Date; | ||
|
||
/** | ||
* Created by xuweijie on 2017/2/21. | ||
*/ | ||
public class Seckill { | ||
|
||
private long seckillId; | ||
private String name; | ||
private int number; | ||
private Date startTime; | ||
private Date endTime; | ||
private Date createTime; | ||
|
||
public long getSeckillId() { | ||
return seckillId; | ||
} | ||
|
||
public void setSeckillId(long seckillId) { | ||
this.seckillId = seckillId; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public int getNumber() { | ||
return number; | ||
} | ||
|
||
public void setNumber(int number) { | ||
this.number = number; | ||
} | ||
|
||
public Date getStartTime() { | ||
return startTime; | ||
} | ||
|
||
public void setStartTime(Date startTime) { | ||
this.startTime = startTime; | ||
} | ||
|
||
public Date getEndTime() { | ||
return endTime; | ||
} | ||
|
||
public void setEndTime(Date endTime) { | ||
this.endTime = endTime; | ||
} | ||
|
||
public Date getCreateTime() { | ||
return createTime; | ||
} | ||
|
||
public void setCreateTime(Date createTime) { | ||
this.createTime = createTime; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Seckill{" + | ||
"seckillId=" + seckillId + | ||
", name='" + name + '\'' + | ||
", number=" + number + | ||
", startTime=" + startTime + | ||
", endTime=" + endTime + | ||
", createTime=" + createTime + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package service; | ||
|
||
import entity.Seckill; | ||
|
||
/** | ||
* Created by xuweijie on 2017/3/3. | ||
*/ | ||
public interface Queryservice { | ||
|
||
public Seckill getByid(long seckillId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package service.impl; | ||
|
||
import dao.QueryTestDao; | ||
import entity.Seckill; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
import service.Queryservice; | ||
|
||
/** | ||
* Created by xuweijie on 2017/3/3. | ||
*/ | ||
@Service | ||
public class QueryserviceImpl implements Queryservice { | ||
|
||
@Autowired | ||
private QueryTestDao queryTestDao; | ||
|
||
|
||
public Seckill getByid(long seckillId) { | ||
return queryTestDao.queryById(seckillId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package web; | ||
|
||
import entity.Seckill; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import service.Queryservice; | ||
|
||
/** | ||
* Created by xuweijie on 2017/3/3. | ||
*/ | ||
@Controller | ||
public class testcontroller { | ||
|
||
@Autowired | ||
private Queryservice queryservice; | ||
|
||
@RequestMapping("/content") | ||
public String showcontent(Model model){ | ||
long id=1000; | ||
Seckill seckill=queryservice.getByid(id); | ||
model.addAttribute("seckill",seckill.getName()); | ||
return "content"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
jdbc.driver=com.mysql.jdbc.Driver | ||
jdbc.url=jdbc:mysql://localhost:3306/seckill?serverTimezone=UTC | ||
jdbc.username=root | ||
jdbc.password=root |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?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="dao.QueryTestDao"> | ||
|
||
<select id="queryById" parameterType="long" resultType="entity.Seckill"> | ||
select * from seckill.seckill WHERE seckill_id=#{seckillId} ; | ||
</select> | ||
|
||
</mapper> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!DOCTYPE configuration | ||
PUBLIC "-//mybatis.org//DTD Config 3.0//EN" | ||
"http://mybatis.org/dtd/mybatis-3-config.dtd"> | ||
<configuration> | ||
|
||
<settings> | ||
<!--使用jdbc的useGeneratedKeys 获取数据库自增主键值--> | ||
<setting name="useGeneratedKeys" value="true"/> | ||
<!--使用列别名替换列名,默认为true--> | ||
<setting name="useColumnLabel" value="true"/> | ||
<!--开启驼峰命名转换Table:create_time到 Entity(createTime)--> | ||
<setting name="mapUnderscoreToCamelCase" value="true"/> | ||
</settings> | ||
|
||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:context="http://www.springframework.org/schema/context" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> | ||
|
||
<!--Spring配置整合mybatis过程--> | ||
<!--1.配置数据库相关参数--> | ||
<context:property-placeholder location="classpath:jdbc.properties"/> | ||
|
||
<!--2.数据库连接池--> | ||
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> | ||
<!--配置连接池属性--> | ||
<property name="driverClass" value="${jdbc.driver}"/> | ||
<property name="jdbcUrl" value="${jdbc.url}"/> | ||
<property name="user" value="${jdbc.username}"/> | ||
<property name="password" value="${jdbc.password}"/> | ||
|
||
<!--c3p0连接池的私有属性--> | ||
<property name="maxPoolSize" value="30"/> | ||
<property name="minPoolSize" value="10"/> | ||
<!--关闭链接后不自动commit--> | ||
<property name="autoCommitOnClose" value="false"/> | ||
<!--获取链接超时时间--> | ||
<property name="checkoutTimeout" value="1000"/> | ||
<!--当获取链接失败重试的次数--> | ||
<property name="acquireRetryAttempts" value="2"/> | ||
|
||
</bean> | ||
|
||
<!--约定大于配置--> | ||
<!--3.配置SqlSessionFactory对象--> | ||
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> | ||
<!--往下才是mybatis和spring真正整合的配置--> | ||
<!--注入数据库连接池--> | ||
<property name="dataSource" ref="dataSource"/> | ||
<!--配置mybatis全局配置文件:mybatis-config.xml--> | ||
<property name="configLocation" value="classpath:mybatis-config.xml"/> | ||
<!--扫描sql配置文件:mapper需要的xml文件--> | ||
<property name="mapperLocations" value="classpath:mapper/*.xml"/> | ||
</bean> | ||
|
||
<!--4:配置扫描Dao接口包,动态实现DAO接口,注入到spring容器--> | ||
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> | ||
<!--注入SqlSessionFactory--> | ||
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/> | ||
<!-- 给出需要扫描的Dao接口--> | ||
<property name="basePackage" value="dao"/> | ||
</bean> | ||
|
||
</beans> |
Oops, something went wrong.