本例采用图片数据存储到数据库字段的方式
package com.test.model;
import java.io.Serializable;
import java.sql.Blob;
import java.sql.Date;
import javax.sql.rowset.serial.SerialBlob;
public class FileInfo implements Serializable{
private Integer id = null;
private String name = null;
private String contextType = null;
private Long length = null;
private Date dt = null;
private byte[] content = null;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getContextType() {
return contextType;
}
public void setContextType(String contextType) {
this.contextType = contextType;
}
public Long getLength() {
return length;
}
public void setLength(Long length) {
this.length = length;
}
public Date getDt() {
return dt;
}
public void setDt(Date dt) {
this.dt = dt;
}
public byte[] getContent() {
return content;
}
public void setContent(byte[] content) {
this.content = content;
}
}
package com.test.model;
import java.util.ArrayList;
import java.util.List;
public class TypeInfo {
private Integer id = null;
private String label = null;
private Integer pid = null;
private Integer seqno = null;
private List children = new ArrayList();
private Integer imgid = null;
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getPid() {
return pid;
}
public void setPid(Integer pid) {
this.pid = pid;
}
public Integer getSeqno() {
return seqno;
}
public void setSeqno(Integer seqno) {
this.seqno = seqno;
}
public List getChildren() {
return children;
}
public void setChildren(List children) {
this.children = children;
}
public void addChildren(TypeInfo ti) {
this.children.add(ti);
}
public Integer getImgid() {
return imgid;
}
public void setImgid(Integer imgid) {
this.imgid = imgid;
}
}
drop table T_FILE;
create table T_FILE(id int auto_increment primary key,
name varchar(200),contexttype varchar(100),length bigint,dt date,content mediumblob);
insert into T_FILE(name,contexttype,length,dt,content) values (#{name},#{contextType},
#{length},#{dt},#{content,jdbcType=BLOB})
package com.test.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import com.test.model.AddressInfo;
import com.test.model.FileInfo;
import com.test.model.StudentInfo;
import com.test.model.TypeInfo;
@Mapper
public interface AddressMapper {
public List getProvince();
public List getCity(@Param("code") String code);
public List getCounty(@Param("code") String code);
public void saveStudent(StudentInfo si);
public void updateStudent(StudentInfo si);
public List findStudent(@Param("name") String name,
@Param("age1") String age1,
@Param("age2") String age2);
public StudentInfo findStudentById(@Param("id") Integer id);
public void deleteStudent(@Param("id") Integer id);
public TypeInfo getRootType();
public List getTypeList(@Param("pid") Integer id);
public void updateType(TypeInfo ti);
public void saveType(TypeInfo ti);
public void saveFile(FileInfo fi);
public FileInfo getFileById(@Param("id") Integer id);
}
package com.test.service;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.github.pagehelper.PageInfo;
import com.test.model.AddressInfo;
import com.test.model.FileInfo;
import com.test.model.StudentInfo;
import com.test.model.TypeInfo;
public interface IAddressService {
public List getProvince();
public List getCity(String code);
public List getCounty(String code);
public void updateStudent(StudentInfo si);
public void saveStudent(StudentInfo stud);
public PageInfo findStudent(Integer page,Integer rows,String name,String age1,String age2);
public StudentInfo findStudentById(Integer id);
public void deleteStudent(Integer id);
public TypeInfo getRootType();
public List getTypeList(Integer id);
public void updateType(TypeInfo ti);
public void saveType(TypeInfo ti);
public void saveFile(FileInfo fi);
public FileInfo getFileById(Integer id);
}
package com.test.service.impl;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.test.mapper.AddressMapper;
import com.test.model.AddressInfo;
import com.test.model.FileInfo;
import com.test.model.StudentInfo;
import com.test.model.TypeInfo;
import com.test.service.IAddressService;
@Service
public class AddressServiceImpl implements IAddressService{
@Autowired
private AddressMapper mapper;
@Override
public List getProvince() {
// TODO Auto-generated method stub
return mapper.getProvince();
}
@Override
public List getCity(String code) {
if(code != null)
{
String code2 = code.substring(0,2);
List citys = mapper.getCity(code2);
List resultCitys = new ArrayList();
for(AddressInfo city:citys)
{
if(!code.equals(city.getCode()))
resultCitys.add(city);
}
return resultCitys;
}
return null;
}
@Override
public List getCounty(String code) {
if(code != null)
{
String code2 = code.substring(0,4);
List countys = mapper.getCounty(code2);
List resultCountys = new ArrayList();
for(AddressInfo county:countys)
{
if(!code.equals(county.getCode()))
resultCountys.add(county);
}
return resultCountys;
}
return null;
}
@Override
public void saveStudent(StudentInfo stud) {
mapper.saveStudent(stud);
}
@Override
public PageInfo findStudent(Integer page,Integer rows,String name,
String age1,String age2) {
System.out.println("findStudent================page="+page+",rows="+rows+",name="+name);
if(page == null)
page = 1;
if(rows == null)
rows = 4;
PageHelper.startPage(page, rows);
List result = mapper.findStudent(name,age1,age2);
PageInfo pInfo = new PageInfo(result);
return pInfo;
}
@Override
public StudentInfo findStudentById(Integer id) {
// TODO Auto-generated method stub
return mapper.findStudentById(id);
}
@Override
public void updateStudent(StudentInfo si) {
mapper.updateStudent(si);
}
@Override
public void deleteStudent(Integer id) {
mapper.deleteStudent(id);
}
@Override
public TypeInfo getRootType() {
return mapper.getRootType();
}
@Override
public List getTypeList(Integer id) {
return mapper.getTypeList(id);
}
@Override
public void updateType(TypeInfo ti) {
mapper.updateType(ti);
}
@Override
public void saveType(TypeInfo ti) {
mapper.saveType(ti);
}
@Override
public void saveFile(FileInfo fi) {
mapper.saveFile(fi);
}
@Override
public FileInfo getFileById(Integer id) {
return mapper.getFileById(id);
}
}
package com.test.ctrl;
import static org.junit.Assert.assertNotNull;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Controller;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.test.model.AddressInfo;
import com.test.model.FileInfo;
import com.test.model.StudentInfo;
import com.test.model.TypeInfo;
import com.test.service.IAddressService;
@Controller
@CacheConfig(cacheNames="student")
@CrossOrigin(origins = {"http://localhost:8080"})
public class StudCtrl {
@Autowired
private IAddressService addsrv;
@RequestMapping("/studlist")
public String studlist()
{
return "studlist";
}
@RequestMapping("/getprovice")
@ResponseBody
public List getprovice()
{
// List
点击上传
只能上传jpg/png文件,且不超过500kb
保存
添加节点
后台代码
https://pan.baidu.com/s/1-CIzMewuu0AfGFgvJ2HFNw 提取码sq4n
前台代码
https://pan.baidu.com/s/1XD2dAXR0zj1zp5DtibWE-Q 提取码9g94